安装依赖:
dnf update && dnf install -y gcc gcc-c++ make perl zlib-devel wget tar unzip
Red Hat 9系安装pcre-devel
sudo dnf install pcre-devel
Red Hat 10系安装pcre2-devel
sudo dnf install pcre2-devel
校准时间:
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && date -R
创建 Nginx 专用的系统用户与组,执行 id nginx 输出中包含 uid= 与 gid= 记录。
groupadd nginx && useradd -M -g nginx -s /sbin/nologin nginx && id nginx
下载/安装/解压 openssl
wget -nc --no-check-certificate https://github.com/openssl/openssl/releases/download/openssl-4.1.0/openssl-4.1.0.tar.gz && tar -zxvf openssl-4.1.0.tar.gz
下载/解压 nginx:
wget -nc --no-check-certificate https://nginx.org/download/nginx-1.30.6.tar.gz && tar -zxvf nginx-1.30.6.tar.gz
删除文件包:
rm -rf nginx-1.30.6.tar.gz && rm -rf openssl-4.1.0.tar.gz && cd nginx-1.30.6
执行配置脚本:
./configure \
--user=nginx \
--group=nginx \
--prefix=/usr/local/nginx \
--conf-path=/etc/nginx/nginx.conf \
--pid-path=/var/run/nginx.pid \
--with-threads \
--with-file-aio \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_v3_module \
--with-http_realip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-stream_ssl_preread_module \
--with-compat \
--with-openssl-opt="no-tests" \
--with-cc-opt='-march=native -O3' \
--with-openssl=../openssl-4.1.0
编译/安装 nginx:
make -j$(nproc) && make install
配置nginx服务:
cat >/usr/lib/systemd/system/nginx.service << "EOF"
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target
[Service]
Type=forking
PIDFile=/var/run/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
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
创建日志和配置文件目录所有权
cd && mkdir -p /etc/nginx/conf.d /etc/nginx/ssl && touch /usr/local/nginx/logs/access.log /usr/local/nginx/logs/error.log && chown -R nginx:nginx /usr/local/nginx/logs && chmod 750 /usr/local/nginx/logs && chmod 640 /usr/local/nginx/logs/*.log
安装wordpress
cd /usr/local/nginx/html && wget https://cn.wordpress.org/latest-zh_CN.zip && unzip latest-zh_CN.zip && mv wordpress/* /usr/local/nginx/html && rm -rf latest-zh_CN.zip wordpress && cd
添加权限和删除编译文件夹
rm -rf nginx-1.30.6 openssl-4.1.0 && chown -R nginx:nginx /usr/local/nginx/html
目录权限设为 755,文件权限设为 644
find /usr/local/nginx/html -type d -exec chmod 755 {} \;
find /usr/local/nginx/html -type f -exec chmod 644 {} \;
修改nginx.conf 中的两行配置
sed -i -e 's/#user\s\+nobody;/user nginx;/' -e 's/worker_processes\s\+1;/worker_processes auto;/' /etc/nginx/nginx.conf
添加default.conf
sed -i '/default_type\s\+application\/octet-stream;/a \ include conf.d\/default.conf;' /etc/nginx/nginx.conf
添加dhparam
curl https://ssl-config.mozilla.org/ffdhe2048.txt > /etc/nginx/ssl/dhparam
申请证书

安装 php:
搜索可下载的PHP模块。
dnf module list php
启用PHP 8.4模块。
dnf module enable php:8.4
安装PHP 及扩展
dnf install php php-fpm php-mysqlnd php-gd php-mbstring php-xml php-curl php-opcache php-cli -y
安装完成后检查版本
php --version
搜索可下载的mariadb模块
dnf module list mariadb
启用mariadb 11.8模块。
dnf module enable mariadb:11.8
安装 MariaDB
默认情况下,Rocky9 基础存储库中提供了 MariaDB。现在我们运行以下命令将 MariaDB 安装到您的系统
dnf install mariadb mariadb-server
安装完成后检查版本:
mariadb --version
修改/etc/php-fpm.d/www.conf
sed -i 's/^user = apache/user = nginx/' /etc/php-fpm.d/www.conf
sed -i 's/^group = apache/group = nginx/' /etc/php-fpm.d/www.conf
sed -i 's/;listen.owner = nobody/listen.owner = nginx/' /etc/php-fpm.d/www.conf
sed -i 's/;listen.group = nobody/listen.group = nginx/' /etc/php-fpm.d/www.conf
sed -i 's/;listen.mode = 0660/listen.mode = 0660/' /etc/php-fpm.d/www.conf
配置 SELinux 策略 ,允许 PHP-FPM 读写网站目录并建立网络连接以下载插件包:
chcon -R -t httpd_sys_rw_content_t /usr/local/nginx/html
允许 Web 服务发起外部网络连接
setsebool -P httpd_can_network_connect 1
安装完成后,现在启用 PHP MariaDB(系统启动时自动启动),启动 MariaDB,并使用以下命令验证状态:
开启php:
systemctl start php-fpm
开启状态:
systemctl status php-fpm
开机自动启动:
systemctl enable php-fpm
重新启动:
systemctl restart php-fpm
开启mariadb:
systemctl start mariadb
开启状态:
systemctl status mariadb
开机自动启动:
systemctl enable mariadb
重新启动:
systemctl restart mariadb
mysql或MariaDB安全加固:
会设置密码,界面1直接回车,剩的都选Y:
mysql_secure_installation
root登录:
mysql -u root -p
查看当前的数据库:
show databases;
创建数据库非root用户名密码:
create database wordpress; create user name@localhost identified by 'password';
授予权限:
grant all privileges on wordpress.* to name@localhost; flush privileges;
修改登录密码无效
ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("password");
退出:
exit
开启BBR:
echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf && echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf && sysctl -p && lsmod | grep bbr
加载单元:
systemctl daemon-reload
开启nginx:
systemctl start nginx
开启状态:
systemctl status nginx
开机自动启动:
systemctl enable nginx
重新启动:
systemctl restart nginx
停止nginx:
service nginx stop
dnf –setopt install_weak_deps=TRUE –skip-broken install \
bash-completion bzip2 file git-core make ncurses-devel patch \
rsync tar unzip wget which diffutils python3 perl perl-base \
perl-devel perl-Data-Dumper perl-File-Compare perl-File-Copy perl-FindBin \
perl-IPC-Cmd perl-JSON-PP perl-lib perl-Thread-Queue perl-Time-Piece \
gcc gcc-c++ zlib zlib-devel pcre pcre-devel \
openssl openssl-devel libxslt libxslt-devel gd gd-devel vim nano