发布作者:
大凯同学
百度收录:
正在检测是否收录...
作品采用:
《
署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
》许可协议授权
本次安装教程采用源码编译安装、亲测有效。记录
安装依赖性
yum install -y gcc make autoconf libtool-ltdl-devel libxml2-devel bzip2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel openssl-devel openldap-devel postgresql-devel sqlite-devel libxslt-devel libzip-devel
下载PHP 7.2的源码包
wget https://www.php.net/distributions/php-7.2.34.tar.gz
解压源码包到一个目录中
tar -zxvf php-7.2.34.tar.gz
进入解压后的目录中,运行以下命令进行配置:
cd php-7.2.34
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-config-file-scan-dir=/usr/local/php/etc/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-exif --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap --with-ldap-sasl --with-libdir=lib64 --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo
# 注意,上述命令中的参数根据实际情况进行调整。
运行以下命令进行编译和安装
make && make install
复制php配置文件并且
cp php.ini-development /usr/local/php/etc/php.ini
配置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
启动php-fpm
/usr/local/php/sbin/php-fpm
查看端口9000是不是已经启动,netstat -an |grep 9000,如果启动就算成功。
[root@lamp ~]# netstat -an |grep 9000
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
配置Nginx,使其支持php-fpm
在Nginx配置文件中添加以下内容:
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
重启Nginx
systemctl restart nginx
11.检查php是否安装成功
/usr/local/php/bin/php -v
至此php7.2安装完成!
切换到该目录下
cd usr/lib/systemd/system
创建文件、具体参考如下
[root@VM-24-5-centos system]# cat php-fpm.service
[Unit]
Description=php-fpm
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
ExecStop=pkill -9 php-fpm
[Install]
WantedBy=multi-user.target
刷新或者重新服务即可
—— 评论区 ——