Install WordPress CMS on Oracle Linux with MySQL database
Introduction
WordPress is one of the most popular Content Management System (CMS). This powerful CMS is commonly used as a blog but there are plenty of add-ons and modules to expand its capabilities.
Use this workshop as a starting point and have a complete installation built on top of Oracle Linux and Oracle MySQL Database Service.
Steps to success
In this workshop you'll learn how to:
- Create VCN and subnets
- Create Linux instances
- Install and configure Apache HTTP Server
- Create and populate MySQL Database Service instance
- Install and configure WordPress
Prerequisites
- You need an Oracle Cloud Infrastructure account.
- A web browser
- SSH Terminal - Cloud Shell (provided in the OCI console). Alternatively, terminal with SSH (Linux or MAC), Windows machine with GitBash/Putty or WSL (Windows Subsystem for Linux).
Create your Virtual Cloud Network and Related Components
Create your VCN and subnets
Set up a Virtual Cloud Network (VCN) to connect your Linux instance to the internet. You will configure all the components needed to create your virtual network.
Open the navigation menu. Under Core Infrastructure, go to Networking and click Virtual Cloud Networks.
Ensure that a compartment (or the compartment designated for you) is selected in the Compartment list on the left.
Click Start VCN Wizard.
Select VCN with Internet Connectivity, and then click Start VCN Wizard.
Enter the following (descriptions are italicized, replace with the values for your scenario):
Name: Enter a name for your cloud network
COMPARTMENT: select the desired compartment
VCN CIDR BLOCK: 10.0.0.0/16
PUBLIC SUBNET CIDR BLOCK: 10.0.0.0/24
PRIVATE SUBNET CIDR BLOCK: 10.0.1.0/24
DNS RESOLUTION: checked
Note The public and private subnets have different CIDR blocks.
Click Next.
The Create a VCN with Internet Connection configuration dialog will be displayed, confirming all the values you just entered and listing additional components that will be created.
Click Create to start the workflow.
After the workflow completes, click on View Virtual Cloud Networks and you will be directed to the details page of the VCN you created.
Configure security list to allow HTTP incoming connections
Create the rules in the default security list that will allow incoming connections on ports 80/TCP and 443/TCP.
Click View Virtual Cloud Network to view your new VCN.
With your new VCN displayed, click on your Public subnet link.
The public subnet information is displayed with the Security Lists at the bottom of the page. There should be a link to the Default Security List for your VCN.
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.
Enter the following:
Stateless: Do not select
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
Once you click Add Ingress Rule, inbound HTTP connections are allowed.
Repeat the steps from 1-4 and enter the following:
Stateless: Do not select
Source Type: CIDR
Source CIDR: 0.0.0.0/0
IP Protocol: TCP
Source port range: (leave-blank)
Destination Port Range: 443
Description: Allow HTTPS connections
Once you click Add Ingress Rule, inbound HTTPS connections are allowed.
Configure security list to allow MySQL incoming connections
Create a rule in the Security List for Private Subnet-VCN Name security list that will allow incoming connections on ports 3306/TCP and 33060/TCP.
Click View Virtual Cloud Network to view your new VCN.
With your new VCN displayed, click on your Private subnet link.
The private subnet information is displayed with the Security Lists at the bottom of the page. There should be a link to the Security List for Private Subnet-VCN Name for your private subnet.
Click the Security List for Private Subnet-VCN Name link.
The default Ingress Rules for your VCN are displayed.
Click Add Ingress Rules.
An Add Ingress Rules dialog is displayed.
Enter the following:
- Stateless: Do not select
- Source Type: CIDR
- Source CIDR: 10.0.0.0/24
- IP Protocol: TCP
- Source port range: (leave-blank)
- Destination Port Range: 3306
- Description: Allow MySQL connections
Once you click Add Ingress Rule, inbound MySQL connections from the public subnet are allowed.
Repeat the steps from 1-4 and enter the following:
- Stateless: Do not select
- Source Type: CIDR
- Source CIDR: 10.0.0.0/24
- IP Protocol: TCP
- Source port range: (leave-blank)
- Destination Port Range: 33060
- Description: Allow MySQL X connections
Once you click Add Ingress Rule, inbound MySQL X connections from the public subnet are allowed.
Create and Configure Oracle MySQL Database Service
Create Oracle MySQL Database Service required policy
Note: If you are using a free Oracle-provided hands-on lab, creating this policy is not required. You can go to Create your Oracle MySQL Database Service section.
Open the navigation menu. Under Governance and Administration, go to Identity and click Policies.
On the Policies page, under List Scope, select the Compartment(root) and click on the Create Policy button.
Enter the following information:
- Name: policy name
- Compartment: (root)
In the Policy Builder, click Customize (Advanced).
Enter the following required MySQL Database Service policies:
Policy Statements
- Allow group Administrators to {COMPARTMENT_INSPECT} in tenancy
- Allow group Administrators to {VCN_READ, SUBNET_READ, SUBNET_ATTACH, SUBNET_DETACH} in tenancy
- Allow group Administrators to manage mysql-family in tenancy
Click Create.
Create your Oracle MySQL Database Service
Open the navigation menu. Under Database, go to MySQL and click DB Systems.
On the DB Systems page, select the compartment and click on Create MySQL DB System.
Enter the following information:
- Name: DB system name
- Description: MySQL system Description
- Compartment: select the compartment
- Select an Availability Domain: select the availability domain
- Fault Domain: Optional. Can be left unchecked
- Select a Shape: choose the desired shape by clicking on Change Shape
- Data Storage Size (GB): Enter the desired storage size
- Maintenance Window Start Time: None
Click Next to advance to Database Information screen.
Enter the following information:
- Username: administrator user name
- Password: admin password
- Confirm Password:admin password
- Virtual Cloud Network in: select the VCN compartment
- Virtual Cloud Network: select the a private VCN
- Hostname: hostname name
- MySQL Port: 3306
- MySQL X Protocol Port: 33060
Click Next to advance to Backup Information screen.
Enter the following information:
- Enable Automatic Backups: checked
- Backup retention period: 7
- Default Backup Window: checked
You'll be taken to the MySQL DB System's details page. Once the yellow hexagon turns green, your DB system is provisioned, and up and running.
Create VM Compute Instance and Configure Apache and PHP
Create Oracle Linux instance to host your Apache web server.
Open the Oracle Cloud Infrastructure main menu.
Select Compute then Instances.
From the list of instances screen click Create Instance.
Enter a name for the instance.
Select the compartment to create the instance in.
Complete the following in the Configure placement and hardware section:
- Availability domain: Select the Availability domain that you want to create the instance in
- Fault Domain: Optional. Can be left unchecked
- Image: Latest Oracle Linux ( by default the latest supported version will be already selected)
- Shape: Select the desired shape
Complete the following in the Configure networking section:
- Network Select an existing virtual cloud network
- Virtual cloud network in: Choose the compartment that has the desired VCN
- Network: Select the Virtual Network Cloud Network
- Subnet in: Choose the compartment that has the desired VCN
- Subnet: Select a public subnet *
- Use network security groups to control traffic:unchecked
- Public IP Address: Assign a public IPv4 address
In the Add SSH keys section:
If you don't have a SSH key pair:
- Select Generate SSH key pair.
- Click on Save Private Key and follow the browser prompt to save the private key.
- Click on Save Public Key and follow the browser prompt to save the public key.
If you have a public key, you can:
- Select Choose public key files
- Drag and drop the public key files over or Or browse to a location., find the location and select the files.
or
- Select Paste public keys.
- Paste the Public Key Value into SSH keys (multiple keys can be added by clicking on Another key).
In the Configure boot volume, leave all options unchecked.
Click Create.
You will be taken to the instance's details page. Once the yellow square turns green, your instance will be provisioned, up and running.
Install and configure Apache HTTP server with PHP
Open the Oracle Cloud Infrastructure main menu.
Select Compute then Instances.
From the list of instances, click on the instance name you want to configure the HTTP server.
Once the instance details are loaded, find on Public IP Address: on the right side, under Istance Access. Copy the Public IP access.
From a terminal (Cloud Shell or any other SSH enabled terminal), connect to the instance:
ssh -i </path/private key file> opc@<instance's public IP>
Install Apache HTTP Server and php. Dependencies will be resolved automatically and installed.
sudo yum install -y httpd
Enable and start Apache HTTP Server.
sudo systemctl enable httpd --now
Allow HTTP and HTTPS in the local iptables firewall.
sudo firewall-cmd --permanent --add-port=80/tcp sudo firewall-cmd --permanent --add-port=443/tcp sudo firewall-cmd --reload
Add the extra repositories:
sudo yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm sudo yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm sudo yum-config-manager --enable remi-php74
Install PHP.
sudo yum install -y php sudo systemctl restart httpd
Create a test php page.
echo -e '<?php \nphpinfo();' | sudo tee /var/www/html/test.php
From a web browser, navigate to http://public server IP/test.php.
Install MySQL and MySQL Shell
Install MySQL release package.
sudo yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
Install MySQL Shell.
sudo yum -y install mysql-shell
Install WordPress CMS
Install WordPress in your Oracle Linux instance
From your SSH enabled terminal, SSH to the Oracle Linux instance where Wordpress will be installed.
ssh -i <path/private key> opc@<instance public IP>
Install WordPress required packages.
sudo yum install -y php-mysqlnd php-zip php-gd php-mcrypt php-mbstring php-xml php-json sudo systemctl restart httpd
Download the latest WordPress.
curl -O https://wordpress.org/latest.tar.gz
Extract latest.tar.gz to /var/www/html (Apache document root).
sudo tar zxf latest.tar.gz -C /var/www/html/ --strip 1
Adjust ownership.
sudo chown apache. -R /var/www/html/
Create upload directory, adjust ownership.
sudo mkdir /var/www/html/wp-content/uploads sudo chown apache:apache /var/www/html/wp-content/uploads
Adjust SE Linux.
sudo chcon -t httpd_sys_rw_content_t /var/www/html -R
Allow Apache to connect to an external database.
sudo setsebool -P httpd_can_network_connect_db 1
Connect to the MySql database service using MySQL Shell.
mysqlsh --sql -u admin -h <MDS end point IP>
Create WordPress database and user.
create database wordpress; create user wordpress IDENTIFIED BY 'ComplexPass0rd!'; GRANT ALL PRIVILEGES ON wordpress.* To wordPress; \quit;
From a browser access http://instance public IP/wp-admin/setup-config.php.
Click Let's Go.
Fill the following information:
- Database Name: database you created for WordPress
- Username: Your database username
- Password: Your database password
- Database Host: MySQL Database Service IP address
- Table Prefix: leave as is. only need to change if multiple WordPress running on the same database
Click Run the installation.
Fill the following information in the welcome screen:
- Site Title: WordPress site title
- Username: WordPresss admin
- Password: WordPresss admin password
- Your Email: your email
Click Install WordPress.
From a browser access http://instance public IP/wp-login.php and star managing your new WordPress installation.
Acknowledgements
Authors: Orlando Gentil and Frédéric Descamps
Learn More
Learn to deploy your WordPress CMS in Oracle Cloud Infrastructure (OCI) using the Terraform code in Github or a sample stack in OCI Resources Manager Set up a WordPress CMS connected to a MySQL database in the cloud .
Watch the video on Running WordPress with Oracle MySQL Database Service
Explore other labs on docs.oracle.com/learn or access more free learning content on the Oracle Learning YouTube channel . Additionally, visit education.oracle.com/learning-explorer to become an Oracle Learning Explorer.
For product documentation, visit Oracle Help Center .