Skip to content

Instantly share code, notes, and snippets.

@leosaa
Last active April 11, 2020 03:19
Show Gist options
  • Save leosaa/7f9791f7c7adb9f3a6ac2648ee2fd0d1 to your computer and use it in GitHub Desktop.
Save leosaa/7f9791f7c7adb9f3a6ac2648ee2fd0d1 to your computer and use it in GitHub Desktop.

Installing moodle on Centos 7 with nginx, php-fpm and mariadb

I am going to use use a Centos 7 minimal install virtual box machine. So the first step is to clone the VM with new mac address.

set the environment

CentOS: 7.7

php: 7.3.16

mariadb: 10.1.41

nginx: 1.16.1

add "IP_address moodle.casa.int" to your /etc/hosts

hostname

hostnamectl set-hostname moodle01 --static
reboot

port fowarding

In order to connect through ssh from your local machine to your VM you need set port forwarding as follow:

ip addr show

In VB, you have to create a portforwarding as:

Name: ssh Protocol: TCP

Host IP: 127.0.0.1

Host Portl: 2222

Guest IP: 10.0.2.15 (the same showed in the previuos command)

GuestPort: 2222

ssh keys

Generate the key pairs

ssh-keygen -t ecdsa -f .ssh/id_moodle
ssh-copy-id -p 2222 -i .ssh/id_moodle root@127.0.0.1

add the following lines to your .ssh/config:

 Host moodle
     Hostname 127.0.0.1
     IdentityFile ~/.ssh/id_moodle
     Port 2222
     User root
     ForwardAgent yes

Now, you will be able to run ssh moodle

enable EPEL and IUS

yum -y install epel-release
yum -y install https://$(rpm -E '%{?centos:centos}%{!?centos:rhel}%{rhel}').iuscommunity.org/ius-release.rpm
yum -y install yum-plugin-replace
yum update
yum -y install vim-enhanced tcpdump wget yum-utils

MariaDB

yum remove mariadb-libs
yum install mariadb101u.x86_64 mariadb101u-server.x86_64

config mariadb

/usr/bin/mysql_secure_installation
* Enter current password for root (enter for none): Just press the Enter button
* Set root password? [Y/n]: Y
* New password: your-root-password
* Re-enter new password: your-root-password
* Remove anonymous users? [Y/n]: Y
* Disallow root login remotely? [Y/n]: Y
* Remove test database and access to it? [Y/n]: Y
* Reload privilege tables now? [Y/n]: Y

create Moodle database

mysql -uroot -p mysql
CREATE DATABASE moodle DEFAULT CHARACTER SET UTF8 COLLATE utf8_unicode_ci;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'moodpass';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost' IDENTIFIED BY 'moodpass' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT

install nginx

yum -y install nginx 

install php 73

yum -y install mod_php73 php73-common php73-mbstring php73-xmlrpc php73-soap php73-gd php73-xml \
php73-cli php73-json php73-mysqlnd php73-intl php73-fpm php73-fpm-nginx
mkdir /var/run/php-fpm
sed -i 's/server 127.0.0.1:9000/\#server 127.0.0.1:9000/' /etc/nginx/conf.d/php-fpm.conf
sed -i  '/#server/a server unix:/var/run/php-fpm/www.sock;' /etc/nginx/conf.d/php-fpm.conf
systemctl restart nginx

config php-fpm

Edit /etc/php-fpm.d/www.conf and replace the following lines:

user = 
group = 
listen = 
listen.owner = 
listen.group = 
listen.mode = 

by

user = nginx
group = nginx
listen = /var/run/php-fpm/www.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660

set the virtual host for moodle in nginx

server {
    access_log /var/log/nginx/moodle.casa.int-access_log;
    error_log /var/log/nginx/moodle.casa.int-error_log crit;

    listen 80;
    server_name moodle.casa.int;

    location / {
        root /var/www/html/moodle;
        index index.php index.html index.htm;

        # moodle rewrite rules
        rewrite ^/(.*.php)(/)(.*)$ /$1?file=/$3 last;
}

# php parsing
location ~ .php$ {
        root /var/www/html/moodle;
        try_files $uri =404;
        fastcgi_pass unix:/var/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 4k;
        fastcgi_busy_buffers_size 256k;
        fastcgi_temp_file_write_size 256k;
    }
}
EOF

install moodle

wget -v https://download.moodle.org/download.php/stable38/moodle-3.8.2.tgz
tar xzvf moodle-3.8.2.tgz -C /var/www/html/
sudo mkdir /var/www/moodledata
sudo chown -R nginx:nginx /var/www/moodledata
sudo chmod -R 755 /var/www/moodledata

config moodle

connect to http://moodle.casa.int

set the cron job

crontab -u apache -e

Populate the cron file with:

* * * * *    /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment