How to Install LAMP on Ubuntu
Step 1: Update Your Package List
Step 2: Install Apache Web Server
Check if Apache is running:
Test in browser:
Visit http://localhost/
or http://your-server-ip/
You should see the Apache2 Ubuntu Default Page.
Step 3: Install MySQL (Database)
Secure the MySQL installation:
You’ll be asked to:
-
Set root password (if not set by default)
-
Remove anonymous users? →
Yes
-
Disallow root login remotely? →
Yes
-
Remove test database? →
Yes
-
Reload the privilege tables? →
Yes
Log in to test:
Then exit:
Step 4: Install PHP and Required Modules
You can install more PHP extensions if needed, like:
Check PHP version:
Step 5: Test PHP
Create a PHP file to test if it works:
Paste this:
Save and exit.
Visit in browser:http://localhost/info.php
You should see the PHP info page.
After testing, delete the file to avoid security risk:
Step 6: Enable Apache mod_rewrite
(Optional but common)
You're Done!
The LAMP stack is now fully installed on your Ubuntu system!
You can now:
-
Run PHP applications (like Laravel, WordPress)
-
Host MySQL databases
-
Use Apache as your web server