Server/Local Server

8. APM 소스 설치 방법 & 패키지 매니저 설치 방법

seongduck 2022. 8. 7. 20:32

1. Ubuntu 패키지 업데이트

#등록된 저장소 내 패키지 정보를 최신으로 업데이트
$ sudo apt update

#저장소 내 패키지 정보를 바탕으로 시스템에 설치된 패키지들을 업그레이드
$ sudo apt upgrade

#불필요해진 패키지를 자동으로 삭제한다.
$ sudo apt autoremove

2. 필수 패키지 설치

$sudo su
# apt-get update
# apt-get upgrade

#Apache2 설치 위한 패키지
# apt-get install make
# apt-get install build-essential
# apt-get install gcc
# apt-get install —reinstall make
# apt-get install libexpat1-dev
# apt-get install g++
# apt-get install net-tools
# apt-get install curl
# apt-get install perl

#MYSQL 설치 위한 패키지
# apt-get install cmake
# apt-get install libssl-dev
# apt-get install libboost-all-dev
# apt-get install libncurses5-dev libncursesw5-dev

#PHP 설치 위한 패키지
# apt-get install libxml2-dev
# apt-get install libjpeg-dev
# apt-get install libpng-deb
# apt-get install libsqlite3-dev

3. Apache2 설치하기 (2.4.53)

# apache2를 설치
$ sudo apt install apache2

# 아파치 서버 시작 (localhost)
$ sudo service apache2 start

# 아파치 서버 중지
$ sudo service apache2 stop

# 아파치 서버 재시작
$ sudo service apache2 restart
  • 한 번에 패키지로 패키지 매니저 설치 방법 (아래 방법이 안될 경우)

apr 설치 (1.7.0)

$ sudo su
/usr/local# mkdir apache
/usr/local# wget <http://mirror.navercorp.com/apache//apr/apr-1.7.0.tar.gz>
/usr/local# wget <http://mirror.navercorp.com/apache//apr/apr-util-1.6.1.tar.gz>
/usr/local# tar xvfz apr-1.7.0.tar.gz
/usr/local# tar xvfz apr-util-1.6.1.tar.gz
/usr/local# wget <https://www.apache.org/dist/apr/apr-1.7.0.tar.gz.sha256>
/usr/local# sha256sum --check apr-1.7.0.tar.gz.sha256
/usr/local/apr-1.7.0# sudo apt-get install build-essential
/usr/local/apr-1.7.0# ./configure --prefix=/usr/local/apr
/usr/local/apr-1.7.0# make
/usr/local/apr-1.7.0# make install

apr-util 설치 (1.6.1)

/usr/local/apr-util-1.6.1# ./configure --with-apr=/usr/local/apr --prefix=/usr/local/apr-util 
/usr/local/apr-util-1.6.1# make
/usr/local/apr-util-1.6.1# make install

pcre 설치 (8.45)

/usr/local# wget <https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz>
/usr/local/pcre-8.45# ./configure --prefix=/usr/local/pcre
/usr/local/pcre-8.45# make
/usr/local/pcre-8.45# make install

apache2 설치 (2.4.53)

/usr/local# wget <https://apache.mirror.cdnetworks.com//httpd/httpd-2.4.53.tar.gz>
/usr/local# tar xvfz httpd-2.4.53.tar.gz
/usr/local/httpd-2.4.53# ./configure --prefix=/usr/local/apache2.4 \\
> --enable-module=so --enable-rewrite --enable-so \\
> --with-apr=/usr/local/apr \\
> --with-apr-util=/usr/local/apr-util \\
> --with-pcre=/usr/local/pcre/bin/pcre-config \\
> --enable-mods-shared=all
/usr/local/httpd-2.4.53# make
/usr/local/httpd-2.4.53# make install

#실행
/usr/local/#  apache2.4/bin/httpd -k start
#재실행
/usr/local/#  apache2.4/bin/httpd -k restart
#종료
/usr/local/#  apache2.4/bin/httpd -k stop

4. Mysql 설치 (8.0.28)

# Mysql 설치
$ sudo apt install mysql-server

# Mysql 보안 스크립트 실행
$ sudo mysql_secure_installation
  • 한 번에 패키지로 패키지 매니저 설치 방법 (아래 방법이 안될 경우)

/usr/local# wget <https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.28.tar.gz>
/usr/local# tar xvfz mysql-8.0.28.tar.gz
/usr/local# cd mysql-8.0.28
/usr/local/mysql-8.0.28# mkdir dir_mysql (이름 아무거나 상관없음) > 소스에 빌드하지 마시오 오류 발생
/usr/local/mysql-8.0.28# cd dir_mysql
/usr/local/mysql-8.0.28/dir_mysql# cmake \\
> .. \\
> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \\
> -DMYSQL_DATADIR=/usr/local/mysql/data \\
> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \\
> -DMYSQL_TCP_PORT=3306 \\
> -DDEFAULT_CHARSET=utf8 \\
> -DDEFAULT_COLLATION=utf8_general_ci \\
> -DSYSCONFDIR=/etc \\
> -DWITH_EXTRA_CHARSETS=all \\
> -DWITH_INNOBASE_STORAGE_ENGINE=1 \\
> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \\
> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \\
> -DDOWNLOAD_BOOST=1 \\
> -DWITH_BOOST=/usr/local/mysql/boost

/usr/local/mysql-8.0.28/dir_mysql# make
/usr/local/mysql-8.0.28/dir_mysql# make install

 

설정 & 실행

데이터베이스 초기화

#디렉토리 생성
/usr/local/mysql-8.0.28/dir_mysql# cd /usr/local/mysql
usr/local/mysql# mkdir mysql-files

#권한주기
/usr/local/mysql# chown -R mysql:mysql /usr/local/mysql
/usr/local/mysql# chown mysql:mysql mysql-files
/usr/local/mysql# chmod 750 mysql-files

#기본 db 생성
/usr/local/mysql/bin# ./mysqld --initialize --user=mysql \\
> --basedir=/usr/local/mysql \\
> --datadir=/usr/local/mysql/data

----> 임시 비밀번호 생성

#서버 실행
/usr/local/mysql/bin# ./mysqld_safe --user=mysql &

#서버 실행 확인
$ ps -ef | grep mysqld

#서버 연결
/usr/local/mysql/bin# ./mysql -u root -p

#root 암호 초기화
mysql> alter user 'root'@'localhost' identified with mysql_native_password by '바꿀 패스워드';

#서버 종료
/usr/local/mysql/bin# ./mysqladmin -u root -p shutdown
ps -ef | grep mysqld --> 확인가능

 

MySQL 서비스 등록(자동 실행)

#mysqld 설정
/usr/local/# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/usr/local/# vi /etc/init.d/mysqld

#/etc/init.d/mysqld 작성
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

#mysqld 서비스 등록
/usr/local# update-rc.d mysqld defaults

#서비스 mysqld 실행 방법
/usr/local# service mysql start
/usr/local# service mysql stop
/usr/local# service mysql restart
/usr/local# service mysql status //서버 상태 확인. 나갈 땐 q

 

MySQL 환경 설정

#환경설정
/usr/local/# vi /etc/my.cnf

#/etc/my.cnf 작성
[mysqld]
bind-address=0.0.0.0
port=3306
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data

5. PHP 설치 (8.1.4)

# Php 설치,  php에서 apache2와 mysql 사용할 수 있게 해주는 모듈을 함께 설치
$ sudo apt install php libapache2-mod-php php-mysql
  • 한 번에 패키지로 패키지 매니저 설치 방법 (아래 방법이 안될 경우)

PHP 설치 (8.1.4)

/usr/local# wget <https://www.php.net/distributions/php-8.1.4.tar.gz>
/usr/local# tar xvfz php-8.1.4.tar.gz
/usr/local# cd php-8.14
/usr/local/php-8.14# ./configure \\
--with-apxs2=/usr/local/apache2.4/bin/apxs \\
--enable-mysqlnd \\
--with-mysql-sock=mysqlnd \\
--with-mysqli=mysqlnd \\
--with-pdo-mysql=mysqlnd \\
--with-imap-ssl \\
--with-iconv \\
--enable-gd \\
--with-jpeg \\
--with-libxml \\
--with-openssl

/usr/local/php-8.14# make
/usr/local/php-8.14# make test
/usr/local/php-8.14# make install

#모듈 설치 확인
/usr/local# cd apache2.4/conf
/usr/local/apache2.4/conf# cat httpd.conf
#httpd.conf에 LoadModule php_module   models/libphp.so 확인

#Type 추가 작성
/usr/local/apache2.4/conf# vi httpd.conf
#/usr/local/apache2.4/conf/httpd.conf을 수정/추가

  AddType application/x-compress .Z
	AddType application/x-gzip .gz .tgz
  AddType application/x-httpd-php .php .html

#php.ini 파일 세팅
/usr/local# cd php-8.1.0
/usr/local/php-8.1.0# cp php.ini-production /usr/local/lib/php.ini

#테스트 php 파일 작성
/usr/local# cd apache2.4/htdocs
/usr/local/apache2.4/htdocs# vi phpinfo.php
#/usr/local/apache2.4/htdocs/phpinfo.php에 작성


#연결 확인
/usr/local# apache2.4/bin/httpd -k start
/usr/local# ps -ef | grep httpd | grep -v grep
/usr/local# sudo netstat -anp | grep httpd
/usr/local# sudo curl 
 접속