要确认 LNMP(Linux + Nginx + MySQL/MariaDB + PHP)是否安装成功,可以按下面步骤逐项测试,从系统服务到实际页面访问,逐步验证。
systemctl status nginx
✅ 正常状态应为:
Active: active (running)
测试 Nginx 是否能响应:
curl http://127.0.0.1
或浏览器访问服务器 IP,看到 Nginx 欢迎页即成功。
systemctl status mysqld
# 或
systemctl status mariadb
登录数据库测试:
mysql -u root -p
✅ 能成功进入 MySQL 命令行说明数据库正常。
查看 PHP 版本:
php -v
检查 PHP-FPM 是否运行:
systemctl status php-fpm
# 或
systemctl status php7.4-fpm
vim /usr/share/nginx/html/info.php
内容:
<?php
phpinfo();
编辑 Nginx 站点配置(示例):
vim /etc/nginx/conf.d/default.conf
确保包含以下内容:
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.php index.html;
location ~ \.php$ {
fastcgi_pass unix:/run/php-fpm/www.sock;
# 或 127.0.0.1:9000
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
重载 Nginx:
nginx -t
systemctl reload nginx
浏览器访问:
http://服务器IP/info.php
✅ 看到 PHP Info 页面说明 LNMP 成功。
创建测试文件:
vim /usr/share/nginx/html/dbtest.php
内容(MySQL 示例):
<?php
$conn = new mysqli("localhost", "root", "你的密码");
if ($conn->connect_error) {
die("数据库连接失败: " . $conn->connect_error);
}
echo "✅ MySQL 连接成功";
?>
访问:
http://服务器IP/dbtest.php
✅ 显示“MySQL 连接成功”说明 PHP + MySQL 正常。
fastcgi_pass 路径错误root 路径错误| 项目 | 验证方式 |
|---|---|
| Linux | uname -a |
| Nginx | curl localhost |
| MySQL | mysql -u root -p |
| PHP | php -v |
| PHP + Nginx | info.php |
| PHP + MySQL | dbtest.php |
如果你愿意,可以告诉我:
我可以帮你 精确定位问题。