Complete Guide: Install LAMP Stack on Oracle Cloud Always Free (Ubuntu 20.04)

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)

  1. 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

bash
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)

bash
sudo apt update
sudo apt upgrade -y

👉 Always do this first to avoid package errors.


STEP 3️⃣ Install Apache Web Server

bash
sudo apt install apache2 -y

Enable Apache on boot

bash
sudo systemctl enable apache2

Start Apache

bash
sudo systemctl start apache2

Check Apache status

bash
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)

bash
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):

bash
sudo reboot

Reconnect via SSH after 1–2 minutes.

Check again:

bash
sudo ufw status

STEP 5️⃣ Test Apache

Open browser:

text
http://YOUR_PUBLIC_IP

✅ You should see Apache2 Ubuntu Default Page

https://ubuntucommunity.s3.us-east-2.amazonaws.com/original/2X/7/771159b35c97e429247aac754ad44bf06cc1efa8.png


STEP 6️⃣ Install MySQL Server

bash
sudo apt install mysql-server -y

Start & Enable MySQL

bash
sudo systemctl start mysql
sudo systemctl enable mysql

Secure MySQL (VERY IMPORTANT)

bash
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)

bash
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

bash
php -v

STEP 8️⃣ Configure Apache for PHP

Edit Apache config:

bash
sudo nano /etc/apache2/mods-enabled/dir.conf

Ensure this order:

text
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

Restart Apache:

bash
sudo systemctl restart apache2

STEP 9️⃣ Test PHP

Create PHP test file:

bash
sudo nano /var/www/html/info.php

Paste:

php
<?php
phpinfo();
?>

Save → CTRL+OENTERCTRL+X

Open browser:

text
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:

bash
sudo rm /var/www/html/info.php

STEP 🔟 Install phpMyAdmin

bash
sudo apt install phpmyadmin -y

During setup:

  • Select Apache2 ✔

  • Configure database → Yes

  • phpMyAdmin password → Set

Enable extensions:

bash
sudo phpenmod mbstring
sudo systemctl restart apache2

Access:

text
http://YOUR_PUBLIC_IP/phpmyadmin

STEP 1️⃣1️⃣ Create MySQL Database & User

Login to MySQL:

bash
sudo mysql

Run:

sql
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

bash
sudo systemctl enable apache2
sudo systemctl enable mysql

STEP 1️⃣3️⃣ Final Service Check

bash
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:

    bash
    sudo apt update && sudo apt upgrade -y

Enjoy your new LAMP stack on Oracle Cloud Always Free! 🚀

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top