准备工作请参考:https://www.31idc.com/helpcontent/529.html
开始编译安装php
注意:请执行以下两条命令,否则安装php可能会出错。
\cp -frp /usr/lib/x86_64-linux-gnu/libXpm.so* /usr/lib/
\cp -frp /usr/lib/x86_64-linux-gnu/libltdl.so* /usr/lib/
2.52、安装php5.2.17
cd /usr/local/src
tar zxvf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz#解压
mv mysql-5.7.30-linux-glibc2.12-x86_64 /usr/local/mysql57#移动目录到到/usr/local/mysql57下
cd /usr/local/src
tar zxvf php-5.2.17.tar.gz
gunzip php-5.2.17-fpm-0.5.14.diff.gz
patch -d php-5.2.17 -p1 < php-5.2.17-fpm-0.5.14.diff#给php源码打上fpm补丁
curl -o php-5.2.17.patch https://mail.gnome.org/archives/xml/2012-August/txtbgxGXAvz4N.txt
cd php-5.2.17
patch -p0 -b <../php-5.2.17.patch
./configure --prefix=/usr/local/php52 --with-config-file-path=/usr/local/php52/etc --with-mysql=/usr/local/mysql57--with-mysqli=/usr/local/mysql57/bin/mysql_config--with-mysql-sock=/tmp/mysql.sock --with-pdo-mysql=/usr/local/mysql57--with-gd=/usr/local/gd --with-freetype-dir=/usr/local/freetype --with-jpeg-dir=/usr/local/jpeg --with-png-dir=/usr/local/libpng --with-iconv --with-zlib --enable-xml --enable-discard-path --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl=/usr/local/ssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --with-mime-magic --enable-session --with-mcrypt --with-curl=/usr/local/curl --enable-ctype --with-mysqli=shared #配置,注意mysql路径是/usr/local/mysql57
make
make install
cp /usr/local/src/php-5.2.17/php.ini-dist /usr/local/php52/etc/php.ini#复制php配置文件到安装目录
#rm -rf /etc/php.ini #删除默认配置文件
#ln -s /usr/local/php52/etc/php.ini /etc/php.ini #创建链接到系统默认的位置
nano /usr/local/php52/etc/php-fpm.conf
<value name="listen_address">127.0.0.1:9006</value>
<value name="user">www</value>#去掉注释,修改用户为www
<value name="group">www</value>#去掉注释,修改用户组为www
ctrl+o #保存
ctrl+x #退出
设置 php-fpm开机启动
cp /usr/local/php52/sbin/php-fpm /etc/rc.d/init.d/php52-fpm
mv /usr/local/php52/sbin/php-fpm /usr/local/php52/sbin/php52-fpm
nano /etc/rc.d/init.d/php52-fpm
在#!/bin/bash下面添加两行
#chkconfig:345 62 62
#description:php-fpm
php_fpm_BIN=/usr/local/php52/bin/php-cgi
php_fpm_CONF=/usr/local/php52/etc/php-fpm.conf
php_fpm_PID=/usr/local/php52/logs/php-fpm.pid
ctrl+o #保存
ctrl+x #退出
chmod 775 /etc/rc.d/init.d/php52-fpm #赋予文件执行权限
update-rc.d php52-fpm defaults 99#设置开机启动
chkconfig php52-fpm on #设置开机启动
/usr/local/php52/sbin/php52-fpm start
service php52-fpm start
nano /usr/local/php52/etc/php.ini #添加mysqli扩展,在最后一行添加
extension="/usr/local/php52/lib/php/extensions/no-debug-non-zts-20060613/mysqli.so"
ctrl+o #保存
ctrl+x #退出
2.53、安装php5.3.x
cd /usr/local/src
tar -zvxf php-5.3.29.tar.gz
cd php-5.3.29
./configure --prefix=/usr/local/php53 --with-config-file-path=/usr/local/php53/etc --with-pdo-mysql=mysqlnd --enable-mysqlnd-compression-support --with-gd=/usr/local/gd --with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-freetype-dir=/usr/local/freetype --with-iconv --with-zlib-dir=/usr/local/zlib --enable-xml --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curlwrappers --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl=/usr/local/ssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl=/usr/local/curl --enable-ctype --enable-mysqlnd--with-xpm-dir=/usr
make #编译
make install #安装
cp php.ini-production /usr/local/php53/etc/php.ini #复制php配置文件到安装目录
#rm -rf /etc/php.ini #删除系统自带配置文件
#ln -s /usr/local/php53/etc/php.ini /etc/php.ini #添加软链接
cp /usr/local/php53/etc/php-fpm.conf.default /usr/local/php53/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
nano /usr/local/php53/etc/php-fpm.conf #编辑
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号
listen = 127.0.0.1:9053
ctrl+o #保存
ctrl+x #退出
设置 php-fpm开机启动
cp /usr/local/src/php-5.3.29/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php53-fpm #拷贝php-fpm到启动目录
chmod +x /etc/rc.d/init.d/php53-fpm #添加执行权限
update-rc.d php53-fpm defaults 99 #设置开机启动
systemctl daemon-reload#重新加载配置
https://www.xidc.xyz ,了解更多关于我们服务器的信息。无论您是寻找稳定高速的网络连接,还是需要专业的技术支持,XIDC都将是您的最佳选择。让我们携手共创美好未来!
申请测试TG: @AmmKiss