Note:

Install Drupal CMS on Oracle Linux with MySQL database

Introduction

Drupal is a web Content Management System (CMS) written in PHP. Drupal provides the infrastructure for websites worldwide – ranging from personal blogs to corporate, political, and government sites. Very extensible and modular, it can be used in a large variety of scenarios.

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:

Prerequisites

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
    3. Select Paste public keys.
    4. 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 Drupal CMS

Install Drupal in your Oracle Linux instance

  1. From your SSH enabled terminal, SSH to the Oracle Linux instance where Drupal will be installed.

    ssh -i <path/private key> opc@<instance public IP>
    
  2. Install Drupal required packages.

    sudo yum install -y  php-mbstring php-gd php-xml php-pear php-fpm php-mysql php-pdo php-opcach
    sudo systemctl restart httpd   
    
  3. Edit the httpd.conf.

    sudo vim /etc/httpd/conf/httpd.conf
    
  4. Locate the section <Directory “/var/www/html”> and in that section change AllowOverride All to AllowOverride None. You can navigate on the file until you find it or press “/”, and enter Options Indexes FollowSymLinks.

  5. Restart Apache.

    sudo systemctl restart httpd
    
  6. Download Drupal from the Drupal website.

    curl -L -o drupallatest.tar.gz  https://www.drupal.org/download-latest/tar.gz
    
  7. Extract latest.tar.gz to /var/www/html (Apache document root).

    sudo tar zxf drupallatest.tar.gz -C /var/www/html/ --strip 1
    
  8. Adjust ownership.

    sudo chown apache. -R /var/www/html/
    
  9. Create settings.php.

    cd /var/www/html/sites/default/
    cp default.settings.php settings.php
    
  10. Adjust ownership.

   sudo chown apache. -R /var/www/html/
  1. Adjust SE Linux.
   sudo chcon -R -t httpd_sys_content_rw_t /var/www/html/sites/
  1. Allow Apache to connect to an external database.
   sudo setsebool -P httpd_can_network_connect_db 1
  1. Connect to the MDS database using MySQL Shell.
   mysqlsh --sql -u admin -h <MDS end point IP>
  1. Create Drupal database and user.
   create database drupal;
   create user drupaluser IDENTIFIED BY 'ComplexPass0rd!';
   GRANT ALL PRIVILEGES ON drupal.* To drupaluser;
   \quit
  1. From a browser access http://instance public IP/.

  2. Choose language and click Save and Continue.

  3. Select an installation profile, select Standard profile and click Save and Continue.

  4. If all settings are correct, you’ll see the database configuration page. Fill the following information:

    • Database type : MySQL, MariaDB, Percona Server, or equivalent
    • Database name: drupal
    • Database username: drupaluser
    • Database password: ComplexPass0rd! Expand Advanced options
    • Host: MDS IP address
  5. Click Install site.

  6. Configure the site by entering the following information:

    • Site name: Choose your site name
    • Site email address: email account for automated emails sent by the site
    • Username: Drupal administrator
    • Password : Drupal administrator password
    • Confirm password: confirm password
    • Email address: your email address
    • Default country: choose the country
    • Default time zone: choose the time zone
    • Check for updates automatically: checked
    • Receive email notifications : unchecked
  7. Click Save and continue.

  8. From a browser access http://instance public IP/, login with your admin user and start customizing the website.

Acknowledgements

Authors: Orlando Gentil and Frédéric Descamps

Learn More

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.