当前系统Centos6.9,已经安装好lnmp(php5.6 mysql5.1)军哥环境,在此基础上并存一个php5.2的版本。
PS:php5.2.14默认不支持php-fpm的,需要打上fpm补丁
安装epel源
1 |
yum -y install epel-release |
安装所需依赖
1 |
yum -y install openldap-devel openldap net-snmp net-snmp-devel libpng libpng-devel mhash-devel libtool-ltdl-devel gcc gcc-c++ libxml2 libxml2-devel openssl-devel openssl curl-devel curl libjpeg libjpeg-devel freetype freetype-demos freetype-devel php-ldap php-xmlrpc zlib zlib-devel php-soap autoconf |
编译libiconv1.13.1
1 2 3 4 5 6 7 |
cd /usr/src wget https://down.whsir.com/downloads/libiconv-1.13.1.tar.gz tar zxf libiconv-1.13.1.tar.gz cd /usr/src/libiconv-1.13.1 ./configure --prefix=/usr/local make -j 8 make install |
编译libmcrypt
1 2 3 4 5 6 7 8 |
cd /usr/src wget https://down.whsir.com/downloads/libmcrypt-2.5.8.tar.gz tar zxf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure make -j 8 make install /sbin/ldconfig |
编译libltdl库
1 2 3 4 |
cd /usr/src/libmcrypt-2.5.8/libltdl/ ./configure --enable-ltdl-install make -j 8 make install |
编译mhash
1 2 3 4 5 6 7 |
cd /usr/src/ wget https://down.whsir.com/downloads/mhash-0.9.9.9.tar.gz tar zxf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9 ./configure make -j 8 make install |
需要做一些软链
1 2 3 4 5 6 7 8 9 10 11 12 13 |
cp -frp /usr/lib64/libldap* /usr/lib/ ln -sv /usr/lib64/libjpeg.so /usr/lib/libjpeg.so ln -sv /usr/lib64/libpng.so /usr/lib/libpng.so ln -sv /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la ln -sv /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so ln -sv /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 ln -sv /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 ln -sv /usr/local/lib/libmhash.a /usr/lib/libmhash.a ln -sv /usr/local/lib/libmhash.la /usr/lib/libmhash.la ln -sv /usr/local/lib/libmhash.so /usr/lib/libmhash.so ln -sv /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2 ln -sv /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1 ln -sv /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config |
至此所需的一些依赖和包已经编译好了,接下来开始编译php5.2并打上php-fpm补丁
下载php5.2和php-fpm补丁
1 2 3 4 |
cd /usr/src/ wget https://down.whsir.com/downloads/php-5.2.14.tar.gz wget https://down.whsir.com/downloads/php-5.2.14-fpm-0.5.14.diff.gz tar zxf php-5.2.14.tar.gz |
打上php-fpm的补丁
1 |
gzip -cd php-5.2.14-fpm-0.5.14.diff.gz | patch -d php-5.2.14 -p1 |
编译php-5.2.14,因为当前php5.6的路径是在/usr/local/php下,所以避免和当前php冲突,我这里编译到了/usr/local/php52下
1 |
cd php-5.2.14 |
1 |
./configure --prefix=/usr/local/php52 --with-config-file-path=/usr/local/php52/etc --enable-fpm --with-mysql=/usr/local/mysql --with-iconv-dir=/usr/local/libiconv --with-mysqli=/usr/local/mysql/bin/mysql_config --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-ttf --enable-gd-jis-conv --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --without-pear --enable-ftp --with-snmp |
1 |
make ZEND_EXTRA_LIBS='-liconv' -j 8 |
1 |
make install |
配置php.ini和php-fpm启动程序
1 2 3 |
cp php.ini-recommended /usr/local/php52/etc/php.ini cp /usr/local/php52/sbin/php-fpm /etc/init.d/php52-fpm chmod +x /etc/init.d/php52-fpm |
修改php-fpm需要注意下面几处配置
1 |
vi /usr/local/php52/etc/php-fpm |
1 2 3 4 5 6 7 8 9 |
<value name="listen_address">/tmp/php52-cgi.sock</value> 这里改成/tmp/php52-cgi.sock <value name="user">nobody</value> <value name="group">nobody</value> 表示php的fastcgi进程以什么用户以及用户组来运行,默认该行是注释掉的,需要打开 <value name="display_errors">0</value> 是否显示php错误信息 <value name="max_children">5</value> 最大的子进程数目 |
修改php.ini文件,修改几项参数
1 |
vi /usr/local/php52/etc/php.ini |
1 2 3 4 5 6 |
post_max_size = 50M upload_max_filesize = 32M date.timezone = PRC short_open_tag = On cgi.fix_pathinfo=0 max_execution_time = 300 |
启动php5.2
1 |
/etc/init.d/php52-fpm start |
最后在nginx中配置下php52就可以了
1 2 3 4 5 6 7 |
location ~ [^/]\.php(/|$) { try_files =404; fastcgi_pass unix:/tmp/php52-cgi.sock; fastcgi_index index.php; include fastcgi.conf; } |
原文链接:php5.2.14多版本共存编译,转载请注明来源!