Using OCI to install Moodle with MySQL 8.0


Let’s continue our series of using OCI to install popular Open Source programs with MySQL 8.0. After WordPress, Drupal, it’s not the Moodle’s turn!

This is a request from my Japanese colleague Machiko 😉

We will use two different compute instances:

  • the application server (apache, PHP and Moodle)
  • the database server (MySQL 8.0)

The application server will be reachable from the Internet on port 22 (ssh) and 80 (http). The database server won’t be reachable from outside, we will have to use the application server as jumphost to install the server.

This is an overview of the proposed architecture:

Deploying 2 compute instances

The first step is to install 2 compute instances, one in the Public Subnet and one in the Private Subnet.

We first start with the application server (called myMoodle):

As the second instance will be located in a private subnet, we need to create it first:

We should now have 2 subnets like this:

Also, we don’t have yet any other choice for the Route Table, we will have to modify it later after the creation of a new one using the NAT Gateway we will create now:

This allows us to create a new Routing Table to use that new NAT Gateway:

So we can create the new Routing Rule to use it:

Finally, we can modify our Private Subnet to use this new Routing Table:

Please, note that all those steps regarding the subnets and the routing needs to be done only once. This means if you have already tried following the previous posts, you don’t have to redo it again.

It’s now the right time to create the second compute instance that we will use for MySQL 8.0 and assign it to the Private Subnet:

Installing the Application Server

When our application server is provisioned, we can connect to it using the ssh key we provided during the creation and using the opcuser:

ssh -i ~/.ssh/id_rsa_oci opc@

We can now install the required repository to install latest PHP 7.4 packages and then install apache and PHP:

$ sudo yum -y install
$ sudo yum -y install
$ sudo yum-config-manager --enable remi-php74
$ sudo yum install php php-cli php-mysqlnd php-zip php-gd \
 php-mcrypt php-mbstring php-xml php-json

Installing Moodle

As the server will be used only by moodle, we will then replace the folder /var/www/html by moodle itsefl.

First we need to download moodle from

$ sudo /var/www/
$ sudo rm -rf html
$ sudo wget
$ sudo tar zxvf moodle-latest-38.tgz
$ sudo mv moodle html
$ sudo rm moodle-latest-38.tgz

We have now to create the moodle data directory, change ownership of the files and tell SELinux that httpd can use them:

$ sudo mkdir moodledata
$ sudo chown apache. -R html moodledata
$ sudo chcon --type httpd_sys_rw_content_t html
$ sudo chcon --type httpd_sys_rw_content_t moodledata

And finally we setup the local firewall of the instance to allow traffic to the port 80 and we start Apache:

$ sudo firewall-cmd --zone=public --permanent --add-port=80/tcp
$ sudo firewall-cmd --reload
$ sudo systemctl start httpd

Now you can verify if the Default Security List for you VCN has the required rule to allow traffic to port 80.

If you don’t have already such rule:

You will need to add it:

When ready, you can enter the public ip address in your Internet Browser and you should see the first page of Moodle’s installation wizard:

Installing the Database Server

Installing MySQL 8.0 is also very easy. We need first to connect in ssh to the MySQL Compute Instance using the Application Moodle Server as jumphost:

Finishing the Installation

ssh -A -i ~/.ssh/id_rsa_oci opc@

Please mind the -A that is very important to forward the key !

Once on myMoodle, we can connect to myMysql using the private IP:

ssh opc@

Installing MySQL 8.0

To install MySQL 8.0, we will install the Community Yum repository and MySQL Server and MySQL Shell:

$ sudo yum install -y
$ sudo yum install -y mysql-community-server mysql-shell

When MySQL Server is installed, we need to :

  • start mysqld
  • get the temporary root password
  • connect to MySQL
  • change the root password
  • create a new schema for moodle’s database
  • create a dedicate user with the required privileges for moodle

Here are the commands to perform all these steps above:

sudo systemctl start mysqld
sudo grep password /var/log/mysqld.log
mysqlsh --sql root@localhost

You use the password you got from the second operation and you continue:

MySQL localhost:33060+ ssl SQL > set password = 'MyBigPassw0rd!';
MySQL localhost:33060+ ssl SQL > create database moodle;
MySQL localhost:33060+ ssl SQL > create user moodle identified by 'MyPassw0rd!';
MySQL localhost:33060+ ssl SQL > grant all privileges on moodle.* to moodle;

Now we need to allow connections to the MySQL Classic Protocol’s port, 3306. Like for the webserver, we need to do it locally on the MySQL Instance itself and on OCI:

$ sudo firewall-cmd --zone=public --permanent --add-port=3306/tcp
$ sudo firewall-cmd --reload

We need again to connect in ssh on the webserver (myMoodle) to tell SELinux that Apache can connect to a remote database too:

sudo setsebool -P httpd_can_network_connect_db 1

Finishing Moodle’s Installation

You can go back in the browser and finish Moodle’s installation:

You will have to install some missing PHP packages:

$ sudo yum install -y php-intl php-xmlrpc php-soap php-opcache
$ sudo systemctl restart httpd

After that you can continue the Wizard and you have a fresh new Moodle running on OCI with MySQL 8.0 !

You can also follow all these steps on the following video:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

I deeply value the diversity of MySQL developers, users, community and my blog readers. I cannot agree the suffering, oppression, and systemic racism the Black community faces every day. Black lives matter.