Install WordPress CMS on Oracle Linux with MySQL database

5
0
Send lab feedback

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

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

  2. Click Start VCN Wizard.

  3. Select VCN with Internet Connectivity, and then click Start VCN Wizard.

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

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

  6. Click Create to start the workflow.

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

  1. Click View Virtual Cloud Network to view your new VCN.

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

  3. Click the Default Security List link.

    The default Ingress Rules for your VCN are displayed.

  4. Click Add Ingress Rules.

    An Add Ingress Rules dialog is displayed.

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

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

  1. Click View Virtual Cloud Network to view your new VCN.

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

  3. Click the Security List for Private Subnet-VCN Name link.

    The default Ingress Rules for your VCN are displayed.

  4. Click Add Ingress Rules.

    An Add Ingress Rules dialog is displayed.

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

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

  1. Open the navigation menu. Under Governance and Administration, go to Identity and click Policies.

  2. On the Policies page, under List Scope, select the Compartment(root) and click on the Create Policy button.

  3. Enter the following information:

    • Name: policy name
    • Compartment: (root)
  4. In the Policy Builder, click Customize (Advanced).

  5. 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
  6. Click Create.

Create your Oracle MySQL Database Service

  1. Open the navigation menu. Under Database, go to MySQL and click DB Systems.

  2. On the DB Systems page, select the compartment and click on Create MySQL DB System.

  3. 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
  4. Click Next to advance to Database Information screen.

  5. 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
  6. Click Next to advance to Backup Information screen.

  7. Enter the following information:

    • Enable Automatic Backups: checked
    • Backup retention period: 7
    • Default Backup Window: checked
  8. 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.

  1. Open the Oracle Cloud Infrastructure main menu.

  2. Select Compute then Instances.

  3. From the list of instances screen click Create Instance.

  4. Enter a name for the instance.

  5. Select the compartment to create the instance in.

  6. 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
  7. 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
  8. In the Add SSH keys section:

    If you don't have a SSH key pair:

    1. Select Generate SSH key pair.
    2. Click on Save Private Key and follow the browser prompt to save the private key.
    3. Click on Save Public Key and follow the browser prompt to save the public key.

    If you have a public key, you can:

    1. Select Choose public key files
    2. Drag and drop the public key files over or Or browse to a location., find the location and select the files.

    or

    1. Select Paste public keys.
    2. Paste the Public Key Value into SSH keys (multiple keys can be added by clicking on Another key).
  9. In the Configure boot volume, leave all options unchecked.

  10. Click Create.

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

  1. Open the Oracle Cloud Infrastructure main menu.

  2. Select Compute then Instances.

  3. From the list of instances, click on the instance name you want to configure the HTTP server.

  4. Once the instance details are loaded, find on Public IP Address: on the right side, under Istance Access. Copy the Public IP access.

  5. 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>
    
  6. Install Apache HTTP Server and php. Dependencies will be resolved automatically and installed.

    sudo yum install -y httpd
    
  7. Enable and start Apache HTTP Server.

    sudo systemctl enable httpd --now
    
  8. 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
    
  9. 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
  10. Install PHP.

    sudo yum install -y php
    sudo systemctl restart httpd
  11. Create a test php page.

    echo -e '<?php \nphpinfo();' | sudo tee /var/www/html/test.php
  12. From a web browser, navigate to http://public server IP/test.php.

Install MySQL and MySQL Shell

  1. Install MySQL release package.

    sudo yum -y install https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
  2. Install MySQL Shell.

    sudo yum -y install mysql-shell

Install WordPress CMS

Install WordPress in your Oracle Linux instance

  1. 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>
  2. 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
  3. Download the latest WordPress.

    curl -O https://wordpress.org/latest.tar.gz
  4. Extract latest.tar.gz to /var/www/html (Apache document root).

    sudo tar zxf latest.tar.gz -C /var/www/html/ --strip 1
  5. Adjust ownership.

    sudo chown apache. -R /var/www/html/
  6. Create upload directory, adjust ownership.

    sudo mkdir /var/www/html/wp-content/uploads
    sudo chown apache:apache /var/www/html/wp-content/uploads
  7. Adjust SE Linux.

    sudo chcon -t httpd_sys_rw_content_t /var/www/html -R
  8. Allow Apache to connect to an external database.

    sudo setsebool -P httpd_can_network_connect_db 1
  9. Connect to the MySql database service using MySQL Shell.

    mysqlsh --sql -u admin -h <MDS end point IP>
  10. Create WordPress database and user.

    create database wordpress;
    create user wordpress IDENTIFIED BY 'ComplexPass0rd!';
    GRANT ALL PRIVILEGES ON wordpress.* To wordPress;
    \quit;
  11. From a browser access http://instance public IP/wp-admin/setup-config.php.

  12. Click Let's Go.

  13. 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
  14. Click Run the installation.

  15. Fill the following information in the welcome screen:

    • Site Title: WordPress site title
    • Username: WordPresss admin
    • Password: WordPresss admin password
    • Your Email: your email
  16. Click Install WordPress.

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

SSR