CentOS-7 编译安装php-7.4
1、环境准备
虚拟机:centos 7 ip:192.168.137.128
php-7.4.8.tar.gz
2、开始安装
添加php用户,用于运行php-fpm进程
useradd php -s /sbin/nologin
解压php源码包
tar -zxf php-7.4.8.tar.gz
安装依赖包
yum install libxml2-devel sqlite-devel libcurl-devel oniguruma-devel libpng-devel libjpeg-devel freetype-devel libzip-devel openssl-devel -y
编译参数参考
./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
编译没有问题就开始安装
[root@swarm-node1 php-7.4.8]# make && make install
编译安装完成
复制相关配置文件到php安装路径
启动脚本:php-7.4.8/sapi/fpm/init.d.php-fpm
[root@swarm-node1 fpm]# cp init.d.php-fpm /usr/local/php/
php.ini配置文件:php-7.4.8/php.ini-production
[root@swarm-node1 php-7.4.8]# cp php.ini-production /usr/local/php/etc/php.ini
创建php-fpm.conf配置文件
进到php的安装路径下面的etc
[root@swarm-node1 etc]# pwd /usr/local/php/etc [root@swarm-node1 etc]# [root@swarm-node1 etc]# ls php-fpm.conf.default php-fpm.d php.ini [root@swarm-node1 etc]# cp php-fpm.conf.default php-fpm.conf
进入php-fpm.d目录,将里面的文件也重命名一下
[root@swarm-node1 php-fpm.d]# pwd /usr/local/php/etc/php-fpm.d [root@swarm-node1 php-fpm.d]# [root@swarm-node1 php-fpm.d]# ls www.conf.default [root@swarm-node1 php-fpm.d]# [root@swarm-node1 php-fpm.d]# cp www.conf.default www.conf
启动php-fpm
执行init.d.php-fpm启动脚本,启动php-fpm
[root@swarm-node1 php]# bash init.d.php-fpm start
测试安装是否成功,可结合nginx配置一个index.php 写一个phpinfo的测试页面
nginx 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; }
index.php 配置文件
[root@swarm-node1 html]# cat index.php <?php phpinfo() ?> [root@swarm-node1 html]# [root@swarm-node1 html]#
启动nginx,访问网页