- PHP 수동설치
기본 폴더 : /usr/local/src
-> cd /usr/local/src
1. 의존 라이브러리 설치
- PHP를 설치하기 위해서는 먼저 의존 라이브러리를 설치 해야 한다.
yum -y install libxml2-devel bzip2-devel libcurl-devel gdbm-devel libvpx libvpx-devel libjpeg-turbo-devel libpng-devel libXpm \
libXpm-devel freetype-devel t1lib t1lib-devel gmp-devel libc-client libc-client-devel pam-devel libicu libicu-devel openldap-devel \
readline-devel libedit-devel libtidy libtidy-devel libxslt libxslt-devel expat* krb5-devel openssl-devel db4-devel
라이브러리를 설치 하다보면 간혹 몇개의 라이브러리를 찾을 수 없어 설치가 안되는 것들이 생기는데
해당 라이브러리는 yum 의 repository를 추가해 주면 찾을 수 있다.
- repository를 추가하는 한가지 예로 epel을 추가해 보겠다. 추가하기 전에 epel repository가 존재 하는지 확인한다.
yum repolist
repolist에서 epel을 찾지 못하였다면 아래 명령을 실행한다.
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
다시 yum repolist를 실행하여 epel repository가 설정되었는지 확인한다.
yum repolist 결과 예시
repo id repo name status
base/7/x86_64 CentOS-7 - Base 8,652
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 7,990
extras/7/x86_64 CentOS-7 - Extras 128
updates/7/x86_64 CentOS-7 - Updates 601
repolist: 17,371
2. libmcrypt 설치 & 심볼 생성
wget http://www.atblog.co.kr/file/package/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
ln -s /usr/local/lib/libmcrypt.so.4 /usr/local/lib64/libmcrypt.so.4
만약 Mysql을 설치 했다면 아래 코드를 실행한다. (Mysql lib 참조)
ln -s /usr/local/mysql/lib /usr/local/mysql/lib64
3. PHP 소스 다운로드
- PHP 소스를 지정된 폴더로 이동하여 다운로드 받는다.
wget http://www.atblog.co.kr/file/package/php-5.6.4.tar.gz
- 압축 해제
tar zxvf php-5.6.4.tar.gz
4. PHP 설치
Configure를 실행하여 PHP를 설치 한다.
- PHP Configure (Mysql 미설치)
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/apache/conf \
--with-regex=php --with-libxml-dir=/usr \
--with-openssl --with-pcre-regex \
--with-zlib --with-bz2 --with-curl \
--with-gdbm --with-db4=/usr --with-dbm \
--with-pcre-dir=/usr --with-openssl-dir=/usr \
--with-libxml-dir=/usr \
--with-gd \
--with-vpx-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr \
--with-zlib-dir=/usr --with-xpm-dir=/usr \
--with-freetype-dir=/usr --with-t1lib=/usr \
--with-gettext --with-gmp --with-mhash \
--with-imap=/usr/local/imap-2007f \
--with-imap-ssl=/usr/local/imap-2007f \
--with-kerberos \
--with-icu-dir=/usr \
--with-ldap --with-ldap-sasl \
--with-libmbfl --with-onig \
--with-mcrypt \
--with-libedit --with-readline \
--with-tidy \
--with-libexpat-dir=/usr --with-xmlrpc --with-xsl \
--with-pear --with-pic \
--with-libdir=lib64 \
--with-mpm=worker \
--enable-bcmath --enable-calendar \
--enable-exif --enable-ftp --enable-pcntl \
--enable-gd-native-ttf --enable-gd-jis-conv \
--enable-intl --enable-mbstring \
--enable-shmop --enable-sockets \
--enable-sysvmsg --enable-sysvsem --enable-sysvshm \
--enable-wddx --enable-zip \
--enable-dba=shared \
--enable-mod-charset \
--enable-dom --enable-mbregex --enable-inline-optimization \
--enable-sigchild --enable-soap \
--enable-maintainer-zts \
--enable-opcache=no
- PHP Configure (Mysql 설치)
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs --with-config-file-path=/usr/local/apache/conf \
--with-mysql=/usr/local/mysql --with-mysql-sock=/var/mysql \ # Mysql 미사용 삭제
--with-mysqli=/usr/local/mysql/bin/mysql_config \ # Mysql 미사용 삭제
--with-pdo-mysql=shared,/usr/local/mysql \ # Mysql 미사용 삭제
--with-regex=php --with-libxml-dir=/usr \
--with-openssl --with-pcre-regex \
--with-zlib --with-bz2 --with-curl \
--with-gdbm --with-db4=/usr --with-dbm \
--with-pcre-dir=/usr --with-openssl-dir=/usr \
--with-libxml-dir=/usr \
--with-gd \
--with-vpx-dir=/usr --with-jpeg-dir=/usr --with-png-dir=/usr \
--with-zlib-dir=/usr --with-xpm-dir=/usr \
--with-freetype-dir=/usr --with-t1lib=/usr \
--with-gettext --with-gmp --with-mhash \
--with-imap=/usr/local/imap-2007f \
--with-imap-ssl=/usr/local/imap-2007f \
--with-kerberos \
--with-icu-dir=/usr \
--with-ldap --with-ldap-sasl \
--with-libmbfl --with-onig \
--with-mcrypt \
--with-libedit --with-readline \
--with-tidy \
--with-libexpat-dir=/usr --with-xmlrpc --with-xsl \
--with-pear --with-pic \
--with-libdir=lib64 \
--with-mpm=worker \
--enable-bcmath --enable-calendar \
--enable-exif --enable-ftp --enable-pcntl \
--enable-gd-native-ttf --enable-gd-jis-conv \
--enable-intl --enable-mbstring \
--enable-shmop --enable-sockets \
--enable-sysvmsg --enable-sysvsem --enable-sysvshm \
--enable-wddx --enable-zip \
--enable-mysqlnd \ # Mysql 미사용 삭제
--enable-dba=shared \
--enable-mod-charset \
--enable-dom --enable-mbregex --enable-inline-optimization \
--enable-sigchild --enable-soap \
--enable-maintainer-zts \
--enable-opcache=no
configure를 실행 하였는데 DBA: Could not find necessary header file(s). 에러가 발생 한다면 아래 명령을 실행하여 해당 에러를 잡아준다.
yum install gdbm*
yum install db4*
Configure 실행이 완료 되었으면 make -> make install을 차례로 입력하여 컴파일을 완료한다.
5. Timezone 설정
기본 환경 설정으로 Timezone을 설정한다.
cp php.ini-production /usr/local/apache/conf/php.ini
vi /usr/local/apache/conf/php.ini
vi 편집기에서 date.timezone 을 찾아 설정해준다.
date.timezone = "Asia/Seoul"
6. PHP 모듈 설치 확인
vi /usr/local/apache/conf/httpd.conf 를 실행하여 httpd.conf 파일을 확인한다.
LoadModule 부분을 찾아 php5_module이 설정되어있는지 확인하고 안되어있다면 추가한다.
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .php3 .php4 .php5 .html .htm .inc
DirectoryIndex index.html index.htm index.php
7. 심볼릭 Phth 등록
ln -s /usr/local/php/bin/php /bin/php
ln -s /usr/local/php/bin/php-config /usr/local/bin/php-config
ln -s /usr/local/php/bin/phpize /usr/local/bin/phpize
8. Test
/usr/local/apache/htdocs에 아래와 같은 내용으로 phpinfo.php를 만들어 php가 정상 동작 하는지 확인한다.
$echo "<?php phpinfo(); ?>" > /usr/local/apache/htdocs/phpinfo.php</code>