Installing Apache and PHP 7 on OCI

Jeff Davies
Aug 28 · 5 min read

Installing Apache web server with PVP 7 on Oracle Cloud Infrastructure

Until now we have been able to use Node.js are our web server. This is because our web server wasn’t very complicated. However, as we prepare to move into more advanced topics in Oracle Cloud Infrastructure, we age going to be a better platform for hosting our web pages. Since Apache HTTPD currently enjoys about 60% of the web server market share, it makes sense that we use Apache as our web server. In addition, we will use PHP with Apache to handle our need for dynamic web pages. In this article I will cover the following:

  1. Stopping Our Current Node Web Servers
  2. Installing Apache Web Server
  3. Configuring our OCI environment
  4. Installing PHP for Apache

Stopping Our Current Node Web Servers

We need to stop the existing web servers running on port 3000. To do this we will need to turn our and disable our existing node.js web servers that listen to that address and auto-start when the server is rebooted.

SSH into each of your compute instances and perform the following commands:

cd /etc/systemd/system
sudo systemctl disable starthelloserver.service
sudo rm starthelloserver.service
cd ~

The next time we reboot the server, the helloServer won't be started. This makes room for us to autostart our new Apache web server instead.

Installing Apache Web Server

To install the Apache software, we will need to SSH to each of our 2 compute instances that currently hosts our Node.js web servers. The installation command is quite simple:

sudo yum install httpd -y

After that, we need to ensure that the server starts by default if the compute instance restarts. The following command will take care of that:

sudo systemctl enable httpd

Let's also force the start of the Apache server with the following command:

sudo systemctl restart httpd

Be sure to do this for both of your compute instances. At this point, Apache is installed and running. Now we just need to configure OCI to allow web access to it through the load balancer.

Configuring our OCI Environment

Before we can access the web server through the load balancer, we need to create a backend set that listens to port 80 from the load balancer. Create a new backend set with the following attributes:

Name: HTTP80
Traffic Distribution Policy: Weighted Round Robin
Enable Load Balancer Cookie Persistence: Selected
Cookie Name: userinfo
Domain Name: The domain name you used for your SSL certificate
Path: /
Attributes — Secure: Checked
Attributes — HTTP Only: Checked
Protocol: HTTP
Port: 80
Interval in MS: 300000 (5 minutes)
Timeout in MS: 5000
Number of Retries: 3
Status Code: 200
URL Path (URI): /
Response Body Regex: leave blank

Now we need to add the specific backend servers to our backend set. Locate the link for the http80 backend set that you just created and add the backends.

Now we can edit our listener for the load balancer and tell it to use this new backend set instead of the old one. Edit your current listener:

And change the Backend Set to the new http80 backend set.

Now SSH to each of your instances and open port 80 in the firewall with the following commands:

sudo firewall-cmd --permanent --add-port=80/tcp

We may as well get rid of the old 3000 port while we are here.

sudo firewall-cmd --permanent --remove-port=80/tcp

Now let's activate these changes:

sudo firewall-cmd --reload

Now you should be able to open your browser to https://<your domain name> and see the Apache home page:

Installing PHP for Apache

This follows the standard process for installing PHP for Apache.

sudo yum install yum install yum install yum-utilssudo yum-config-manager --enable remi-php73sudo yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo

Be advised that many of these commands will require your acceptance by typing in a y in the terminal. Now you can check the version of PHP that has been installed from the command line:

php -v

Which should show you the following:

Testing the PHP Installation

Using the ssh connection to each of your server instances, navigate to /var/www/html and create a file named info.php using the following command:

sudo vi /etc/www/html/info.php

Edit the file to contain the following:


Save the file and do the same thing in your other compute instance. Now you can point your web browser to https://<your domain name>/info.php and see the details of your Apache and PHP installation:


Hopefully, this helped demystify the process for running PHP on OCI. Naturally, if we had a larger number of web server to manage, making these changes manually would be wasteful. A better approach at scale would be to create an image of one server that is fully configured, and use that image to create new compute instances and add them to the backed set of the load balancer.

In my next article, I will show you how to create a simple PHP website that leverages OCIs built-in Identity Cloud Service (IDCS) to help you control access to your website contents by requiring users to log into the web site.

As always, I hope you enjoyed this article and found it useful. If so please give me a clap and as always, feel free to ask any questions.

Oracle Developers

Aggregation of articles from Oracle & partners engineers, Groundbreaker ambassadors & the developer community on all things Oracle Cloud and its technologies. The views expressed are those of authors solely and do not necessarily reflect Oracle's. Contact @jimgris or @brhubart

Jeff Davies

Written by

Long time software engineer, software architect, technical evangelist and motorcycle enthusiast.

Oracle Developers

Aggregation of articles from Oracle & partners engineers, Groundbreaker ambassadors & the developer community on all things Oracle Cloud and its technologies. The views expressed are those of authors solely and do not necessarily reflect Oracle's. Contact @jimgris or @brhubart

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade