当前系统环境Centos7.6,php版本5.6.39
1、安装epel源,安装所需依赖
1 2 |
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
1 2 |
cd /usr/local/src wget http://cn2.php.net/distributions/php-5.6.39.tar.gz |
3、解压编译安装
1 2 3 4 5 6 |
useradd -s /bin/false -M www tar xf php-5.6.39.tar.gz cd php-5.6.39 ./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
1 2 |
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设置以下参数
1 |
vi /usr/local/php/etc/php.ini |
1 2 3 |
cgi.fix_pathinfo=0 date.timezone = PRC short_open_tag = On |
编辑php-fpm.conf设置以下参数
1 |
vi /usr/local/php/etc/php-fpm.conf |
1 2 3 |
listen.owner = www listen.group = www listen = /var/run/php-fpm/php-fpm.sock |
创建socket目录
1 |
mkdir /var/run/php-fpm/ |
注意:php.ini和php-fpm根据使用情况自行调整,这里只是一个简单的示例
5、配置php-fpm服务并设置开机启动
1 2 3 4 |
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、配置环境变量
1 2 3 |
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
1 2 3 4 5 6 |
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是否正常即可
原文链接:Centos7.6编译安装php5.6,转载请注明来源!