技术交流QQ群:①185473046   ②190706903   ③203744115   网站地图
登录

下次自动登录
现在的位置: 首页LNMP>正文
Rocky Linux 10.x编译安装nginx-1.28.x+mysql-8.4.x+php-8.4.x
2025年09月05日 LNMP 暂无评论 ⁄ 被围观 44次+

前置知识:

Rocky Linux 10.x系统安装配置图解教程

https://www.osyunwei.com/archives/15874.html

准备篇

1、防火墙配置

Rocky Linux默认使用的是firewall作为防火墙

firewall-cmd --list-all #显示所有规则(含服务、端口、区域)

systemctl status firewalld #检查 firewalld 状态

#开放80 443 3306端口

firewall-cmd --permanent --add-port=80/tcp

firewall-cmd --permanent --add-port=443/tcp

firewall-cmd --permanent --add-port=3306/tcp

firewall-cmd --reload #重新加载防火墙配置

2、关闭SELINUX

vi /etc/selinux/config

#SELINUX=enforcing #注释掉

#SELINUXTYPE=targeted #注释掉

SELINUX=disabled #增加

:wq! #保存退出

setenforce 0 #使配置立即生效

getenforce #查看 SELinux 当前运行模式

3、系统约定

软件源代码包存放位置:/usr/local/src

源码包编译安装位置:/usr/local/软件名字

4、软件包下载

4.1 nginx

https://nginx.org/download/nginx-1.28.0.tar.gz

4.2 mysql

https://cdn.mysql.com//Downloads/MySQL-8.4/mysql-8.4.6-linux-glibc2.28-x86_64.tar.xz

4.3 php

https://www.php.net/distributions/php-8.4.12.tar.gz

4.4 cmake (mysql编译工具)

https://cmake.org/files/v4.1/cmake-4.1.0.tar.gz

4.5 pcre (支持nginx伪静态)

https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz/download

4.6 openssl (nginx扩展)

https://github.com/openssl/openssl/releases/download/openssl-3.5.2/openssl-3.5.2.tar.gz

4.7 zlib (nginx的gzip压缩需要)

https://www.zlib.net/zlib-1.3.1.tar.gz

4.8 yasm(php需要)

http://www.tortall.net/projects/yasm/releases/yasm-1.3.0.tar.gz

4.9 libgd(php需要)

https://github.com/libgd/libgd/releases/download/gd-2.3.3/libgd-2.3.3.tar.gz

4.10 libvpx(php需要)

https://github.com/webmproject/libvpx/archive/refs/tags/v1.15.2.tar.gz

4.11 tiff(php需要)

https://download.osgeo.org/libtiff/tiff-4.7.0.tar.gz

4.12 libpng(php需要)

https://downloads.sourceforge.net/libpng/libpng-1.6.50.tar.xz

4.13 freetype(php需要)

https://download.savannah.gnu.org/releases/freetype/freetype-2.13.3.tar.gz

4.14 freetype(php需要)

https://ijg.org/files/jpegsrc.v9f.tar.gz

4.15 libzip(php支持zip压缩)

https://libzip.org/download/libzip-1.11.4.tar.gz

4.16 curl(php需要)

https://curl.se/download/curl-8.15.0.tar.gz

4.17 tiff(php需要)

http://download.osgeo.org/libtiff/tiff-4.7.0.tar.gz

4.18 ngx_cache_purge (nginx需要)

https://codeload.github.com/FRiCKLE/ngx_cache_purge/tar.gz/refs/tags/2.3

4.19 oniguruma (php需要)

https://github.com/kkos/oniguruma/releases/download/v6.9.10/onig-6.9.10.tar.gz

5、安装编译工具及库文件

yum install apr* autoconf automake bison bzip2 bzip2* cpp curl curl-devel fontconfig fontconfig-devel freetype-devel git gcc gcc-c++ gd gd-devel gettext gettext-devel glibc kernel kernel-headers keyutils keyutils-libs-devel krb5-devel libcom_err-devel libpng libpng-devel libjpeg* libsepol-devel libselinux-devel libstdc++-devel libtool* libgomp libxml2 libxml2-devel libXpm* libxml* libXaw-devel libXmu-devel libtiff libtiff* libzip lame make openssl openssl-devel patch perl php-common php-gd policycoreutils telnet wget zlib-devel ncurses-devel gtk* ntpstat bison* sqlite-devel oniguruma postgresql-devel

安装篇

1、安装mysql

1.1 使用yum源安装mysql依赖包

yum install libaio-devel libaio ncurses-devel

1.2创建mysql运行用户和组

groupadd mysql

useradd -g mysql mysql -s /bin/false

1.3创建mysql安装目录以及数据库存放目录并赋权

mkdir -p /data/server/mysql #mysql安装目录

mkdir -p /data/server/mysql/data #mysql数据库存放目录

chown -R mysql:mysql /data/server/mysql #赋权

chown -R mysql:mysql /data/server/mysql/data #赋权

1.4安装mysql

#解压二进制版本mysql安装包到安装目录

cd /usr/local/src/

tar -xvf mysql-8.4.6-linux-glibc2.28-x86_64.tar.xz -C /data/server/mysql --strip-components 1

1.5设置my.cnf配置文件

vi /data/server/mysql/my.cnf #编辑添加

[client]

port = 3306

socket = /data/server/mysql/data/mysql.sock

[mysqld]

# 基础路径设置

user = mysql

port = 3306

basedir = /data/server/mysql

datadir = /data/server/mysql/data

socket = /data/server/mysql/data/mysql.sock

pid-file = /data/server/mysql/data/mysql.pid

# 字符集设置

character-set-server = utf8mb4

collation-server = utf8mb4_unicode_ci

# 日志相关

log-error = /data/server/mysql/data/error.log

server-id = 1

# 默认引擎和连接数

default-storage-engine = InnoDB

max_connections = 1000

# 性能相关(可根据内存调整)

innodb_buffer_pool_size = 1G

innodb_log_file_size = 256M

key_buffer_size = 32M

# 其他推荐配置

tmpdir = /tmp

explicit_defaults_for_timestamp = true

sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

[mysqld_safe]

log-error = /data/server/mysql/data/error.log

:wq! #保存退出

1.6添加mysql系统环境变量

vi /etc/profile #把mysql服务加入系统环境变量:在最后添加下面这一行

#set mysql environment

export PATH=$PATH:/data/server/mysql/bin

:wq! #保存退出

source /etc/profile #使配置立即生效

1.7初始化mysql数据库

/data/server/mysql/bin/mysqld --defaults-file=/data/server/mysql/my.cnf --user=mysql --initialize-insecure --basedir=/data/server/mysql --datadir=/data/server/mysql/data --socket=/data/server/mysql/data/mysql.sock --pid-file=/data/server/mysql/data/mysql.pid

1.8启动mysql数据库

/data/server/mysql/bin/mysqld_safe --defaults-file=/data/server/mysql/my.cnf --user=mysql --port=3306 --basedir=/data/server/mysql --datadir=/data/server/mysql/data --socket=/data/server/mysql/data/mysql.sock --pid-file=/data/server/mysql/data/mysql.pid &

1.9添加软连接

ln -s /data/server/mysql/data/mysql.sock /tmp/mysql.sock

1.10设置mysql管理员root密码,根据提示设置密码

/data/server/mysql/bin/mysql_secure_installation --socket=/data/server/mysql/data/mysql.sock

输入y使用密码验证插件

选择密码规则(一般选择1 = MEDIUM),输入1

LOW Length >= 8 #长度大于等于8

MEDIUM Length >= 8, numeric, mixed case, and special characters #长度大于等于8,数字、大小写字母、特殊符号

STRONG Length >= 8, numeric, mixed case, special characters and dictionary file #长度大于等于8,数字、大小写字母、特殊符号和字典文件(慎选!)

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1

设置新密码:12345678Abc++

y系统询问你是否确认使用这个强密码

y删除匿名用户

y禁止root远程登录

y删除测试数据库

y重新加载权限表

1.11关闭mysql数据库

/data/server/mysql/bin/mysqladmin -uroot -S /data/server/mysql/data/mysql.sock shutdown -p

#根据提示输入上面设置的密码即可关闭数据库

1.12设置mysql启动脚本

cp /data/server/mysql/support-files/mysql.server /data/server/mysql/mysql.sh

vi /data/server/mysql/mysql.sh #编辑修改

basedir=/data/server/mysql #mysql程序安装路径

datadir=/data/server/mysql/data #mysql数据库存放目录

conf=/data/server/mysql/my.cnf #mysql配置文件my.cnf路径

:wq! #保存退出

#添加执行权限

chmod +x /data/server/mysql/mysql.sh

#添加开机启动

vi /etc/rc.d/rc.local

/bin/sh /data/server/mysql/mysql.sh start

:wq! #保存退出

#默认/etc/rc.local没有执行权限,需要手动添加执行权限

chmod +x /etc/rc.d/rc.local

sh /data/server/mysql/mysql.sh start #启动mysql

1.13使用systemd服务实现mysql开机启动

vi /etc/systemd/system/mysqld.service

[Unit]

Description=MySQL Server

Documentation=man:mysqld(8)

Documentation=https://dev.mysql.com/doc/

After=network.target

After=syslog.target

[Service]

Type=simple

User=mysql

Group=mysql

ExecStart=/data/server/mysql/bin/mysqld --defaults-file=/data/server/mysql/my.cnf

ExecStop=/bin/kill -SIGTERM $MAINPID

WorkingDirectory=/data/server/mysql

PIDFile=/data/server/mysql/data/mysql.pid

LimitNOFILE=5000

TimeoutSec=300

Restart=on-failure

RestartSec=10

PrivateTmp=true

ProtectHome=true

NoNewPrivileges=true

[Install]

WantedBy=multi-user.target

:wq! #保存退出

systemctl daemon-reload

systemctl restart mysqld

systemctl status mysqld

注意:1.12和1.13任意其一就可以

1.14创建mysql数据库和用户

数据库名:dbtest

数据库用户名:usertest

数据库密码:12345678Abc++

#进入mysql控制台

/data/server/mysql/bin/mysql -uroot -p -S /data/server/mysql/data/mysql.sock

或者

mysql -u root -p

输入密码12345678Abc++

#创建数据库dbtest

Create DATABASE IF NOT EXISTS dbtest default charset utf8mb4 COLLATE utf8mb4_general_ci;

#创建用户usertest

CREATE USER 'usertest'@'192.168.21.%' IDENTIFIED BY '12345678Abc++';

#授权用户usertest访问dbtest数据库

GRANT ALL PRIVILEGES ON dbtest.* TO 'usertest'@'192.168.21.%';

flush privileges; #刷新系统授权表

#创建mysql管理员

CREATE USER 'admin'@'127.0.0.1' IDENTIFIED BY '12345678Abc++'; #创建mysql数据库管理员admin

CREATE USER 'admin'@'localhost' IDENTIFIED BY '12345678Abc++'; #创建mysql数据库管理员admin

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'127.0.0.1'; #授权访问数据库

GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost'; #授权访问数据库

flush privileges; #刷新系统授权表

#修改root密码

SELECT User, Host FROM mysql.user WHERE User = 'root';

CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY '12345678Abc++';

ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678Abc++';

ALTER USER 'root'@'127.0.0.1' IDENTIFIED BY '12345678Abc++';

flush privileges; #刷新系统授权表

exit; #退出控制台

1.15导出数据库

#导出数据库dbtest到/tmp/dbtest.sql

/data/server/mysql/bin/mysqldump -u root -p --default-character-set=utf8mb4 --opt -Q -R --skip-lock-tables dbtest > /tmp/dbtest.sql

备注:在导出之前可以先进入MySQL控制台执行下面命令

flush tables with read lock; #数据库只读锁定命令,防止导出数据库的时候有数据写入

unlock tables; #解除锁定

1.16导入数据库

进入mysql控制台

/data/server/mysql/bin/mysql -uroot -p -S /data/server/mysql/data/mysql.sock

use dbtest #进入数据库

source /tmp/dbtest.sql #导入备份文件到数据库

exit; #退出控制台

2、安装nginx

2.1安装pcre

cd /usr/local/src

mkdir /usr/local/pcre

tar zxvf pcre-8.45.tar.gz

cd pcre-8.45

./configure --prefix=/usr/local/pcre

make

make install

2.2安装openssl

cd /usr/local/src

mkdir /usr/local/openssl

tar zxvf openssl-3.5.2.tar.gz

cd openssl-3.5.2

./config -fPIC shared zlib --prefix=/usr/local/openssl

make

make install

2.3安装zlib

cd /usr/local/src

mkdir /usr/local/zlib

tar zxvf zlib-1.3.1.tar.gz

cd zlib-1.3.1

./configure --prefix=/usr/local/zlib

make

make install

2.4安装nginx

nginx默认运行账号和组是Linux系统的内置账号和组nobody

创建nginx运行账号

groupadd www

useradd -g www www -s /bin/false

cd /usr/local/src

tar zxvf ngx_cache_purge-2.3.tar.gz

tar zxvf nginx-1.28.0.tar.gz

cd nginx-1.28.0

./configure --prefix=/usr/local/nginx --user=www --group=www --without-http_memcached_module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_realip_module --with-stream --with-http_flv_module --with-http_mp4_module --with-http_sub_module --http-client-body-temp-path=/usr/local/nginx/client --http-proxy-temp-path=/usr/local/nginx/proxy --http-fastcgi-temp-path=/usr/local/nginx/fcgi --http-uwsgi-temp-path=/usr/local/nginx/uwsgi --with-openssl=/usr/local/src/openssl-3.5.2 --with-zlib=/usr/local/src/zlib-1.3.1 --with-pcre=/usr/local/src/pcre-8.45 --add-module=../ngx_cache_purge-2.3

make

make install

注意:这3个路径指向的是源码包解压的路径,不是安装的路径,否则会报错。

--with-openssl=/usr/local/src/openssl-3.5.2

--with-zlib=/usr/local/src/zlib-1.3.1

--with-pcre=/usr/local/src/pcre-8.45

查看Nginx的configure支持的所有参数

./configure --help

#启动Nginx

/usr/local/nginx/sbin/nginx

#查看nginx版本和安装模块信息

/usr/local/nginx/sbin/nginx -V

2.5配置nginx启动脚本

vi /usr/local/nginx/nginx.sh

#!/bin/bash

NGINX_PATH="/usr/local/nginx/sbin/nginx"

PID_FILE="/usr/local/nginx/logs/nginx.pid"

function start_nginx() {

if [ -f $PID_FILE ]; then

echo "Nginx is already running."

else

echo "Starting Nginx..."

$NGINX_PATH

echo "Nginx started."

fi

}

function stop_nginx() {

if [ -f $PID_FILE ]; then

echo "Stopping Nginx..."

$NGINX_PATH -s stop

echo "Nginx stopped."

else

echo "Nginx is not running."

fi

}

function restart_nginx() {

if [ -f $PID_FILE ]; then

echo "Restarting Nginx..."

$NGINX_PATH -s stop

sleep 1

$NGINX_PATH

echo "Nginx restarted."

else

echo "Nginx is not running. Starting it now..."

$NGINX_PATH

echo "Nginx started."

fi

}

function reload_nginx() {

if [ -f $PID_FILE ]; then

echo "Reloading Nginx configuration..."

$NGINX_PATH -s reload

echo "Nginx configuration reloaded."

else

echo "Nginx is not running. Cannot reload the configuration."

fi

}

function status_nginx() {

if [ -f $PID_FILE ]; then

echo "Nginx is running with PID $(cat $PID_FILE)."

else

echo "Nginx is stopped."

fi

}

case "$1" in

start)

start_nginx

;;

stop)

stop_nginx

;;

restart)

restart_nginx

;;

reload)

reload_nginx

;;

status)

status_nginx

;;

*)

echo "Usage: $0 {start|stop|restart|reload|status}"

exit 1

;;

esac

:wq! #保存退出

#添加执行权限

chmod +x /usr/local/nginx/nginx.sh

#添加开机启动

vi /etc/rc.d/rc.local

/bin/sh /usr/local/nginx/nginx.sh start

:wq! #保存退出

#默认/etc/rc.local没有执行权限,需要手动添加执行权限

chmod +x /etc/rc.d/rc.local

/bin/sh /usr/local/nginx/nginx.sh restart

2.6使用systemd服务实现nginx开机启动

vi /lib/systemd/system/nginx.service #添加以下代码

[Unit]

Description=The NGINX HTTP and reverse proxy server

After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]

Type=forking

PIDFile=/usr/local/nginx/logs/nginx.pid

ExecStartPre=/usr/local/nginx/sbin/nginx -t

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/bin/kill -s QUIT $MAINPID

ExecStartPost=/bin/sleep 0.1

PrivateTmp=true

[Install]

WantedBy=multi-user.target

:wq! #保存退出

/usr/local/nginx/sbin/nginx -s stop #停止

systemctl enable nginx.service #设置开机自启动

systemctl start nginx.service #启动

systemctl stop nginx.service #关闭

systemctl restart nginx.service #重启

systemctl reload nginx.service #重新加载配置文件

注意:2.5和2.6任意其一就可以

3、安装php

3.1安装yasm

cd /usr/local/src

tar zxvf yasm-1.3.0.tar.gz

cd yasm-1.3.0

./configure

make

make install

3.2安装libvpx

cd /usr/local/src

tar zxvf libvpx-1.15.2.tar.gz

cd libvpx-1.15.2

./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9

make

make install

3.3安装libpng

cd /usr/local/src

tar xvJf libpng-1.6.50.tar.xz

cd libpng-1.6.50

./configure --prefix=/usr/local/libpng --enable-shared

make

make install

3.4安装freetype

cd /usr/local/src

tar zxvf freetype-2.13.3.tar.gz

cd freetype-2.13.3

./configure --prefix=/usr/local/freetype --enable-shared

make

make install

3.5安装jpeg

cd /usr/local/src

tar zxvf jpegsrc.v9f.tar.gz

cd jpeg-9f

./configure --prefix=/usr/local/jpeg --enable-shared

make

make install

3.6安装tiff

cd /usr/local/src

tar zxvf tiff-4.7.0.tar.gz

cd tiff-4.7.0

./configure --prefix=/usr/local/tiff --enable-shared

make

make install

3.7安装GD库

cd /usr/local/src

tar zxvf libgd-2.3.3.tar.gz

cd libgd-2.3.3

./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/lib64 --with-tiff=/usr/local/tiff

make

make install

#添加动态库路径

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

echo '/usr/local/libgd/lib' | tee /etc/ld.so.conf.d/libgd.conf

ldconfig

ldconfig -p | grep libgd

# 检查库文件

ls /usr/local/libgd/lib/libgd.*

# 检查头文件

ls /usr/local/libgd/include/gd.h

3.8安装cmake

cd /usr/local/src

tar zxvf cmake-4.1.0.tar.gz

cd cmake-4.1.0

./configure

make

make install

3.9安装libzip

cd /usr/local/src

tar -zxvf libzip-1.11.4.tar.gz

cd libzip-1.11.4

mkdir build

cd build

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/libzip -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=ON ..

make

make install

#添加动态库路径

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

pkg-config --modversion libzip

3.10安装curl

cd /usr/local/src

tar zxvf curl-8.15.0.tar.gz

cd curl-8.15.0

./configure --prefix=/usr/local/curl --with-ssl=/usr/local/openssl --without-nss --enable-shared --enable-static --disable-ldap --disable-ldaps

make

make install

#添加动态库路径

echo '/usr/local/curl/lib' | tee /etc/ld.so.conf.d/curl.conf

ldconfig

ldconfig -p | grep libcurl

/usr/local/curl/bin/curl --version

3.11安装oniguruma

cd /usr/local/src

tar -zxf onig-6.9.10.tar.gz

cd onig-6.9.10

./configure --prefix=/usr/local/oniguruma --enable-shared --enable-static

make

make install

#添加动态库路径

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

export LD_LIBRARY_PATH=/usr/local/oniguruma/lib:$LD_LIBRARY_PATH

pkg-config --modversion oniguruma

ldconfig -p | grep libonig

3.12安装php

#添加所有自编译库路径

echo '/usr/local/libgd/lib' | tee /etc/ld.so.conf.d/gd.conf

echo '/usr/local/libzip/lib' | tee /etc/ld.so.conf.d/libzip.conf

echo '/usr/local/curl/lib' | tee /etc/ld.so.conf.d/curl.conf

echo '/usr/local/jpeg/lib' | tee /etc/ld.so.conf.d/jpeg.conf

echo '/usr/local/freetype/lib' | tee /etc/ld.so.conf.d/freetype.conf

echo '/usr/local/openssl/lib' | tee /etc/ld.so.conf.d/openssl.conf

echo '/usr/local/oniguruma/lib' | tee /etc/ld.so.conf.d/oniguruma.conf

#更新缓存

ldconfig

cd /usr/local/src

tar -zvxf php-8.4.12.tar.gz

cd php-8.4.12

./configure \

--prefix=/usr/local/php84 \

--with-config-file-path=/usr/local/php84/etc \

--with-config-file-scan-dir=/usr/local/php84/etc/php.d \

--with-mysqli=mysqlnd \

--with-pdo-mysql=mysqlnd \

--enable-gd \

--with-external-gd=/usr/local/libgd \

--with-jpeg=/usr/local/jpeg \

--with-freetype=/usr/local/freetype \

--with-xpm=/usr/lib64 \

--with-zlib \

--with-iconv \

--with-libxml \

--enable-xml \

--enable-bcmath \

--enable-shmop \

--enable-sysvsem \

--enable-opcache \

--enable-mbregex \

--enable-fpm \

--enable-mbstring \

--enable-ftp \

--with-openssl=/usr/local/openssl \

--enable-pcntl \

--enable-sockets \

--with-zip=/usr/local/libzip \

--enable-soap \

--without-pear \

--with-gettext \

--enable-session \

--with-curl=/usr/local/curl \

--enable-ctype \

--enable-mysqlnd \

--enable-pdo \

--with-pgsql \

--with-pdo-pgsql

make -j$(nproc) #编译

make install #安装

./configure --help #可以查看编译参数的写法

3.13 配置php

3.13.1 配置php.ini文件

cp /usr/local/src/php-8.4.12/php.ini-production /usr/local/php84/etc/php.ini #复制php配置文件到安装目录

rm -rf /etc/php.ini #删除系统自带配置文件

ln -s /usr/local/php84/etc/php.ini /etc/php.ini #添加软链接到 /etc目录

vi /usr/local/php84/etc/php.ini #编辑配置文件

找到:disable_functions =

修改为:disable_functions = passthru,exec,system,shell_exec,popen,proc_open,dl,show_source,highlight_file

#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。

找到:;date.timezone =

修改为:date.timezone = PRC #设置时区

找到:expose_php = On

修改为:expose_php = Off #禁止显示php版本的信息

找到:short_open_tag = Off

修改为:short_open_tag = ON #支持php短标签

找到opcache.enable=0

修改为opcache.enable=1 #php支持opcode缓存

找到:;opcache.enable_cli=1

修改为:opcache.enable_cli=0 #php支持opcode缓存

在最后一行添加:zend_extension=opcache.so #开启opcode缓存功能

; 启用 OPcache

opcache.enable=1

opcache.enable_cli=0

opcache.memory_consumption=256

opcache.interned_strings_buffer=16

opcache.max_accelerated_files=20000

opcache.validate_timestamps=1

opcache.revalidate_freq=60

opcache.fast_shutdown=1

; JIT 配置(PHP 8.0+)

opcache.jit_buffer_size=256M

opcache.jit=1254

:wq! #保存退出

3.13.2 配置php-fpm.conf文件

cp /usr/local/php84/etc/php-fpm.conf.default /usr/local/php84/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件

ln -s /usr/local/php84/etc/php-fpm.conf /etc/php-fpm.conf #添加软连接到 /etc目录

vi /usr/local/php84/etc/php-fpm.conf #编辑

pid = run/php-fpm.pid #取消前面的分号

include=/usr/local/php84/etc/php-fpm.d/*.conf

:wq! #保存退出

3.13.3 配置www.conf文件

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

vi /usr/local/php84/etc/php-fpm.d/www.conf #编辑

user = www #设置php-fpm运行账号为www

group = www #设置php-fpm运行组为www

listen = 127.0.0.1:9084 #php监听端口设置,默认是9000端口,可以修改为自定义的端口

:wq! #保存退出

3.13.4 配置php-fpm的systemd启动服务

mv /usr/local/php84/sbin/php-fpm /usr/local/php84/sbin/php84-fpm

vi /etc/systemd/system/php84-fpm.service

[Unit]

Description=PHP 8.4.12 FastCGI Process Manager

After=network.target

[Service]

Type=simple

PIDFile=/usr/local/php84/var/run/php-fpm.pid

ExecStart=/usr/local/php84/sbin/php84-fpm --nodaemonize --fpm-config /usr/local/php84/etc/php-fpm.conf

ExecReload=/bin/kill -USR2 $MAINPID

ExecStop=/bin/kill -QUIT $MAINPID

TimeoutStopSec=10

PrivateTmp=true

Restart=always

[Install]

WantedBy=multi-user.target

:wq! #保存退出

systemctl daemon-reexec

systemctl daemon-reload

systemctl start php84-fpm

systemctl status php84-fpm

systemctl enable php84-fpm

3.14 设置nginx支持php

vi /usr/local/nginx/conf/nginx.conf

#修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改

#首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php84/etc/php-fpm.d/www.conf中的user,group配置相同,否则php运行出错

user www www;

index index.html index.htm index.php; #添加index.php

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9084; #php监听端口,和www.conf文件里面的端口设置要一致

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

include fastcgi_params;

}

#取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径

#fastcgi_pass 127.0.0.1:9084; 可以使用端口号来区分php版本,如果只有1个版本,默认使用9000也可以

systemctl restart nginx.service #重启nginx

systemctl restart php84-fpm #重启php84-fpm

测试篇

cd /usr/local/nginx/html/ #进入nginx默认网站根目录

rm -rf /usr/local/nginx/html/* #删除默认测试页

vi index.php #新建index.php文件

<?php

phpinfo();

?>

:wq! #保存退出

chown www:www /usr/local/nginx/html/ -R #设置目录所有者

chmod 700 /usr/local/nginx/html/ -R #设置目录权限

在浏览器中打开服务器IP地址,会看到下面的界面

遇到问题:

至此,Rocky Linux 10.x编译安装nginx-1.28.x+mysql-8.4.x+php-8.4.x完成。

     

  系统运维技术交流QQ群:①185473046 系统运维技术交流□Ⅰ ②190706903 系统运维技术交流™Ⅱ ③203744115 系统运维技术交流™Ⅲ

给我留言

您必须 [ 登录 ] 才能发表留言!



Copyright© 2011-2025 系统运维 All rights reserved
版权声明:本站所有文章均为作者原创内容,如需转载,请注明出处及原文链接
陕ICP备11001040号-3