Rocky Linux 9 源码安装 PHP 8
hi,我是温新,一名 PHPer
卸载自带的 PHP
# 检查是否有自带的PHP
rpm -qa|grep php
# 卸载
dnf -y remove php
# 再次查看
rpm -qa|grep php
创建用户
groupadd www
useradd -g www www -M -s /sbin/nologin
源码安装 PHP 8.3.1
cd /usr/local/src
# 下载
wget https://www.php.net/distributions/php-8.3.1.tar.gz
tar -zxvf php-8.3.1.tar.gz
cd php-8.3.1
# 预编译
./configure --prefix=/usr/local/software/php-8.3.1 \
--with-config-file-path=/usr/local/software/php-8.3.1/etc \
--with-fpm-user=www \
--with-fpm-group=www \
--enable-mbstring \
--enable-ftp \
--enable-gd \
--enable-gd-jis-conv \
--enable-mysqlnd \
--enable-pdo \
--enable-sockets \
--enable-fpm \
--enable-xml \
--enable-soap \
--enable-pcntl \
--enable-cli \
--with-openssl \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-pear \
--with-zlib \
--with-iconv \
--with-curl \
--with-jpeg \
--enable-sockets
# 安装
make && make install
配置
cp php.ini-production /usr/local/software/php-8.3.1/etc/php.ini
cd /usr/local/software/php-8.3.1/etc/
cp ./php-fpm.conf.default ./php-fpm.conf
cp ./php-fpm.d/www.conf.default ./php-fpm.d/www.conf
编辑如下文件后并保存退出
vim ./php-fpm.conf
修改内容
# 删除分号
pid = run/php-fpm.pid
配置环境变量
vim /etc/profile
内容
export PATH=$PATH:/usr/local/software/php-8.3.1/bin
source /etc/profile
查看版本
php -v
PHP 8.3.1 (cli) (built: Dec 22 2023 16:05:05) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.1, Copyright (c) Zend Technologies
设置开机自启
vim /usr/lib/systemd/system/php-fpm-831.service
输入如下内容,保存并退出
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/software/php-8.3.1/sbin/php-fpm --nodaemonize --fpm-config /usr/local/software/php-8.3.1/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
加入开机自启
systemctl enable php-fpm-831.service
Nginx 解析 PHP
1)编辑nginx.conf
配置文件
cd /usr/local/software/nginx-1.25.3/conf/
cp nginx.conf nginx.conf.bak
vim nginx.conf
2)修改内容
location / {
root /www;
index index.php index.html index.htm;
}
location ~ \.php$ {
root /www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
3)创建目录
mkdir /www
chown www:www /www/
// 创建index.php
echo "<?php phpinfo(); " > /www/index.php
4)重启服务
systemctl restart php-fpm-831.service
systemctl restart nginx.service
5)浏览器访问效果
浏览器中输入 IP 就可以问啦:http://192.168.73.128/
请登录后再评论