WEB & WAS/PHP

CentOS 7 PHP 5.2.17 소스 컴파일 설치

서버엔지니어 2023. 3. 16.
728x90

## PHP 설치전 선행 작업

cd /usr/local/src/
yum install -y wget vim epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum update -y

## CentOS 7 Default 환경변수설정

echo " " >> /etc/profile
echo "####default PATH#####" >> /etc/profile
echo "export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:" >> /etc/profile
echo "#####################" >> /etc/profile

## 소스설치를 위한 패키지 환경 설치

yum install -y libdb-devel enchant-devel libxslt libxslt-devel net-snmp-devel readline-devel readline aspell-devel unixODBC unixODBC-devel libicu-devel icu libicu libc-client libc-client-devel libc-client-2007f freetype-devel freetype* freetype libXpm libXpm-devel libpng-devel libpng* libvpx-devel libvpx libcurl libcurl-devel curl* curl-devel curl tcp_wrappers-devel libzip environment-modules uw-imap-utils uw-imap-devel uw-imap uw-imap-static pam-devel libldb-devel openldap-devel cyrus-sasl-devel bzip2-devel bzip2 bzip2-libs ncurses-devel ncurses mysql-devel libjpeg-devel libjpeg* libjpeg-devel openssl-devel openssl* openssl-libs libxml* libxml2 libxml2-devel libmcrypt libmcrypt-devel libmcrypt* mcrypt mhash* mhash mhash-devel libmhash libmhash-devel expat-devel expat expat* gmp* gmp gmp-devel krb5* krb5-devel db4 db4-devel wget make cmake libtool* pcre* gdbm* gdbm gdbm-devel libtiff* libtiff libtiff-devel flex zlib* zlib-devel zlib gd* gd gd-devel patch t1lib t1lib-devel readline libedit-devel libtidy libtidy-devel gcc* gcc gcc-c++ libtermcap-devel dialog sqlite-devel oniguruma oniguruma-devel libzip5 mod_ssl postgresql-devel lcov systemtap-sdt-devel mod_ldap elfutils-devel libwebp-devel libwebp git gzip libnghttp2-devel valgrind* mod_proxy* editline editline-devel patchelf systemd-devel ImageMagick-devel libzstd-devel libffi libffi-devel libraqm-devel libraqm libsodium libsodium-devel

## CentOS 6 이하 관련 라이브러리 설정

mkdir /usr/kerberos
ln -s /usr/lib64 /usr/kerberos/lib

## PHP imap 관련 모듈 64비트 32비트 라이브러리 호환설정

ln -s /usr/lib64/libc-client.a /usr/lib/libc-client.a
unlink /usr/include/db.h
ln -s /usr/include/libdb4/db.h /usr/include/db.h
ln -s /usr/include/sqlext.h /usr/local/include/sqlext.h
ln -s /usr/lib64/libgdbm_compat.so /usr/local/lib64/libdbm.so

## openldap 호환

\cp -arpf /usr/lib64/libldap* /usr/lib/
ln -sf /usr/lib64/libm.so /usr/lib/libm.so
ln -sf /usr/lib64/libssl.so /usr/lib/libssl.so

## libXpm 모듈 32비트 호환

ln -s /usr/lib64/libXpm.so /usr/lib/
ln -s /usr/lib64/libXpm.so.4 /usr/lib/
ln -s /usr/lib64/libXpm.so.4.11.0 /usr/lib/

## PHP 이미지모듈 64비트 32비트 라이브러리 호환설정

ln -s /usr/lib64/libjpeg.so /usr/lib
ln -s /usr/lib64/libpng.so /usr/lib

 

## PHP 설치 전 선행작업 libmcrypt

cd /usr/local/src/APM_Setup
wget http://netcologne.dl.sourceforge.net/sourceforge/mcrypt/libmcrypt-2.5.8.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
cd /usr/local/src/APM_Setup/libmcrypt-2.5.8
./configure
make -j
make install

 

## PHP 설치 전 선행작업 mhash

cd /usr/local/src/APM_Setup
wget https://sourceforge.net/projects/mhash/files/mhash/0.9.9.9/mhash-0.9.9.9.tar.gz/download
\mv -f /usr/local/src/APM_Setup/download /usr/local/src/APM_Setup/mhash-0.9.9.9.tar.gz
tar zxvf /usr/local/src/APM_Setup/mhash-0.9.9.9.tar.gz
cd /usr/local/src/APM_Setup/mhash-0.9.9.9
./configure
make -j
make install

 

## PHP 다운로드 및 배포

cd /usr/local/src/APM_Setup
wget http://museum.php.net/php5/php-5.2.17.tar.gz
wget https://museum.php.net/php5/php-5.2.17.tar.gz
wget https://sourceforge.net/projects/korwah/files/source/php/php-5.2.17.tar.gz/download
\mv -f download php-5.2.17.tar.gz.2
tar zxvf php-5.2.17.tar.gz
cd /usr/local/src/APM_Setup/php-5.2.17

 

## Apache 2.4 와 PHP 5.2 관련 이슈 설정

Apache 2.4는 진행해야하고, 만약 Apache 2.2라면 하지말것!

sed -i 's/unixd_config;/ap_unixd_config;/g' /usr/local/src/APM_Setup/php-5.2.17/sapi/apache2handler/php_functions.c
sed -i 's/unixd_config.user/ap_unixd_config.user/g' /usr/local/src/APM_Setup/php-5.2.17/sapi/apache2handler/php_functions.c
sed -i 's/unixd_config.group/ap_unixd_config.group/g' /usr/local/src/APM_Setup/php-5.2.17/sapi/apache2handler/php_functions.c

 

## gmp 관련변수오류로인한변경

sed -i 's/__GMP_BITS_PER_MP_LIMB/GMP_LIMB_BITS/g' /usr/local/src/APM_Setup/php-5.2.17/ext/gmp/gmp.c

 

## PHP 5.2 패치파일 적용

cd /usr/local/src/APM_Setup/php-5.2.17
wget -O php.patch  https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
patch -p0 -b < php.patch

 

## PHP 컴파일 설정

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --enable-cgi --enable-fastcgi --enable-force-cgi-redirect --enable-discard-path --with-config-file-path=/usr/local/apache/conf --enable-bcmath --enable-mod-charset --with-iconv-dir --with-mime-magic --with-libxml-dir --with-xmlrpc --with-openssl --with-pcre-dir=/usr/local/ --with-zlib --with-zlib-dir --with-bz2 --enable-calendar --enable-ctype --with-curl --enable-dba --enable-dbase --with-pspell --with-dbm --enable-ftp --with-gd --enable-gd-native-ttf --with-gdbm --with-jpeg-dir --with-png-dir --with-ttf --with-freetype-dir --with-t1lib --enable-shmop --with-gettext --with-gmp --with-imap --with-imap-ssl --with-kerberos --enable-mbstring --with-libmbfl --with-mhash --with-mcrypt --enable-sockets --with-regex=php --enable-mbregex --enable-sysvmsg --enable-sysvsem --enable-sysvshm --with-ldap --enable-soap --with-ldap-sasl --with-ncurses --with-tidy --with-xsl --enable-wddx --enable-zend-multibyte --enable-zip --enable-exif --enable-pcntl --enable-sigchild --enable-posix --enable-magic-quotes --enable-libgcc --with-mysql=/usr/local/mysql --with-pdo-mysql --with-mysqli --enable-libxml --with-readline --with-libedit --enable-session --enable-simplexml --enable-xml --enable-reflection --with-pcre-regex --enable-filter --with-xpm-dir --enable-xmlwriter --enable-xmlreader --enable-tokenizer --enable-safe-mode --disable-debug --enable-zend-multibyte --with-mysql-sock=/tmp/mysql.sock --enable-maintainer-zts --enable-zts --enable-roxen-zts --enable-fpm --with-fpm-user=nobody --with-fpm-group=nobody

 

 --enable-gd-jis-conv

 

## lber 라이브러리 참조 못하여 강제적으로 넣어주기

sed -i 's/-lm -lcrypt/-lm -lcrypt -llber/g' /usr/local/src/APM_Setup/php-5.2.17/Makefile
make -j
make install

 

## php.ini 설정파일 수정

\cp -arpf php.ini-dist /usr/local/apache/conf/php.ini
sed -i 's/;upload_tmp_dir =/upload_tmp_dir = \/tmp/g' /usr/local/apache/conf/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 100M/g' /usr/local/apache/conf/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 100M/g' /usr/local/apache/conf/php.ini
sed -i 's/memory_limit = 128M/memory_limit = 256M/g' /usr/local/apache/conf/php.ini
sed -i 's/allow_url_fopen = On/allow_url_fopen = Off/g' /usr/local/apache/conf/php.ini
sed -i 's/expose_php = On/expose_php = Off/g' /usr/local/apache/conf/php.ini
sed -i 's/display_errors = Off/display_errors = On/g' /usr/local/apache/conf/php.ini
sed -i 's/log_errors = Off/log_errors = On/g' /usr/local/apache/conf/php.ini
sed -i 's/;error_log = syslog/error_log = syslog/g' /usr/local/apache/conf/php.ini
sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/apache/conf/php.ini
sed -i 's/;date.timezone =/date.timezone = "Asia\/Seoul"/g' /usr/local/apache/conf/php.ini
sed -i 's/session.gc_maxlifetime = 1440 /session.gc_maxlifetime = "3600"/g' /usr/local/apache/conf/php.ini
sed -i 's/register_globals = Off/register_globals = On/g' /usr/local/apache/conf/php.ini

## imagick PHP 추가 모듈 설치

cd /usr/local/src/APM_Setup
wget https://pecl.php.net/get/imagick-3.1.2.tgz
tar zxvf imagick-3.1.2.tgz
cd imagick-3.1.2
/usr/local/php/bin/phpize && ./configure --with-php-config=/usr/local/php/bin/php-config && make -j && make install
sed -i 's/extension_dir = /;extension_dir = /g' /usr/local/apache/conf/php.ini
echo "extension_dir = \"/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613\"" >> /usr/local/apache/conf/php.ini
echo "extension=imagick.so" >> /usr/local/apache/conf/php.ini
echo " " >> /usr/local/apache/conf/php.ini

## Apache php 모듈 확인 및 재시작

apachectl -M | grep php

/etc/init.d/apachectl restart

 

## APM 환경변수 설정

아래 설정은 Apache, MySQL, PHP 부분이 모두 포함되어있습니다.
echo " " >> /etc/profile
echo "APACHE_HOME=/usr/local/apache" >> /etc/profile
echo "MySQL_HOME=/usr/local/mysql" >> /etc/profile
echo "PHP_HOME=/usr/local/php" >> /etc/profile
echo " " >> /etc/profile
echo "export PATH="\$"APACHE_HOME/bin:"\$"MySQL_HOME/bin:"\$"PHP_HOME/bin:"\$"PHP_HOME/sbin"\$"{PATH:+:"\$"{PATH}}" >> /etc/profile
source /etc/profile

댓글