CentOS7.6_php7.2_php5.6 编译安装 服务器: IBM x3850 X5 软件环境:CentOS7.6+Nginx1.16.0+php7.2.21+php5.6.40+mysql8.0.17 由于旧的业务需求,还要用到老PHP版本,所以装上php5.6,双版本同时运行 1.下载安装包 [root@XiaoFeng sjd]# wget https://www.php.net/distributions/php-7.2.21.tar.gz
[root@XiaoFeng sjd]# wget http://cn2.php.net/distributions/php-5.6.40.tar.gz
2.安装依赖包 [root@XiaoFeng sjd]# yum install -y curl curl-devel libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype
freetype-devel gmp gmp-devel php-mcrypt libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel zlib
[root@XiaoFeng sjd]# tar -zxvf php-7.2.21.tar.gz
[root@XiaoFeng sjd]# cd php-7.2.21
[root@XiaoFeng php-7.2.21]# useradd -s /sbin/nologin php-fpm #创建php-fpm运行用户和组
3.编译配置 [root@XiaoFeng php-7.2.21]# ./configure --prefix=/usr/local/php --exec-prefix=/usr/local/php --bindir=/usr/local/php/bin --sbindir=/usr/local/php/sbin --with-libdir=/usr/lib64 --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-config-file-path=/etc --with-libxml-dir --with-openssl --with-mysqli --with-zlib --enable-bcmath --with-bz2 --enable-calendar --with-curl --enable-exif --with-pcre-dir --enable-ftp --with-openssl-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-mbstring --with-libmbfl --with-onig --with-pdo-mysql --with-readline --enable-shmop --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-xmlrpc --with-xsl --enable-zip --with-pear --enable-mysqlnd --enable-shared --enable-inline-optimization --disable-debug --enable-xml --with-sqlite3 --with-iconv --with-cdb --enable-dom --enable-fileinfo --enable-filter --enable-json --enable-mbregex --enable-mbregex-backtrack --enable-pdo --with-pdo-sqlite --enable-session --enable-simplexml --enable-opcache
[root@XiaoFeng php-7.2.21]# make && make install
[root@XiaoFeng php-7.2.21]# cp php.ini-development /etc/php.ini #复制php配置文件
[root@XiaoFeng php-7.2.21]# cd /usr/local/php/etc/
[root@XiaoFeng etc]# cp php-fpm.conf.default php-fpm.conf #php-fpm配置文件
[root@XiaoFeng etc]# cp php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@XiaoFeng etc]# /usr/local/php/sbin/php-fpm -t #检验配置文件是否正确
[13-Aug-2019 14:39:38] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successfu
4.配置PHP命令和服务并开机启动 #启动php-fpm [root@XiaoFeng etc]# cp /sjd/php-7.2.21/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@XiaoFeng etc]# chmod +x /etc/init.d/php-fpm
[root@XiaoFeng etc]# service php-fpm start #启动php-fpm
Starting php-fpm done
[root@XiaoFeng etc]# ps aux |grep php-fpm
root 17498 0.0 0.0 134628 6636 ? Ss 14:59 0:00 php-fpm: master process
(/usr/local/php/etc/php-fpm.conf)
php-fpm 17499 0.0 0.0 134628 6180 ? S 14:59 0:00 php-fpm: pool www
php-fpm 17500 0.0 0.0 134628 6184 ? S 14:59 0:00 php-fpm: pool www
root 17503 0.0 0.0 112724 992 pts/0 S+ 15:00 0:00 grep --color=auto php-fpm
加入开机启动,执行: [root@XiaoFeng etc]# chkconfig php-fpm on
[root@XiaoFeng etc]# chkconfig --list php-fpm
5.PHP7.2已经安装完了,接下来要配置nginx来支持php [root@XiaoFeng etc]# cd /usr/local/nginx/conf
[root@XiaoFeng conf]# vim nginx.conf
第一行是空的,就在第二行修改user nginx; 运行nginx的用户为nginx 第45行,设置默认访问的首页文件,添加index.php 第65行到71行,去掉注释,第69行中的/scripts 改成$document_root 代码如下: location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
在网站目录下写个php页面测试下 [root@XiaoFeng conf]# vim ../html/index.php
<?php
echo phpinfo();
重启nginx [root@XiaoFeng conf]# /usr/local/nginx/sbin/nginx -s reload
打开浏览器看到PHP Version 7.2.21页面就完成了 6.接下来再安装另一个PHP版本5.6 安装依赖组件, libmcrypt这个yum安装不了的话就自己去下找包来安装 [root@web sjd]# tar -zxvf libmcrypt-2.5.8.tar.gz
[root@web sjd]# cd libmcrypt-2.5.8
[root@web libmcrypt-2.5.8]# ./configure --prefix=/usr/local
[root@web libmcrypt-2.5.8]# make && make install
7.开始安装PHP5.6
[root@XiaoFeng sjd]# tar -zxvf php-5.6.40.tar.gz
[root@XiaoFeng sjd]# cd php-5.6.40
[root@XiaoFeng php-5.6.40]# ./configure --prefix=/usr/local/php5.6 --with-config-file-path=/usr/local/php5.6/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --disable-ipv6 --with-pear --with-curl --enable-bcmath --enable-mbstring --enable-sockets --with-gd --with-libxml-dir=/usr/local --with-gettext
[root@XiaoFeng php-5.6.40]# make && make install
8.修改配置文件,改php-fpm端口为9001 [root@XiaoFeng php-5.6.14]# cp php.ini-production /usr/local/php5.6/etc/php.ini
[root@XiaoFeng php-5.6.14]# cd /usr/local/php5.6/etc/
[root@XiaoFeng etc]# cp php-fpm.conf.default php-fpm.conf
[root@XiaoFeng etc]# vim php-fpm.conf
[global]
pid = /usr/local/php5.6/var/run/php-fpm.pid
error_log = /usr/local/php5.6/var/log/php-fpm.log
[www]
listen = 127.0.0.1:9001
保存配置文件后,检验配置是否正确的方法为: [root@web etc]# /usr/local/php5.6/sbin/php-fpm -t
[13-Aug-2019 16:21:44] NOTICE: configuration file /usr/local/php5.6/etc/php-fpm.conf test is
successful
启动php-fpm [root@XiaoFeng etc]# cp /sjd/php-5.6.40/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm5.6
[root@XiaoFeng etc]# chmod +x /etc/init.d/php-fpm5.6
[root@XiaoFeng etc]# service php-fpm5.6 start
Starting php-fpm done
[root@XiaoFeng etc]# ps aux |grep php-fpm
root 17498 0.0 0.0 134628 6636 ? Ss 14:59 0:00 php-fpm: master process
(/usr/local/php/etc/php-fpm.conf)
php-fpm 17499 0.0 0.0 134692 8180 ? S 14:59 0:00 php-fpm: pool www
php-fpm 17500 0.0 0.0 134692 7124 ? S 14:59 0:00 php-fpm: pool www
root 26997 0.0 0.0 114764 4752 ? Ss 16:25 0:00 php-fpm: master process
(/usr/local/php5.6/etc/php-fpm.conf)
php-fpm 26998 0.0 0.0 114764 4300 ? S 16:25 0:00 php-fpm: pool www
php-fpm 26999 0.0 0.0 114764 4300 ? S 16:25 0:00 php-fpm: pool www
root 27004 0.0 0.0 112724 996 pts/0 S+ 16:25 0:00 grep --color=auto php-fpm
root@XiaoFeng etc]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 17498/php-fpm: mast
tcp 0 0 127.0.0.1:9001 0.0.0.0:* LISTEN 26997/php-fpm: mast
让它开机启动,执行: [root@XiaoFeng etc]# chkconfig php-fpm5.6 on
[root@XiaoFeng etc]# chkconfig --list php-fpm5.6
多PHP版本同时运行环境配置完成
|