Install dependencies:
yum -y install gcc gcc-c++ glibc automake autoconf libtool make
yum -y install libxslt-devel libjpeg libjpeg-devel libpng libpng-devel
yum -y install freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel
yum -y install glibc glibc-devel glib2 bzip2-devel ncurses ncurses-devel
yum -y install curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel libidn libidn-devel
yum -y install openssl openssl-devel sqlite-devel libcurl-devel libpng-devel libjpeg-devel
yum -y install freetype-devel libicu-devel libxslt-devel
yum -y install systemd-devel
yum -y install oniguruma oniguruma-devel
# gmp扩展
yum -y install gmp-devel
If oniguruma cannot be installed, use:
# 方案一:
yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-6.7.0-1.el7.x86_64.rpm
yum -y install http://mirror.centos.org/centos-7/7.7.1908/cloud/x86_64/openstack-queens/oniguruma-devel-6.7.0-1.el7.x86_64.rpm
#方案二:
yum -y install http://down.24kplus.com/linux/oniguruma/oniguruma-6.7.0-1.el7.x86_64.rpm
yum -y install http://down.24kplus.com/linux/oniguruma/oniguruma-devel-6.7.0-1.el7.x86_64.rpm
upgrade cmake
cd /usr/local/src
yum -y install wget
yum remove cmake -y
wget https://cmake.org/files/v3.21/cmake-3.21.0-linux-x86_64.tar.gz
tar zxvf cmake-3.21.0-linux-x86_64.tar.gz
mv cmake-3.21.0-linux-x86_64 /usr/local/cmake
edit and configure
vim /etc/profile.d/cmake.sh
export CMAKE_HOME=/usr/local/cmake
export PATH=$CMAKE_HOME/bin:$PATH
# 执行
source /etc/profile.d/cmake.sh
Install libzip
wget https://libzip.org/download/libzip-1.8.0.tar.gz
tar -zxvf libzip-1.8.0.tar.gz
cd libzip-1.8.0
mkdir build && cd build
cmake ..
make install
export PKG_CONFIG_PATH="/usr/local/lib64/pkgconfig/":$PKG_CONFIG_PATH
Download the php source package, compile and install
groupadd php-fpm
useradd -s /sbin/nologin -g php-fpm -M php-fpm
cd /usr/loca/src
wget https://www.php.net/distributions/php-8.1.3.tar.gz
tar zxvf php-8.1.3.tar.gz
compile parameters
./configure \
--prefix=/usr/local/php8 \
--with-config-file-path=/usr/local/php8 \
--with-config-file-scan-dir=/usr/local/php8/php.d \
--enable-mysqlnd \
--with-mysqli \
--with-pdo-mysql \
--enable-gd \
--with-gmp \
--with-jpeg \
--with-iconv \
--with-zlib \
--with-zip \
--with-openssl \
--enable-xml \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-pcntl \
--enable-sockets \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-freetype \
--enable-opcache \
--enable-fpm \
--with-fpm-user=php-fpm \
--with-fpm-group=php-fpm \
--with-fpm-systemd \
--disable-fileinfo
Execute compilation:
make && make install
Configure php.ini
php.ini-development test development environment
php.ini-production production environment
Copy a copy to the specified directory (choose according to your own situation, you can compare the differences between these two files):
cp php.ini-production /usr/local/php8/etc/php.ini
Configure php-fpm:
# 设置目录
mkdir /home/log/
cd /usr/local/php8/etc
cp php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
Set pid and log
error_log = /home/log/php-fpm.log
pid = /home/log/php-fpm.pid
Configure www
cd /usr/local/php8/etc/php-fpm.d
cp www.conf.default www.conf
Use systemctl command to control php-fpm
cd /usr/local/src/php-8.1.3
cp ./sapi/fpm/php-fpm.service /usr/lib/systemd/system/
managephp-fpm
# 开机启动
systemctl enable php-fpm
# 启动
systemctl start php-fpm
# 查看状态
systemctl status php-fpm
# 停止
systemctl stop php-fpm
Add environment variable:
vim /etc/profile
# 末尾追加
export PATH=$PATH:'/usr/local/php8/bin/'
# wq 保存退出,执行
source /etc/profile
test:
php -v
question
Why do you need to set a log directory for php-fpm? Doesn't the default work?
In the systemd configuration file of php-fpm (/usr/lib/systemd/system/php-fpm.service),
when ProtectSystem=true, the php-fpm process will mount the /usr and /boot directories in a read-only manner;
when When ProtectSystem=full, the php-fpm process will mount the /usr, /boot and /etc directories in a read-only manner.
Solution:
- Open the systemd configuration file /usr/lib/systemd/system/php-fpm.service of php-fpm, and change ProtectSystem=true to ProtectSystem=false. This method will cause certain risks to the system and is not recommended for production environments;
- Modify the php-fpm configuration file php-fpm.conf, and set error_log to a file in a directory other than /usr, /boot, /etc.