下面给你一个**在 Debian(以 Debian 11/12 为例)上配置 LAMP(Linux + Apache + MySQL/MariaDB + PHP)**的完整、常用且稳定的方案,适合新手和服务器部署。
sudo apt update
sudo apt upgrade -y
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
浏览器访问:
http://服务器IP
看到 Apache Debian Default Page 即成功。
Debian 官方源默认使用 MariaDB。
sudo apt install mariadb-server -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
常见选项:
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip -y
如果你需要 PHP 8.x,Debian 12 默认已经是 PHP 8.2
sudo systemctl restart apache2
echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php
http://服务器IP/info.php
看到 PHP 信息页面即成功 ✅
测试完成后建议删除:
sudo rm /var/www/html/info.php
sudo mkdir -p /var/www/example.com/public_html
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 755 /var/www
sudo nano /etc/apache2/sites-available/example.com.conf
内容示例:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
<Directory /var/www/example.com/public_html>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite example.com.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
sudo ufw allow 80
sudo ufw allow 443
sudo ufw reload
sudo apache2ctl configtest
sudo apt install libapache2-mod-php
sudo systemctl restart apache2
sudo mysql -u root -p
✅ Debian
✅ Apache(Web 服务)
✅ MariaDB(数据库)
✅ PHP(动态页面)
如果你需要:
可以直接告诉我你的使用场景,我可以给你更针对性的配置方案。