一、环境准备
主机 | IP | 身份 |
web01 | 10.0.0.7 | 编译安装PHP |
二、准备安装
1.新建目录
[root@jindada ~]# mkdir /php
2.上传源码包并解压
[root@jindada ~]# cd /php/
[root@jindada /php]# rz
[root@jindada /php]# ll
-rw-r--r-- 1 root root 16516067 Aug 31 21:11 php-7.4.9.tar.gz
[root@jindada /php]# tar xf php-7.4.9.tar.gz
3.安装依赖包
[root@jindada /php]# yum install libxml2-devel sqlite-devel libcurl-devel oniguruma-devel libpng-devel libjpeg-devel freetype-devel libzip-devel openssl-devel -y
4.编译参数
[root@jindada /php]# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/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.安装
[root@jindada /php]# make && make install
6.复制相关配置文件到PHP相关路径
[root@jindada /php]# cp /php/php-7.4.9/sapi/fpm/init.d.php-fpm /usr/local/php/
[root@jindada /php]# cp php.ini-production /usr/local/php/etc/php.ini
[root@jindada /php]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@jindada /php]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
7.启动php-fpm
[root@jindada /php]#bash init.d.php-fpm start
三、测试
1.配置nginx站点文件
[root@jindada /etc/nginx/conf.d]# cat linux.php.com.conf
server{
listen 81;
server_name www.jinhuino1.cn;
location / {
root /code/php;
index index.php;
}
location ~ .php$ {
root /code/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2.创建nginx站点目录
[root@jindada /etc/nginx/conf.d]# mkdir /code/php/
[root@jindada /code/php]# vim index.php
<?php
phpinfo()
?>
3.重启nginx
[root@jindada /code/php]# systemctl restart nginx
4.测试访问