Let us create a basic public Apache web app using the Oracle Cloud Infrastructure (OCI)'s virtual cloud network and VM compute instance.
1. Create a VCN
Log in to Oracle Cloud at cloud.oracle.com.
Go to Virtual cloud networks in the Networking family.
Click on Start VCN Wizard to create a simple VCN with full Internet connectivity.
Click on Create VCN with Internet Connectivity
Then, click on the Start VCN Wizard.
Give the VCN a name.
Click on Next leaving everything else as default.
Click on Create on the next page and wait till the creation is complete.
2. Create a public VM instance
Go to the Instances page under the Compute family.
Click on Create instance
Ensure you select a public subnet from the VCN you just created:
Scrolling down in Add SSH keys, click on Save private key to download the SSH key you'll be using to log into the instance.
Then, click Create.
Once creation is done, copy the Public IP address of the compute instance.
3. SSH into instance and install Apache
Change directory to where you downloaded the SSH key, e.g., Downloads
.
Change access mode of the SSH key using:
chmod 400 my-ssh-file.key
to make it read-only for you for better security. Modify the name of the key to your key name.
Log into the VM using:
ssh -i ssh-key-2024-10-30.key opc@132.145.138.252
changing your SSH key name and IP address to yours.
When prompted by the Terminal "Are you sure you want to continue...", answer yes
.
Once in the VM, install Apache using:
sudo yum install httpd -y
sudo apachectl start
sudo systemctl enable httpd
sudo acpachectl configtest
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload
sudo bash -c 'echo This is APP server 1 running on Oracle Cloud Infrastructure >> /var/www/html/index.html'
When everything is done, run curl localhost:80
to ensure the web app is accessible locally inside the VM:
4. Allow public access to the VM web app
Going back to the Compute Instance page, select the subnet where it lives:
You'll arrive at the subnet details page. Select the security list used by the subnet.
You'll arrive at the security list details page. Click on Add Ingress Rules.
Add an ingress rule to allow incoming connections from everywhere (0.0.0.0/0) to port 80. Click Add Ingress Rules.
6. Validate web app
On your web browser, type in the IP address of your VM compute instance and validate you can see the following message:
Safe harbor statement
The information provided on this channel/article/story is solely intended for informational purposes and cannot be used as a part of any contractual agreement. The content does not guarantee the delivery of any material, code, or functionality, and should not be the sole basis for making purchasing decisions. The postings on this site are my own and do not necessarily reflect the views or work of Oracle or Mythics, LLC.
This work is licensed under a Creative Commons Attribution 4.0 International License.