环境:centos7
PHP版本:7.4.14
PHP下载地址:
链接:https://pan.baidu.com/s/1zmNJffhrOPpK8XFwBLDZsA
提取码:lz1p
[root@localhost ~]# useradd PHP -s /sbin/nologin
2.解压PHP tar包
[root@localhost ~]# tar -zxvf PHP-7.4.14.tar.gz
3.安装依赖包
yum install libxml2-devel sqlite-devel libcurl-devel oniguruma-devel libpng-devel libjpeg-devel freetype-devel libzip-devel openssl-devel -y
4.进入PHP解压目录进行编译
[root@localhost ~]# cd PHP-7.4.14 [root@localhost PHP-7.4.14]# ./configure --prefix=/PHP --with-config-file-path=/PHP/etc --with-mhash --with-openssl --with-MysqLi=MysqLnd --with-pdo-MysqL=MysqLnd --with-iconv --with-zlib --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-bcmath --enable-shmop --enable-sysvsem --enable-gd --with-jpeg --with-freetype --enable-mbregex --enable-mbstring --enable-ftp --enable-pcntl --enable-sockets --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-opcache --enable-fpm --with-fpm-user=PHP --with-fpm-group=PHP --without-gdbm --enable-fast-install --disable-fileinfo
5.编译不过出现此错误
checking for oniguruma... no configure: error: Package requirements (oniguruma) were not met: No package 'oniguruma' found
请安装以下rpm包
[root@localhost PHP-7.4.14]# yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5PHP-6.9.6-1.el7.remi.x86_64.rpm [root@localhost PHP-7.4.14]# yum install https://rpms.remirepo.net/enterprise/7/remi/x86_64/oniguruma5PHP-devel-6.9.6-1.el7.remi.x86_64.rpm
6.出现此提示说明编译成功,接下来进行安装
+--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP.
[root@localhost PHP-7.4.14]# make && make install
7.安装成功后将启动脚本复制到安装目录下
[root@localhost PHP-7.4.14]# cp sapi/fpm/init.d.PHP-fpm /PHP
[root@localhost PHP-7.4.14]# cp PHP.ini-production /PHP/etc/PHP.ini
8.进入PHP安装目录下的etc目录,创建PHP-fpm.conf配置文件
[root@localhost PHP-7.4.14]# cd /PHP/etc/ [root@localhost etc]# ll total 80 -rw-r--r--. 1 root root 5327 Feb 5 00:51 PHP-fpm.conf.default drwxr-xr-x. 2 root root 30 Feb 5 00:51 PHP-fpm.d -rw-r--r--. 1 root root 72584 Feb 5 01:06 PHP.ini [root@localhost etc]# cp PHP-fpm.conf.default PHP-fpm.conf
[root@localhost etc]# ll total 88 -rw-r--r--. 1 root root 5327 Feb 5 01:07 PHP-fpm.conf -rw-r--r--. 1 root root 5327 Feb 5 00:51 PHP-fpm.conf.default drwxr-xr-x. 2 root root 30 Feb 5 00:51 PHP-fpm.d -rw-r--r--. 1 root root 72584 Feb 5 01:06 PHP.ini [root@localhost etc]# cd PHP-fpm.d/ [root@localhost PHP-fpm.d]# mv www.conf.default www.conf
10.启动PHP
[root@localhost PHP]# bash init.d.PHP-fpm start Starting PHP-fpm done
11.测试PHP是否安装成功
编辑Nginx.conf,在server内添加location段
location ~ \.PHP$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.PHP; fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; include fastcgi.conf; }
随后在/Nginx/html目录内添加一个文件index.PHP文件,内容如下
[root@localhost html]# ll total 12 -rw-r--r--. 1 root root 494 Jan 29 23:45 50x.html -rw-r--r--. 1 root root 612 Jan 29 23:45 index.html -rw-r--r--. 1 root root 19 Feb 5 01:49 index.PHP [root@localhost html]# cat index.PHP <?PHP PHPinfo() ?>
[root@localhost html]#
随后浏览器访问服务器ip/index.PHP,出现如下页面说明PHP安装成功!