Centos7.6编译安装php5.6
当前系统环境 Centos7.6,php版本5.6.40
1、安装epel源,安装所需依赖
yum install epel-release
yum install gcc gcc-c++ libxml2-devel libxml2 openssl openssl-devel curl curl-devel libjpeg-devel libpng-devel freetype-devel icu libicu libicu-devel libmcrypt libmcrypt-devel libxslt libxslt-devel
2、下载php5.6
cd /usr/local/src
wget https://www.php.net/distributions/php-5.6.40.tar.gz
3、解压编译安装
useradd -s /bin/false -M www
tar xf php-5.6.40.tar.gz
cd php-5.6.40
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-opcache --enable-intl --with-xsl
make
make install
4、配置php.ini和php-fpm.conf
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
编辑php.ini设置以下参数
vi /usr/local/php/etc/php.ini
cgi.fix_pathinfo=0
date.timezone = PRC
short_open_tag = On
编辑php-fpm.conf设置以下参数
vi /usr/local/php/etc/php-fpm.conf
listen.owner = www
listen.group = www
listen = /var/run/php-fpm/php-fpm.sock
创建socket目录
mkdir /var/run/php-fpm/
注意:php.ini和php-fpm根据使用情况自行调整,这里只是一个简单的示例
5、配置php-fpm服务并设置开机启动
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
6、配置环境变量
echo 'export PATH=$PATH:/usr/local/php/bin' >> /etc/profile
echo 'export PATH=$PATH:/usr/local/php/bin' >> ~/.bashrc
source /etc/profile
7、启动php服务
/etc/init.d/php-fpm start
8、在nginx上配置php
location ~ [^/]\.php(/|$) {
try_files $uri =404;
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
}
9、验证
最后写个phpinfo到web下,验证php是否正常即可