title | parent | tags | thumbnail | date | description | author | redirect_from | mrm | xredirect | slug | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Get Started with Apache and PHP on Ubuntu and OCI |
tutorials |
|
assets/apache-php-ubuntu-Apache_Diagram.png |
2021-10-21 01:00 |
Using Free Tier OCI to install PHP and Apache on an Ubuntu Linux instance, then connecting the instance to the internet for further development. |
|
/collections/tutorials/apache-php-ubuntu-oci-installation/ |
WWMK211125P00028 |
apache-php-ubuntu-oci-installation |
{% slides %}
In this tutorial, you'll use an Oracle Cloud Infrastructure (OCI) Free Tier account to set up a compute instance on the latest version of Ubuntu. Then, you'll install PHP and an Apache web server to access your new server from the internet. This tutorial covers all the steps necessary to set up a virtual network for your host and connect that host to the internet.
Key tasks include how to:
- Set up a compartment for your development work.
- Install your Ubuntu instance and connect it to your Virtual Cloud Network (VCN).
- Set up an Oracle Cloud Infrastructure virtual cloud network and related network services required for your host to connect to the internet.
- Set up
ssh
encryption keys to access your Ubuntu server.
- Configure ingress rules for your VCN.
- Configure Apache and PHP 7 on your instance.
- Connect to your instance from the internet.
Here's a simplified diagram for setting up your Linux VM.
![] ![]({% imgx aligncenter assets/apache-php-ubuntu-Apache_Diagram.png 1200 578 "" "Within OCI is the Compute VM, connected to the VCN, connected to the Internet" %})
For additional information, see:
- [Start for Free]({{ site.urls.always_free }})
- Launch your first Linux VM
- Create a VCN
To successfully complete this tutorial, you'll need:
- An Oracle Cloud Infrastructure Free Tier account. [Start for Free]({{ site.urls.always_free }}).
- A MacOS, Linux, or Windows computer with
ssh
support installed.
First, let's configure a compartment for your development.
Create a compartment for the resources that you create in this tutorial.
- Log in to the Oracle Cloud Infrastructure Console.
- Open the navigation menu and click Identity & Security. Under Identity, click Compartments.
- Click Create Compartment.
- Complete the following fields:
- Name:
<your-compartment-name>
- Description:
Compartment for <your-description>.
- Parent Compartment:
<your-tenancy>(root)
- Name:
- Click Create Compartment.
Reference: Create a compartment
Use the Create a VM Instance wizard to create a new compute instance.
The wizard does several things when installing the instance:
- Creates and installs a compute instance running Ubuntu Linux.
- Creates a VCN with the required subnet and components needed to connect your Ubuntu Linux instance to the internet.
- Creates an
ssh
key pair you use to connect to your instance.
To get started installing your instance with the Create a VM Instance wizard, follow these steps:
-
From the main landing page, select Create a VM Instance wizard. ![]({% imgx aligncenter assets/apache-php-ubuntu-01action-menu.png 1200 423 "" "Quick Actions in the VM Instance Wizard, choose Create a VM Instance" %})
The Create Compute Instance page is displayed. It has a section for Placement, Image and shape, Networking, Add SSH keys, and Boot volume.
-
Choose the Name and Compartment.
Initial Options
- Name:
<name-for-the-instance>
- Create in compartment:
<your-compartment>
Enter a value for the name or leave the system-supplied default.
- Name:
-
Review the Placement settings, and click the Show advanced options link.
Take the default values. Your data might look similar to the following:
Availability domain
- Availability domain: AD-1
- Capacity type: On-demand capacity
- Fault domain: Let Oracle choose the best fault domain
Note: For Free Tier, use Always Free Eligible option for availability domain. {:.notice}
-
Review the Image and shape settings.
-
Select the latest Ubuntu image.
- Click Change Image.
- Select the latest Ubuntu image.
- Click Select Image. Your image is displayed, for example your data looks similar to the following:
Image
- Image: Canonical Ubuntu 20.04
- Image build: 2020.12.11-0
-
Take the default values for Shape.
For example, your data should look similar to the following:
Shape
- Shape: VM.Standard.E2.1.Micro
- OCPU count: 1
- Memory (GB): 1
- Network bandwidth (Gbps): 0.48
Note: For Free Tier, use Always Free Eligible shape options. {:.notice}
-
-
Review the Networking settings. Take the default values provided by the wizard.
Note: The following is sample data. The actual values change over time or differ in a different data center.
- Virtual cloud network: vcn--
- Subnet: vcn--
- Assign a public IPv4 address: Yes {:.notice}
-
Review the Add SSH keys settings. Take the default values provided by the wizard.
- Select the Generate a key pair for me option.
- Click Save Private Key and Save Public Key to save the private and public SSH keys for this compute instance.
If you want to use your own SSH keys, select one of the options to provide your public key.
Note: Put your private and public key files in a safe location. You cannot retrieve keys again after the compute instance has been created. {:.notice}
-
Review the Boot volume settings. Take the default values provided by the wizard.
Leave all check boxes unchecked.
-
Click Create to create the instance. Provisioning the system might take several minutes.
You have successfully created an Ubuntu Linux instance to run your Apache Web Server.
The Create a VM Instance wizard automatically creates a VCN for your VM. You add an ingress rule to your subnet to allow internet connections on port 80.
Follow these steps to select your VCN's public subnet and add the ingress rule.
-
Open the navigation menu and click Networking, and then click Virtual Cloud Networks.
-
Select the VCN you created with your compute instance.
-
With your new VCN displayed, click
<your-subnet-name>
subnet link.The public subnet information is displayed with the Security Lists at the bottom of the page. A link to the Default Security List for your VCN is displayed.
-
Click the Default Security List link.
The default Ingress Rules for your VCN are displayed.
-
Click Add Ingress Rules.
An Add Ingress Rules dialog is displayed.
-
Fill in the ingress rule with the following information.
- Stateless: Checked
- Source Type: CIDR
- Source CIDR: 0.0.0.0/0
- IP Protocol: TCP
- Source port range: (leave-blank)
- Destination Port Range: 80
- Description: Allow HTTP connections
Click Add Ingress Rule. Now HTTP connections are allowed. Your VCN is configured for Apache server.
-
Click Add Ingress Rule.
Now HTTP connections are allowed. Your VCN is configured for Apache server.
You have successfully created an ingress rule that makes your instance available from the internet.
Next, install and configure Apache web server and PHP to run on your Ubuntu Linux instance.
To install and set up Apache and PHP, perform the following steps:
-
Open the navigation menu and click Compute. Under Compute, click Instances.
-
Click the link to the instance you created in the previous step.
From the Instance Details page look under the Instance Access section, the Public IP Address field. Write down the public IP address the system created for you. You use this IP address to connect to your instance.
-
Open a Terminal or Command Prompt window.
-
Change into the directory where you stored the
ssh
encryption keys you created before. -
Connect to your instance with this SSH command.
ssh -i <your-private-key-file> ubuntu@<x.x.x.x>
Since you identified your public key when you created the instance, this command logs you into your instance. You can now issue
sudo
commands to install and start your server. -
Install Apache Server.
sudo apt update sudo apt -y install apache2
-
Start Apache.
sudo systemctl restart apache2
-
Update firewall settings.
The Ubuntu firewall is disabled by default. However, you still need to update your
iptables
configuration to allow HTTP traffic. Updateiptables
with the following commands:sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 80 -j ACCEPT sudo netfilter-persistent save
These commands add a rule to allow HTTP traffic and saves the changes to the
iptables
configuration files. -
You can now test your server.
You can test your server from the command line with
curl localhost
. Or, you can connect your browser to your public IP address assigned to your instance: http://<x.x.x.x>
. The page looks similar to: ![]({% imgx aligncenter assets/apache-php-ubuntu-06apache-ubun.png 1200 444 "" "Default Apache2 Ubuntu welcome page" %}) -
Install PHP 7 with the following commands.
sudo apt -y install php libapache2-mod-php
-
Verify installation and restart Apache.
$ php -v $ sudo systemctl restart apache2
-
Add a PHP test file to your instance.
Create the file:
sudo vi /var/www/html/info.php
-
In the file, input the following text and save the file:
<?php phpinfo(); ?>
-
Connect to http://
<your-public-ip-address>/
info.php.The browser produces a listing of PHP configuration on your instance similar to the following.
![]({% imgx aligncenter assets/apache-php-ubuntu-07php.png 1200 942 "" "PHP configuration information screen" %})
Note: After you are done testing, remove info.php from your system. {:.notice}
Congratulations! You have successfully installed Apache and PHP 7 on your Oracle Cloud Infrastructure instance.
You have successfully installed and deployed an Apache web server and PHP on Oracle Cloud Infrastructure using a Linux instance.
To explore more information about development with Oracle products, check out these sites:
{% endslides %}