路径A 手动搭建 LNMP(以 CentOS 7 为例,稳定、可控)
- 安装 Nginx
- 创建源:/etc/yum.repos.d/nginx.repo,内容:
[nginx]
name=nginx repo
baseurl=https://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1
- 安装与启动:
yum install -y nginx
systemctl start nginx && systemctl enable nginx
- 安装 MariaDB
yum install -y mariadb-server mariadb
systemctl start mariadb && systemctl enable mariadb
mysql_secure_installation(按向导设置 root 密码与加固项)
- 安装 PHP 与 PHP-FPM
yum install -y php php-fpm php-mysqlnd
systemctl start php-fpm && systemctl enable php-fpm
- 配置 Nginx 与 PHP 联动(示例)
- 编辑:/etc/nginx/conf.d/default.conf,关键片段:
server {
listen 80;
root /usr/share/nginx/html;
server_name localhost;
index index.php index.html;
location / { try_files $uri $uri/ =404; }
error_page 500 502 503 504 /50x.html;
location = /50x.html { root /usr/share/nginx/html; }
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
- 检查并重载:nginx -t && systemctl reload nginx
- 环境自检
echo “” > /usr/share/nginx/html/info.php
浏览器访问:http://服务器IP/info.php 应看到 PHP 信息页。