在 Debian 上搭建 PHP Web 开发环境的推荐路径
sudo apt update;按需选择 PHP 版本(如 PHP 7.4/8.2),可用 apt-cache policy php 查看可用版本。php-cli php-fpm php-mysql php-curl php-gd php-mbstring php-xml php-zip php-bcmath php-json,满足大多数框架与数据库需求。方案一 LAMP 快速搭建(Apache 模块方式)
sudo apt install apache2 libapache2-mod-php php php-mysqlsudo a2enmod php<version> 后 sudo systemctl restart apache2<?php phpinfo(); ?>,访问 http://localhost/info.php 应看到 PHP 信息页。方案二 LNMP 快速搭建(Nginx + PHP-FPM)
sudo apt install nginx mysql-server php<version>-fpm php<version>-mysqlroot /var/www/html; index index.php index.html;location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php<version>-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/ && sudo nginx -t && sudo systemctl restart nginx开发与调试工具
sudo apt install composer,用于安装 Laravel/Symfony 等框架与库。sudo apt install php-xdebug,在 php.ini 中启用后可与 IDE 联动断点调试。部署与框架集成要点
composer create-project --prefer-dist laravel/laravel your-project)root /path/to/your-project/public;try_files $uri $uri/ /index.php?$query_string;location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php<version>-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }sudo systemctl restart php<version>-fpm nginx