centos7编译安装PHP7.2

发布 : 2019-05-16 分类 : 服务器 浏览 :

编译安装PHP7.2需要以下步骤:

1. 下载 PHP7.2

1
wget https://www.php.net/distributions/php-7.2.18.tar.gz

2. 解压 PHP7.2

1
tar-zxvf php-7.2.18.tag.gz

3. 切换进入目录

1
cd php-7.2.18

4. 安装依赖包

1
yum install -y libzip libzip-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 libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel

5. 编译配置

1
./configure --prefix=/usr/local/php  --with-config-file-path=/etc  --enable-fpm  --with-fpm-user=nginx  --with-fpm-group=nginx  --enable-inline-optimization  --disable-debug  --disable-rpath  --enable-shared  --enable-soap  --with-libxml-dir  --with-xmlrpc  --with-openssl  --with-mhash  --with-pcre-regex  --with-sqlite3  --with-zlib  --enable-bcmath --with-iconv  --with-bz2  --enable-calendar  --with-curl  --with-cdb  --enable-dom  --enable-exif  --enable-fileinfo  --enable-filter  --with-pcre-dir  --enable-ftp  --with-gd  --with-openssl-dir  --with-jpeg-dir  --with-png-dir  --with-zlib-dir  --with-freetype-dir  --enable-gd-jis-conv  --with-gettext  --with-gmp  --with-mhash  --enable-json  --enable-mbstring  --enable-mbregex  --enable-mbregex-backtrack  --with-onig  --enable-pdo  --with-mysqli=mysqlnd  --with-pdo-mysql=mysqlnd  --with-zlib-dir  --with-pdo-sqlite  --with-readline  --enable-session  --enable-shmop  --enable-simplexml  --enable-sockets  --enable-sysvmsg  --enable-sysvsem  --enable-sysvshm  --enable-wddx  --with-libxml-dir  --with-xsl  --enable-zip  --enable-mysqlnd-compression-support  --with-pear  --enable-opcache

6. 正式安装

1
make && make install

7. 添加环境变量

1
vim /etc/profile

在末尾添加:

1
export PATH="/usr/local/php/bin:$PATH"

使改动立即生效

1
source /etc/profile

8. 生成必要文件

1
2
3
4
5
6
7
cp php.ini-production /usr/local/php/etc/php.ini
cp sapi/fpm/php-fpm /usr/local/php/etc/php-fpm
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp /usr/local/src/php-7.2.18/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm #添加执行权限
chkconfig php-fpm on #设置开机启动

9. 启动php-fpm

1
2
cd /usr/local/php/sbin
./php-fpm

如果出现错误:ERROR: [pool www] cannot get uid for user ‘nginx’ 则新建nginx 用户组:

1
2
groupadd nginx
useradd -g nginx nginx

10. 配置nginx.conf文件,支持php

打开nginx.conf文件,添加如下代码:

1
2
3
4
5
6
7
8
vim nginx.conf
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;
}

以上步骤完成了,可用phpinfo()函数检测php是否安装成功。

知识 & 情怀 | 二者兼得

微信扫一扫, 向我投食

微信扫一扫, 向我投食

支付宝扫一扫, 向我投食

支付宝扫一扫, 向我投食

留下足迹