线程安全的 PHP 版本安装
线程安全的 PHP 版本只能通过编译安装 并且编译选项
必须加上--enable-maintainer-zts 下面以安装php7.2为例子。
结尾有常见问题,安装过程中遇到报错优先查看
一、安装EPEL仓库
sudo yum install epel-release
二、安装Nginx
sudo yum install epel-release -y
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
通过IP地址访问 http://ip地址
三、安装编译所需依赖
sudo yum install gcc gcc-c++ make zlib-devel pcre-devel openssl-devel libxml2-devel bzip2-devel libcurl-devel
四、上传PHP源码和解压
直接使用使用XTerminal.app软件上传php-7.2.26.tar.gz压缩包到root目录下并使用右键菜单解压(也可使用tar -xzvf php-7.2.34.tar.gz命令解压,但是本人尝试多次中途服务器会自动退出XTerminal软件)
五、安装一些配置插件
sudo yum install libXpm-devel
sudo yum install libpng-devel
sudo yum install xorg-x11-proto-devel
sudo yum install postgresql-devel
sudo yum install net-snmp-devel
sudo yum install freetype-devel
sudo yum install libxslt-devel
六、配置PHP 7.2编译选项
./configure --prefix=/usr/local/php --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pear --with-pdo-mysql --with-xmlrpc --with-xsl --with-zlib --enable-bcmath --enable-fpm --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-maintainer-zts
七、编译和安装PHP 7.2
make
sudo make install
八、配置PHP-FPM
cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
九、手动创建 systemd 服务文件
安装 PHP-FPM 后,通常会自动创建一个 systemd 服务文件。你可以检查 /etc/systemd/system/ 或 /lib/systemd/system/ 目录下是否存在与 php-fpm 相关的服务文件
ls /etc/systemd/system/php-fpm*
ls /lib/systemd/system/php-fpm*
如果找不到任何文件,则手动创建 systemd 服务文件
在/etc/systemd/system/ 目录创建一个php-fpm.service
文件,文件内容如下
[Unit]
Description=The PHP FastCGI Process Manager
After=network.target
[Service]
Type=simple
PIDFile=/run/php/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.d/www.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]