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
PHP
Copy
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 freetypefreetype-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运行用户和组
PHP
Copy
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.defaultphp-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
PHP
Copy
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-fpmStarting php-fpmdone[root@XiaoFeng etc]# ps aux |grep php-fpmroot 174980.00.0 1346286636 ?Ss 14:59 0:00 php-fpm: master process(/usr/local/php/etc/php-fpm.conf)php-fpm174990.00.0 1346286180 ?S14:59 0:00 php-fpm: pool wwwphp-fpm175000.00.0 1346286184 ?S14:59 0:00 php-fpm: pool wwwroot 175030.00.0 112724 992 pts/0S+ 15:00 0:00 grep --color=auto php-fpm
PHP
Copy加入开机启动,执行:
[root@XiaoFeng etc]# chkconfig php-fpm on[root@XiaoFeng etc]# chkconfig --list php-fpm
PHP
Copy
5.PHP7.2已经安装完了,接下来要配置nginx来支持php
[root@XiaoFeng etc]# cd /usr/local/nginx/conf[root@XiaoFeng conf]# vim nginx.conf
PHP
Copy第一行是空的,就在第二行修改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_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;includefastcgi_params;}
PHP
Copy在网站目录下写个php页面测试下
[root@XiaoFeng conf]# vim ../html/index.php

