# Setting up Moodle using nginx, postgresql and php on a newly installed Ubuntu 20.04 # All commands are issued as root user, working directory is /root apt update apt install joe nginx certbot python3-certbot-nginx postgresql php-common php-fpm \ php-pgsql php-xml php-soap php-curl php-intl php-gd php-zip php-mbstring php-xmlrpc ghostscript ufw default deny incoming; ufw default allow outgoing; ufw allow OpenSSH; ufw allow 'Nginx Full'; ufw enable; mkdir -p /var/www/lms/html mkdir -p /var/www/alpha/html # Nginx configuration files joe /etc/nginx/sites-available/default # This is the content of a working configuration file, with Moodle LMS server { listen 80; listen [::]:80; root /var/www/html; index index.php index.html index.htm; server_name scischool.in; # for Moodle client_max_body_size 10m; # for PHP7.4 access location ~[^/]\.php(/|$) { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_read_timeout 600; } } ------------------------- systemctl restart nginx certbot --nginx -d scischool.in # get the TLS certificate #To test, connect to https://scischool.in/index.nginx-debian.html --------------Skip this if you have only one domain name------ #- More domain names can be added by creating config files in # /etc/nginx/sites-available and enabling them. # you may copy 'default' to new files and modify the contents. ln -s /etc/nginx/sites-available/alpha /etc/nginx/sites-enabled/ ln -s /etc/nginx/sites-available/lms /etc/nginx/sites-enabled/ systemctl restart nginx certbot --nginx -d lms.scischool.in -d alpha.scischool.in ------------------------------------------- # Configure PHP-Fast Process Manager for Moodle joe /etc/php/7.4/fpm/php.ini ----------- modify parameters ------ post_max_size = 10M upload_max_filesize = 10M max_execution_time = 600 ----------- joe /etc/php/7.4/fpm/pool.d/www.conf -------PHP Fastprocess Manager settings may set to static------------ pm = static pm.max_children = 20 to 100 depending on RAM ------------------- systemctl restart php7.4-fpm.service # Set the postgres HBA configuration to allow a connection using IP protocol joe /etc/postgresql/12/main/pg_hba.conf -------- add below # IPv4 local connections----------- host all all 127.0.0.1/32 password local all all password --------------- /etc/init.d/postgresql restart # Become the postgres user to create the moodle database and user. sudo -su postgres $ psql postgres=# create database alpha; postgres=# create user alpha password '***'; #use your own username & passwords postgres=# grant all on database alpha to alpha; postgres=# \q exit #---------- Similar records should be created for each Moodle Instance ------------- #from the home directory git clone -b MOODLE_39_STABLE git://git.moodle.org/moodle.git cp -r /root/moodle /var/www/html chmod 777 /var/www/html/moodle # change this back to 755 after the installation is over mkdir /var/www/moodledata chown www-data:www-data /var/www/moodledata To start the installation, connect browser to https://scischool.in/moodle Follow the instructions #Theme may be changed if you prefer, it's only for the looks. chmod 777 /var/www/html/moodle/theme Download and install Moove theme plugin chmod 755 /var/www/html/moodle/theme chmod 755 /var/www/html/moodle chmod 755 /var/www/moodledata --------TIPS------------ #postgres backup and restore pg_dump -Fc mydb > db.dump # Before restoring a new database and user should be created. It is # simpler to use the old names pg_restore -d newdb db.dump #Adding Swap, for low RAM machines fallocate -l 1G /swapfile chmod 600 /swapfile mkswap /swapfile swapon /swapfile Add to the following line /etc/fstab /swapfile none swap sw 0 0 sysctl vm.vfs_cache_pressure=50 sysctl vm.swappiness=10 Add the following two lines to /etc/sysctl.conf vm.swappiness=10 vm.vfs_cache_pressure=50