这里有最新的使用文档和教程
Debian 10.9.x编译安装多版本PHP
准备工作请参考: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 #重新加载配置
nano /etc/rc.d/init.d/php53-fpm
prefix=/usr/local/php53
php_fpm_BIN=${exec_prefix}/sbin/php53-fpm
ctrl+o #保存
ctrl+x #退出
mv /usr/local/php53/sbin/php-fpm /usr/local/php53/sbin/php53-fpm
service php53-fpm start #启动
nano /usr/local/php53/etc/php.ini #编辑配置文件
找到:disable_functions =
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_php = On
修改为:expose_php = OFF #禁止显示php版本的信息
找到:short_open_tag = Off
修改为:short_open_tag = ON #支持php短标签
ctrl+o #保存
ctrl+x #退出
2.54、安装php5.4.x
nano /usr/local/gd/include/gd_io.h #添加void (*data);
typedef struct gdIOCtx
{
int (*getC) (struct gdIOCtx *);
int (*getBuf) (struct gdIOCtx *, void *, int);
void (*putC) (struct gdIOCtx *, int);
int (*putBuf) (struct gdIOCtx *, const void *, int);
/* seek must return 1 on SUCCESS, 0 on FAILURE. Unlike fseek! */
int (*seek) (struct gdIOCtx *, const int);