AlmaLinux 10 部署LNMP环境

AlmaLinux 10 部署LNMP环境

1 . 系统前置准备

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

2 . 安装 Nginx

dnf install nginx -y
systemctl enable nginx --now
systemctl status nginx

3 . 安装 MariaDB

dnf install mariadb mariadb-server -y
systemctl enable mariadb --now
systemctl status mariadb

4 . 安装 PHP及相关扩展

dnf install php php-fpm php-opcache php-gd php-curl php-mysqlnd php-pdo php-xml php-json -y
systemctl enable php-fpm --now
systemctl status php-fpm

5 . 运行 MariaDB 初始化脚本(手动)

mysql_secure_installation

6 . 配置 Nginx

# 增加配置文件
cat >/etc/nginx/conf.d/default.conf <<EOF
server {
    listen       80;
    server_name  localhost;
    root         /usr/share/nginx/html;

    location / {
        index  index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include       fastcgi_params;
        fastcgi_pass  php-fpm;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}
EOF

nginx -s reload

# 创建 PHP 测试文件
cat >/usr/share/nginx/html/info.php <<EOF
<?php phpinfo(); ?>
EOF

7 . 验证访问

curl -I http://$(hostname -I | awk '{print $1}')/info.php

或者浏览器中访问:http://<服务器IP地址>/info.php

posted @ 2025-03-30 12:02  wanghongwei-dev  阅读(176)  评论(0)    收藏  举报