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 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:
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:
When our application server is provisioned, we can connect to it using the ssh key we provided during the creation and using the
ssh -i ~/.ssh/id_rsa_oci firstname.lastname@example.org
We can now install the required repository to install latest PHP 7.4 packages and then install apache and PHP:
$ 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 $ sudo yum install php php-cli php-mysqlnd php-zip php-gd \ php-mcrypt php-mbstring php-xml php-json
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 https://moodle.org:
$ sudo /var/www/ $ sudo rm -rf html $ sudo wget https://download.moodle.org/download.php/direct/stable38/moodle-latest-38.tgz $ 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 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:
ssh -A -i ~/.ssh/id_rsa_oci email@example.com
Please mind the
-Athat is very important to forward the key !
myMoodle, we can connect to
myMysql using the private IP:
To install MySQL 8.0, we will install the Community Yum repository and MySQL Server and MySQL Shell:
$ sudo yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm $ sudo yum install -y mysql-community-server mysql-shell
When MySQL Server is installed, we need to :
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
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: