温馨提示×

Debian LNMP支持PHP吗

小樊
64
2026-07-02 04:23:09
栏目: 编程语言

是的,Debian 上的 LNMP 完全支持 PHP,而且这是非常常见、成熟的组合。

什么是 LNMP?

LNMP 通常指:

  • L:Linux(如 Debian)
  • N:Nginx
  • M:MySQL / MariaDB
  • P:PHP

在 Debian 上,这个组合是官方仓库直接支持的。


一、Debian 上 PHP 的支持情况

Debian 官方仓库中自带 PHP,例如:

  • Debian 11(Bullseye):PHP 7.4
  • Debian 12(Bookworm):PHP 8.2
  • Debian 13(Trixie,测试):PHP 8.2 / 8.3

你可以通过 apt 直接安装 PHP 及常用扩展。


二、在 Debian 上安装 LNMP(含 PHP)

1️⃣ 安装 Nginx

sudo apt update
sudo apt install nginx

2️⃣ 安装 PHP(FastCGI)

sudo apt install php-fpm

常见扩展(按需):

sudo apt install php-mysql php-curl php-gd php-mbstring php-xml php-zip

3️⃣ 安装数据库

sudo apt install mariadb-server

三、Nginx 配置支持 PHP

编辑站点配置(示例):

server {
    listen 80;
    server_name example.com;
    root /var/www/html;
    index index.php index.html;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php-fpm.sock;
    }
}

然后重启服务:

sudo systemctl restart nginx
sudo systemctl restart php-fpm

四、验证 PHP 是否工作

创建测试文件:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

浏览器访问:

http://服务器IP/info.php

五、常见注意点

✅ Debian + Nginx + PHP-FPM 是官方推荐方式
✅ PHP 以 php-fpm 运行,性能比 mod_php 更好
✅ 支持 PHP 7.x / 8.x
✅ 支持 Composer、Laravel、ThinkPHP、WordPress 等


六、如果你需要更新 PHP 版本

可以使用 第三方仓库(如 ondrej/php),但 Debian 官方仓库通常已足够稳定。


如果你愿意,可以告诉我:

  • 你的 Debian 版本
  • 是 服务器 / 本地 / 云服务器
  • 是否用于 生产环境

我可以给你一套更精确的 LNMP 安装方案。

0 踩