Setting Up a LAMP Stack on Ubuntu
The LAMP stack (Linux, Apache, MySQL, PHP) is the foundation of the web. Even in 2026, it remains the most popular way to host dynamic websites like WordPress, Joomla, and custom PHP applications.
Since you are running Ubuntu (Linux), you already have the "L". This guide covers installing the rest.
1. Install Apache Web Server
Apache is the software that actually "serves" your web pages to the browser.
- Install Apache:
sudo apt update sudo apt install apache2 -y - Verify it works:
Open your web browser on Windows and type:
http://localhost- You should see the "Apache2 Ubuntu Default Page".
WSL Note: If
localhostdoesn't work, ensure the service is running:sudo service apache2 start. In WSL, services don't always start automatically on boot.
2. Install MySQL Database
MySQL is where your application stores its data (like blog posts, user accounts, and comments).
-
Install MySQL:
sudo apt install mysql-server -y -
Secure the Installation: Run the included security script to set a root password and remove insecure defaults.
sudo mysql_secure_installation- VALIDATE PASSWORD PLUGIN? Press
N(unless you want strict password enforcement for a dev machine). - Remove anonymous users?
Y - Disallow root login remotely?
Y - Remove test database?
Y - Reload privilege tables now?
Y
- VALIDATE PASSWORD PLUGIN? Press
-
Test Access:
sudo mysqlType
exitto leave the MySQL prompt.
3. Install PHP
PHP is the scripting language that connects Apache to MySQL and generates dynamic HTML.
- Install PHP and dependencies:
sudo apt install php libapache2-mod-php php-mysql -y - Check Version:
php -v
4. Connecting the Parts (The "info.php" Test)
To confirm that Apache can pass .php files to the PHP processor, we create a test file.
- Create the file:
By default, Apache looks for files in
/var/www/html.sudo nano /var/www/html/info.php - Add the code:
Paste the following into the editor:
<?php phpinfo(); ?> - Save and Exit:
Ctrl+O,Enter,Ctrl+X. - Restart Apache:
sudo service apache2 restart - View the result:
Go to
http://localhost/info.phpin your browser. You should see a purple PHP information page detailing your configuration.
Security Warning: Once you confirm it works, delete this file! It exposes sensitive server information.
sudo rm /var/www/html/info.php
5. Managing Services in WSL
Unlike a standard server, WSL doesn't use systemd to keep services running in the background perfectly all the time.
- Start LAMP:
sudo service apache2 start && sudo service mysql start - Stop LAMP:
sudo service apache2 stop && sudo service mysql stop - Check Status:
sudo service apache2 status