Complete Guide: Install LAMP Stack on Oracle Cloud Always Free (Ubuntu 20.04)
Below is a complete, beginner-friendly, step-by-step guide to install the LAMP stack (Linux, Apache, MySQL, PHP) on Ubuntu 20.04 running on an Oracle Cloud Always Free instance.
This guide is written assuming:
-
✔ Oracle Cloud Always Free VM
-
✔ Ubuntu 20.04 LTS
-
✔ You connect via SSH (PuTTY / Terminal)
🧱 What is LAMP?
-
Linux → Ubuntu 20.04
-
Apache → Web server
-
MySQL → Database
-
PHP → Server-side scripting
STEP 0️⃣ Prerequisites (Oracle Cloud)
-
Create Oracle Cloud Always Free VM
Choose:-
Image: Ubuntu 20.04
-
Shape: VM.Standard.E2.1.Micro (Always Free)
-
Public IP: Enabled
-
SSH key: Downloaded
-
https://documentation.ubuntu.com/oracle/_images/1_latest_ubuntu_image.png
https://learncodeshare.net/wp-content/uploads/2019/12/getPublicIp.png
https://docs.oracle.com/en/learn/generate_ssh_keys/images/cloudshellopen.png
STEP 1️⃣ Connect to Your Instance (SSH)
Linux / Mac
ssh ubuntu@YOUR_PUBLIC_IP
Windows (PuTTY)
-
Host Name: YOUR_PUBLIC_IP
-
Port: 22
-
Auth → Select .ppk key
-
Login user: ubuntu
STEP 2️⃣ Update System (IMPORTANT)
sudo apt update sudo apt upgrade -y
👉 Always do this first to avoid package errors.
STEP 3️⃣ Install Apache Web Server
sudo apt install apache2 -y
Enable Apache on boot
sudo systemctl enable apache2
Start Apache
sudo systemctl start apache2
Check Apache status
sudo systemctl status apache2
STEP 4️⃣ Open Port 80 (HTTP) in Oracle Cloud
A. Oracle Cloud Security List / NSG
Allow:
-
Source: 0.0.0.0/0
-
Protocol: TCP
-
Port: 80
https://cleavr.io/images/oracle/oracle-port-5.png
https://docs.oracle.com/en/solutions/oci-security-checklist/img/vcn-config-png.png
B. Ubuntu Firewall (UFW)
sudo ufw allow OpenSSH sudo ufw allow 'Apache Full' sudo ufw allow 80 sudo ufw allow Apache sudo ufw reload sudo ufw enable sudo ufw status
Need to Reboot?
Not mandatory now, but recommended later.
You can continue installing LAMP without reboot.
(Optional reboot after LAMP install):
sudo reboot
Reconnect via SSH after 1–2 minutes.
Check again:
sudo ufw status
STEP 5️⃣ Test Apache
Open browser:
http://YOUR_PUBLIC_IP
✅ You should see Apache2 Ubuntu Default Page
STEP 6️⃣ Install MySQL Server
sudo apt install mysql-server -y
Start & Enable MySQL
sudo systemctl start mysql sudo systemctl enable mysql
Secure MySQL (VERY IMPORTANT)
sudo mysql_secure_installation
Recommended answers:
-
Validate password plugin → No
-
Root password → Set strong password (not required)
-
Remove anonymous users → Yes
-
Disallow root remote login → Yes
-
Remove test DB → Yes
-
Reload privileges → Yes
STEP 7️⃣ Install PHP (Compatible with Ubuntu 20.04)
sudo apt install php php-mysql libapache2-mod-php php-cli php-curl php-zip php-gd php-mbstring php-xml -y
Check PHP version
php -v
STEP 8️⃣ Configure Apache for PHP
Edit Apache config:
sudo nano /etc/apache2/mods-enabled/dir.conf
Ensure this order:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
Restart Apache:
sudo systemctl restart apache2
STEP 9️⃣ Test PHP
Create PHP test file:
sudo nano /var/www/html/info.php
Paste:
<?php
phpinfo();
?>
Save → CTRL+O, ENTER, CTRL+X
Open browser:
http://YOUR_PUBLIC_IP/info.php
✅ PHP info page should load
https://kinsta.com/wp-content/uploads/2019/10/phpinfo-page-example.png
⚠️ After testing, delete it for security:
sudo rm /var/www/html/info.php
STEP 🔟 Install phpMyAdmin
sudo apt install phpmyadmin -y
During setup:
-
Select Apache2 ✔
-
Configure database → Yes
-
phpMyAdmin password → Set
Enable extensions:
sudo phpenmod mbstring sudo systemctl restart apache2
Access:
http://YOUR_PUBLIC_IP/phpmyadmin
STEP 1️⃣1️⃣ Create MySQL Database & User
Login to MySQL:
sudo mysql
Run:
CREATE DATABASE mydb; CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'StrongPassword@123'; GRANT ALL PRIVILEGES ON mydb.* TO 'myuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
STEP 1️⃣2️⃣ Auto-Start Services on Boot
sudo systemctl enable apache2 sudo systemctl enable mysql
STEP 1️⃣3️⃣ Final Service Check
systemctl status apache2
systemctl status mysql
php -v
✅ LAMP Stack Installed Successfully 🎉
You now have:
-
✔ Ubuntu 20.04 (Always Free)
-
✔ Apache Web Server
-
✔ MySQL Database
-
✔ PHP
-
✔ phpMyAdmin
🔒 Security Tips (Recommended)
-
Use strong MySQL passwords
-
Remove test PHP files
-
Keep system updated:
sudo apt update && sudo apt upgrade -y
Enjoy your new LAMP stack on Oracle Cloud Always Free! 🚀