文章目录
Linux------PHP8.0编译安装和yum安装
PHP8.0编译安装
此内容参考于:https://www.cnblogs.com/jhno1/p/14237034.html
安装依赖
shell
# 安装编译依赖
[root@csq ~]# yum -y install ncurses ncurses-devel openssl-devel bison gcc gcc-c++ make cmake wget
# 安装php依赖
[root@csq ~]# yum -y install libxml2-devel sqlite-devel bzip2-devel libcurl-devel libpng-devel libjpeg-devel freetype-devel libicu-devel oniguruma-devel libxslt-devel
# 编译安装libzip-devel依赖包,因为yum版本的libzip-devel依赖包版本过低
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
tar -xvf libzip-1.2.0.tar.gz
cd libzip-1.2.0/
./configure && make && make install
vim /etc/profile
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH\
source /etc/profile
shell
[root@csq ~]# wget https://www.php.net/distributions/php-8.0.0.tar.gz
解压
shell
[root@csq ~]# tar -xvf php-8.0.0.tar.gz
[root@csq ~]# cd php-8.0.0/
编译
shell
./configure --prefix=/usr/local/php-8.0.0 --with-config-file-path=/usr/local/php-8.0.0/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
make && make install
查看安装版本
shell
# 配置环境变量
[root@csq php-8.0.0]# echo "export PATH=${PATH}:/usr/local/php-8.0.0/bin/" >> /etc/profile
[root@csq php-8.0.0]# source /etc/profile
# 查看安装版本
[root@csq php-8.0.0]# php --version
PHP 8.0.0 (cli) (built: May 7 2024 18:30:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies
配置软连接
shell
[root@csq php-8.0.0]# ln -s /usr/local/php-8.0.0/ /usr/local/php
生成各个配置文件
shell
# 生成php.ini配置文件
[root@csq php-8.0.0]# cp php.ini-production /usr/local/php/etc/php.ini
# 生成www.conf配置文件
[root@csq php-8.0.0]# cd /usr/local/php/etc/php-fpm.d/
[root@csq php-fpm.d]# cp www.conf.default www.conf
# 生成php-fpm的配置文件
[root@csq php-fpm.d]# cd ..
[root@csq etc]# cp php-fpm.conf.default php-fpm.conf
配置php文件
shell
[root@csq etc]# cd php-fpm.d/
[root@csq php-fpm.d]# vim www.conf
# 指定 PHP-FPM 进程的运行用户
user = nginx
# 指定 PHP-FPM 进程的运行用户组
group = nginx
[root@csq php-fpm.d]# vim ../php.ini
# 通过 POST 方法提交的整个请求的最大大小
post_max_size = 100M
# 指定了允许上传的单个文件的最大大小
upload_max_filesize = 100M
启动php-fpm
shell
# 创建启动目录
[root@csq ~]# mkdir /usr/local/php/daemon
# 生成php-fpm启动文件
[root@csq ~]# cp -rf php-8.0.0/sapi/fpm/init.d.php-fpm /usr/local/php/daemon
# 修改启动文件权限
[root@csq ~]# chmod 740 /usr/local/php/daemon/init.d.php-fpm
# 配置systemd启动
[root@csq ~]# vim /etc/systemd/system/php-fpm.service
[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
[root@csq ~]# systemctl enable php-fpm.service --now
[root@csq ~]# netstat -tlnp |grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 28324/php-fpm: mast
PHP8.0yum安装
shell
yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
# 禁用以 "remi-php" 开头的 Yum 软件仓库
[root@csq ~]# yum-config-manager --disable 'remi-php*'
# 启用名为 "remi-php80" 的 Yum 软件仓库
[root@csq ~]# yum-config-manager --enable remi-php80
# 安装php8
[root@csq ~]# yum install -y php
[root@csq ~]# yum install -y php80-php-cli php80-php-common php80-php-devel php80-php-embedded php80-php-fpm php80-php-gd php80-php-mbstring php80-php-mysqlnd php80-php-pdo php80-php-opcache php80-php-xml php80-php-soap
[root@csq ~]# php -v
PHP 8.0.30 (cli) (built: Apr 10 2024 07:34:10) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.30, Copyright (c) Zend Technologies
[root@csq ~]# systemctl enable php80-php-fpm.service --now
[root@csq ~]# systemctl status php80-php-fpm.service
● php80-php-fpm.service - The PHP FastCGI Process Manager
Loaded: loaded (/usr/lib/systemd/system/php80-php-fpm.service; disabled; vendor preset: disabled)
Active: active (running) since Tue 2024-05-07 19:14:54 CST; 21s ago
Main PID: 30420 (php-fpm)
[root@csq ~]# netstat -tlnp |grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 31405/php-fpm: mast