一、介绍

  PHP为服务端脚本语言,本文为离线源码编译安装方式,方便选择适合自己的版本。

二、安装

2.1 下载

》》官网下载源码安装包

2.2 安装依赖

》》安装PHP依赖

yum -y install libxml2-devel sqlite-devel bzip2-devel libcurl-devel libpng-devel libjpeg-devel freetype-devel libicu-devel oniguruma-devel libxslt-devel

由于yum版本安装libzip-devel依赖包过低,必须下载新版本安装。

》》下载依赖包

 wget https://nih.at/libzip/libzip-1.2.0.tar.gz

》》解压依赖包

 tar xf libzip-1.2.0.tar.gz

》》配置编译安装依赖包

 cd libzip-1.2.0
 ./configure
make&&make install

》》配置环境变量

vim /etc/profile.d/libzip.sh 

》》内容如下:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH

》》更新环境

source /etc/profile 

2.3 安装

》》解压PHP源码包

》》configure选项(注意php目录版本)

./configure --prefix=/usr/local/php8 --with-config-file-path=/usr/local/php8/etc --with-curl --with-freetype --enable-gd --with-jpeg  --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql  --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xsl --with-zlib --with-zip -with-bz2 --with-iconv  --enable-fpm --enable-pdo  --enable-bcmath  --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl  --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-sysvsem --enable-cli --enable-opcache --enable-intl --enable-calendar --enable-static --enable-mysqlnd --disable-fileinfo

》》编译并安装

》》安装完成,查看版本

》》配置软连接

ln -s /usr/local/php8/ /usr/local/php

2.4 生成各配置文件

》》生成php.ini配置文件

cp php.ini-production /usr/local/php/etc/php.ini


》》生成www.conf配置文件

cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf


》》生成php-fpm配置文件

2.5 配置PHP文件

》》配置php.ini文件

》编辑配置文件如下

2.6 生成php-fpm启动文件

》》创建启动目录,复制启动文件,修改启动文件权限

》》配置system启动

[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target

[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target


》》system重载

2.7 启动php-fpm

》》启动php-fpm

》》再次确认进程是否启动

》》查看php-fpm默认监听端口

三、卸载PHP

直接删除php包即可

参考链接:
https://help.aliyun/document_detail/97251.html
https://wwwblogs/jhno1/p/14237034.html

更多推荐

源码安装PHP