官网下载路径:https://www.php.net/downloads
下载和解压
cd /usr/local/src/
wget https://www.php.net/distributions/php-7.3.22.tar.bz2
tar -xzvf php-7.3.22.tar.bz2
创建用户:下面编译会有指定用户,不指定的话最后启动服务会报错
useradd -s /sbin/nologin php-fpm
cd php-7.3.22
./configure
--prefix=/usr/local/php-fpm
//指定安装路径
--with-config-file-path=/usr/local/php-fpm/etc
//指定配置文件路径
--enable-fpm
//开启fpm这个功能
--with-fpm-user=php-fpm
// 指定用户为php-fpm
--with-fpm-group=php-fpm
//指定组 为php-fpm
--with-mysql=/usr/local/mysql
//老版本 关联mysql的参数
--with-mysqli=/usr/local/mysql/bin/mysql_config
//新版本 关联mysql的参数
--with-pdo-mysql=/usr/local/mysql
//关联mysql的参数
--with-mysql-sock=/tmp/mysql.sock
//指定sockt
--with-libxml-dir
这一列和下面所有都是PHP的模块,为了实现PHP的功能
-with-gd
--with-jpeg-dir
--with-png-dir
--with-freetype-dir
--with-iconv-dir
--with-zlib-dir
--with-mcrypt
--enable-soap
--enable-gd-native-ttf
--enable-ftp
--enable-mbstring
--enable-exif
--with-pear
--with-curl
--with-openssl
错误1:
checking for cc... no
checking for gcc... no
解决:yum install -y gcc
错误2:
configure: error: libxml2 not found. Please check your libxml2 installation.
解决:yum list | grep libxmle ; yum install -y libxml2-devel.x86_64
错误3:
configure: error: Cannot find OpenSSL‘s <evp.h>
解决:yum list | grep -i openssl ; yum install -y openssl-devel.x86_64
错误4:
checking for cURL 7.15.5 or greater... configure: error: cURL version 7.15.5 or later is required to compile php with cURL support
解决:yum list | grep -i curl ; yum install -y libcurl-devel.x86_64
错误5:
configure: error: jpeglib.h not found
解决:yum list | grep jpeg ; yum install -y libjpeg-turbo-devel.x86_64
错误6:
configure: error: png.h not found.
解决:yum list | grep png ;yum install -y libpng-devel.x86_64
错误7:
configure: error: freetype-config not found.
解决:yum list | grep freetype ;yum install -y freetype-devel.x86_64
错误8:
configure: error: Please reinstall the mysql distribution
解决:重新下载一个低版本的mysql/mariadb
wget
http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
tar -xzvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql5.6
更改编译参数:
--with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql
改成
--with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6
改完后继续执行
cd /usr/local/src/php.7.3.22
./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql5.6 --with-mysqli=/usr/local/mysql5.6/bin/mysql_config --with-pdo-mysql=/usr/local/mysql5.6 --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
输出结果可用echo $?验证,结果为0继续下面编译
make
make install
cd /usr/local/php-fpm/etc
[root@jinkai etc]# ls
pear.conf php-fpm.conf.default php-fpm.d
php-fpm.conf.default 模板配置文件
[root@jinkai etc]# cp php-fpm.conf.default php-fpm.conf 服务本身的配置文件
生成php-fpm.conf 配置文件,不然php-fpm无法启动
cd /usr/local/src/php-7.3.22
cp php.ini-development /usr/local/php-fpm/etc/php.ini
生成php.ini配置文件,这个是php的配置文件
添加到启动服务里面,设置开机启动
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpm on
chkconfig --list
设置执行权限
chmod 755 /etc/init.d/php-fpm
启动服务
service php-fpm start
错误:Starting php-fpm [09-Sep-2020 15:31:49] WARNING: Nothing matches the include pattern ‘/usr/local/php-fpm/etc/php-fpm.d/.conf‘ from /usr/local/php-fpm/etc/php-fpm.conf at line 143.
解决:查看错误提示的文档143行
vim /usr/local/php-fpm/etc/php-fpm.conf
143:include=/usr/local/php-fpm/etc/php-fpm.d/.conf
查看这个文件下是否存在*.conf文件
/usr/local/php-fpm/etc/php-fpm.d/
[root@jinkai php-7.3.22]# ls /usr/local/php-fpm/etc/php-fpm.d/
www.conf.default
[root@jinkai php-7.3.22]# cp www.conf.default www.conf
www.conf php-fpm?进程服务的扩展配置文件
重新启动用户
[root@jinkai php-fpm.d]# service php-fpm start
Starting php-fpm done
查看服务是否启动
ps aux| grep php-fpm
查看监听端口是否开启
netstat -lntp
原文:https://blog.51cto.com/11451960/2536097