简短回答:支持,但 Debian 上的 Nginx 本身不能直接运行 PHP,需要配合 PHP-FPM 来实现对 PHP 的支持。
sudo apt update
sudo apt install nginx php-fpm
Debian 11/12 通常安装的是:
php-fpm(PHP 8.x)/run/php/php-fpm.sock编辑站点配置(如 /etc/nginx/sites-available/default):
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php-fpm.sock;
}
}
创建测试文件:
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
访问:
http://服务器IP/info.php
| Debian 版本 | 默认 PHP |
|---|---|
| Debian 11 | PHP 7.4 |
| Debian 12 | PHP 8.2 |
| 第三方源(surury) | PHP 8.3 / 8.4 |
✅ Nginx + PHP-FPM 是最推荐方案
❌ 不要使用 php-cgi 手动方式(已过时)
✅ WordPress / Laravel / ThinkPHP 都支持
如果你愿意,我可以:
你现在是 新装系统还是已有 Nginx?