1.下载php
yum install wget -y && wget https://www.php.net/distributions/php-7.3.14.tar.gz
2.解压
tar -zxf php-7.3.14.tar.gz
3.进入到php解压目录
cd php-7.3.14
4.创建php所属用户组,如果nginx已经创建用户组则不用创建,nginx和php可以用同一个用户组
groupadd www
5.创建php所属用户,如果nginx已经创建用户则不用创建,nginx和php可以用同一个用户
useradd -g www www -M -s /sbin/nologin
6.安装依赖
yum install libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libxslt-devel -y
7.编译参数
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-gd --with-openssl --with-mhash --enable-pcntl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-opcache --with-xsl
如果编译的时候报这个错:Please reinstall the libzip distribution,就依次执行下面的命令安装libzip,如果没错误下面这些都不用执行:
wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make -j4
make install
tar -zxf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ..
make -j4
make install
执行上面cmake ..这一步的时候可能会报这个错:CMake 3.0.2 or higher is required. You are running version 2.8.12.2
这个错误是因为cmake版本太低,要安装cmake3才行,执行下面这行命令安装cmake3
wget https://github.com/Kitware/CMake/releases/download/v3.16.4/cmake-3.16.4.tar.gz
tar -zxf cmake-3.16.4.tar.gz
cd cmake-3.16.4
./bootstrap && make && make install
tar -zxf cmake-3.16.4.tar.gz
cd cmake-3.16.4
./bootstrap && make && make install
然后vim /etc/profile,修改这个文件,加入以下内容,加好后:wq保存退出
PATH=/usr/local/bin:$PATH
export PATH
export PATH
接着执行
source /etc/profile
这样就解决了cmake报错的问题,然后继续cmake ..往下执行。
安装好libzip后,切换到php解压目录,再编译
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-gd --with-openssl --with-mhash --enable-pcntl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-opcache --with-xsl
这时候可能还会报错:error: off_t undefined; check your library configuration
# 添加搜索路径到配置文件
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
# 更新配置
ldconfig -v
echo '/usr/local/lib64
/usr/local/lib
/usr/lib
/usr/lib64'>>/etc/ld.so.conf
# 更新配置
ldconfig -v
8.安装
make && make install
9.进入到php解压目录下,拷贝配置文件到php安装目录
cp php.ini-development /usr/local/php/etc/php.ini
10.进入php安装目录下的etc目录,拷贝配置文件
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf
cp php-fpm.conf.default php-fpm.conf
cd php-fpm.d
cp www.conf.default www.conf
11.启动php
/usr/local/php/sbin/php-fpm