LNMP环境之编译安装php
环境:centos7
php版本:7.4.14
php下载地址:
链接:https://pan.baidu.com/s/1zmNJffhrOPpK8XFwBLDZsA
提取码:lz1p
1.新建php用户并设置禁止该用户登录服务器
[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
php.ini文件复制到/php/etc目录下
[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
9.进入php-fmp.d目录,将www文件重命名
[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安装成功!