LAMP Stack Local Development Guide

Set up LAMP (Linux + Apache + MySQL + PHP) on Linux and run PHP websites via http://localhost.


LAMP is the classic web development stack: Linux + Apache + MySQL (or MariaDB) + PHP. Most PHP sites run in production and local Linux environments on this stack.

Default localhost Access

PurposeAddress
Site Root Directoryhttp://localhost
phpMyAdmin (if installed)http://localhost/phpmyadmin

Apache listens on port 80 by default.

Quick Installation (Debian/Ubuntu)

sudo apt update
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
sudo systemctl start apache2
sudo systemctl start mysql

Opening http://localhost in a browser should display the Apache default page.

Website Root Directory

Virtual Hosts (Optional)

Add a VirtualHost in /etc/apache2/sites-available/, pointing DocumentRoot to your project path, then run a2ensite followed by systemctl reload apache2.

Relationship with WAMP/XAMPP

LAMP is a conceptual combination on Linux, not a single installation package. The Windows equivalent is WAMP, while cross-platform integrated packages include XAMPP and MAMP.

Common Issues

403 Forbidden
Check directory permissions: the www-data user must have read access.

PHP Not Parsing
Ensure libapache2-mod-php is installed and restart Apache.

MySQL Connection Failed
Run sudo mysql_secure_installation to create a database user and grant permissions.

Summary

LAMP is the standard solution for local PHP development on Linux. After placing files in /var/www/html, access them via http://localhost.

访客计数:------ Best viewed in Netscape Navigator · 800×600 © LocalHost Run