什么是 LAMP 服务器?组件、工作原理与安装指南
发布: (2025年12月26日 GMT+8 18:18)
2 min read
原文: Dev.to
Source: Dev.to
LAMP 组件
- Linux: 基础操作系统。
- Apache: 一个广泛使用的网页服务器,处理 HTTP 请求并提供网页内容。
- MySQL/MariaDB: 用于存储和管理数据的关系型数据库管理系统 (RDBMS)。
- PHP/Python/Perl: 用于服务器端脚本编写的编程语言。
LAMP 工作原理
Linux 为所有组件提供稳定的基础。Apache 接收传入的 HTTP 请求并提供网页。PHP(或其他脚本语言)处理动态内容。MySQL/MariaDB 存储并管理网站数据。
在 Linux 上安装 LAMP

在 Ubuntu/Debian 上
sudo apt install apache2 mysql-server php php-mysql
# Enable and start services
sudo systemctl enable apache2
sudo systemctl start apache2
sudo systemctl enable mysql
sudo systemctl start mysql
在 CentOS/Fedora 上
sudo apt install httpd mysql-server php php-mysql
# Enable and start services
sudo systemctl enable httpd
sudo systemctl start httpd
sudo systemctl enable mysql
sudo systemctl start mysql
验证安装
Apache
打开网页浏览器并访问 http://your-server-ip。你应该能看到 Apache 的默认页面。
PHP
在 /var/www/html/info.php 创建一个测试文件,内容如下:
然后在浏览器中访问 http://your-server-ip/info.php。