Cara Install Moodle dengan Nginx di FreeBSD

Tutorial FreeBSD server kali ini, kita akan belajar bagaimana cara install Moodle dengan menggunakan Nginx web server disertai SSL dari Let’s Encrypt untuk protokol HTTPS.

*Perangkat yang digunakan*

Perangkat yang digunakan di tutorial ini:

· VPS FreeBSD 12.1 di Vultr · Subdomain moodle.musaamin.my.id · IP 207.148.123.152 · Nginx · PHP 7.4 · MariaDB 10.5 · Let’s Encrypt · Moodle 3.10

*Install Nginx*

Install Nginx web server.

[INPUT]

1 pkg install nginx  

Aktifkan service nginx.

[INPUT]

1 sysrc nginx_enable=”YES”    

Jalankan service nginx.

[INPUT]

1 service nginx start

Browse *http://serverIP* untuk menguji apakah Nginx web server sudah berjalan dengan baik.

-Konfigurasi Server Block-

Selanjutnya mengkonfigurasi Nginx server block untuk subdomain *moodle.musaamin.my.id*.

Membuat folder untuk document root.

[INPUT]

1 2 mkdir -p /var/www/moodle.musaamin.my.id/public_html echo “hello world” > /var/www/moodle.musaamin.my.id/public_html/index.html

Membuat folder untuk menyimpan file konfigurasi server block.

[INPUT]

1 mkdir -p /usr/local/etc/nginx/vhosts

Membuat file konfigurasi server block.

[INPUT]

1 nano /usr/local/etc/nginx/vhosts/moodle.musaamin.my.id.conf  

Isi file konfigurasi server block.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 server {     listen 80;     server_name moodle.musaamin.my.id;     root /var/www/moodle.musaamin.my.id/public_html;     index index.html;       location / {             try_files $uri $uri/ =404;     }       access_log /var/log/nginx/moodle.musaamin.my.id_access.log;     error_log /var/log/nginx/moodle.musaamin.my.id_error.log; }

Buka file konfigurasi Nginx.

[INPUT]

1 nano /usr/local/etc/nginx/nginx.conf

Tambahkan konfigurasi di bawah ini sebelum penutup http.

[INPUT]

1 2 3 4 http {     …     include /usr/local/etc/nginx/vhosts/*.conf; }

Cek apakah ada kesalahan konfigurasi.

[INPUT]

1 nginx -t    

Jika tidak ada kesalahan.

[INPUT]

1 2 nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful    

Restart service nginx.

[INPUT]

1 service nginx restart  

Browse *http://moodle.musaamin.my.id*.

*Install PHP*

Install PHP 7.4 dan extensionnya.

[INPUT]

1 pkg install php74-curl php74-ctype php74-dom php74-fileinfo php74-filter php74-gd php74-iconv php74-intl php74-json php74-mbstring php74-opcache php74-openssl php74-session php74-simplexml php74-soap php74-tokenizer php74-xml php74-xmlreader php74-xmlrpc php74-zip php74-zlib

Buka file konfigurasi PHP-FPM.

[INPUT]

1 nano /usr/local/etc/php-fpm.d/www.conf  

Aktifkan dan sesuaikan konfigurasi berikut.

[INPUT]

1 2 3 4 listen = /var/run/php74.sock listen.owner = www listen.group = www listen.mode = 0660  

Buat file *php.ini*

[INPUT]

1 2 cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini-production.default ln -s /usr/local/etc/php.ini-production /usr/local/etc/php.ini  

Buka file php.ini.

[INPUT]

1 nano /usr/local/etc/php.ini    

Opsi yang diaktifkan dan diubah.

[INPUT]

1 cgi.fix_pathinfo=  

Aktifkan dan jalankan service php-fpm.

[INPUT]

1 2 sysrc php_fpm_enable=”YES” service php-fpm start  

Konfigurasi server block untuk membaca script PHP.

[INPUT]

1 nano /usr/local/etc/nginx/vhosts/moodle.musaamin.my.id.conf    

Ubah konfigurasinya menjadi seperti di bawah ini.

[INPUT]

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 server {     listen 80;     server_name moodle.musaamin.my.id;     root /var/www/moodle.musaamin.my.id/public_html;     index index.php index.html index.htm;       location / {       try_files $uri $uri/ /index.php?$query_string;     }     location /dataroot/ {         internal;         alias /var/www/moodle.musaamin.my.id/moodledata;     }       location ~ [^/]\.php(/|$) {         fastcgi_split_path_info  ^(.+\.php)(/.+)$;         fastcgi_index            index.php;         fastcgi_pass             unix:/var/run/php74.sock;         include                  fastcgi_params;         fastcgi_param   PATH_INFO       $fastcgi_path_info;         fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;     }       access_log /var/log/nginx/moodle.musaamin.my.id_access.log;     error_log /var/log/nginx/moodle.musaamin.my.id_error.log; }  

Tes konfigurasi Nginx.

[INPUT]

1 nginx -t    

Restart nginx.

[INPUT]

1 service nginx restart  

Buat file *info.php*.

[INPUT]

1 echo “” > /var/www/moodle.musaamin.my.id/public_html/info.php

Browse *http://moodle.musaamin.my.id/info.php*

*Install SSL Let’s Encrypt*

Install certbot Let’s Encrypt untuk Nginx.

[INPUT]

1 pkg install py37-certbot-nginx  

Request SSL untuk domain moodle.musaamin.my.id.

[INPUT]

1 certbot –nginx -d moodle.musaamin.my.id

Jika berhasil, certbot mengubah file konfigurasi server block.

[INPUT]

1 nano /usr/local/etc/nginx/vhosts/moodle.musaamin.my.id.conf        

Isinya.

[INPUT]

1 2 3 4 5 6 7 …     listen 443 ssl; # managed by Certbot     ssl_certificate /usr/local/etc/letsencrypt/live/moodle.musaamin.my.id/fullchain.pem; # managed by Certbot     ssl_certificate_key /usr/local/etc/letsencrypt/live/moodle.musaamin.my.id/privkey.pem; # managed by Certbot     include /usr/local/etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot     ssl_dhparam /usr/local/etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot …

Browse *https://moodle.musaamin.my.id*.

*Install MariaDB*

Install MariaDB database.

[INPUT]

1 pkg install mariadb105-server mariadb105-client

Aktifkan dan jalankan service MariaDB.

[INPUT]

1 2 sysrc mysql_enable=”YES” service mysql-server start

Amankan instalasi MariaDB.

[INPUT]

1 mysql_secure_installation

Jawab pertanyaannya.

[INPUT]

1 2 3 4 5 6 7 Enter current password for root (enter for none): ENTER Switch to unix_socket authentication [Y/n] y Change the root password? [Y/n] y 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

Konfigurasi MariaDB.

[INPUT]

1 nano /usr/local/etc/mysql/conf.d/server.cnf    

Tambahkan konfigurasi di bawah *[mysqld]*.

[INPUT]

1 2 3 4 default_storage_engine = innodb innodb_file_per_table = 1 innodb_file_format = Barracuda innodb_large_prefix = 1    

Restart service MariaDB.

[INPUT]

1 service mysql-server restart    

Login MariaDB

[INPUT]

1 mysql

Buat database untuk Moodle.

[INPUT]

1 2 3 4 5 CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;     CREATE USER ‘moodle’@’localhost’ IDENTIFIED BY ‘rahasia’; GRANT ALL PRIVILEGES ON moodle.* TO ‘moodle’@’localhost’; FLUSH PRIVILEGES; exit

*Install Moodle*

Download Moodle.

[INPUT]

1 2 wget https://download.moodle.org/download.php/direct/stable310/moodle-latest-310.tgz tar xzvf moodle-latest-310.tgz

Hapus file index.html dan info.php yang dibuat sebelumnya.

[INPUT]

1 2 rm -f /var/www/moodle.musaamin.my.id/public_html/info.php   rm -f /var/www/moodle.musaamin.my.id/public_html/index.html

Copy isi folder moodle.

[INPUT]

1 cp -Rfv moodle/* /var/www/moodle.musaamin.my.id/public_html    

Ubah ownership.

[INPUT]

1 chown -R www:www /var/www/moodle.musaamin.my.id

Browse *https://moodle.musaamin.my.id* untuk install Moodle.

1. Language = English. Next 2. Cek Data directory = /var/www/moodle.musaamin.my.id/moodledata. Next 3. Database driver = MariaDB (native/mariadb). Next 4. Database host = 127.0.0.1, Database name = moodle, Database user = moodle, Database password = rahasia. Next 5. Konfirmasi lisensi. Continue 6. Pemeriksaan server environment. Continue 7. Instalasi. Continue 8. Masukkan New password, email. Update profile 9. Masukkan Full site name, Short name, Front page summary. Save changes

Moodle telah selesai diinstall.

/Gratis saldo $100 untuk pendaftaran akun baru di Vultr. Daftar sekarang/

Selamat mencoba 🙂

Leave a Reply

Your email address will not be published.