Installing Moodle on a Ubuntu cloud server: Difference between revisions
(Webserver config file is /etc/apache2/sites-available/000-default.conf) |
Tim Bahula 2 (talk | contribs) m (→top: clean up, typos fixed: usully → usually) |
||
Line 7: | Line 7: | ||
After setting up your Linux server, you need to know 3 things: | After setting up your Linux server, you need to know 3 things: | ||
*User ( | *User (usually this will be root) | ||
*User Password | *User Password | ||
*IP address (this will be in the form of 4 groups of 3 digits, separated by a dot) | *IP address (this will be in the form of 4 groups of 3 digits, separated by a dot) |
Latest revision as of 15:10, 17 March 2022
A cloud server with a LAMP stack has many advantages. They are scalable, have high speed data connections and backup power. There is no hardware to buy and the monthly lease may be lower than the electricity consumed by a home based server but before installing a webserver, there are some things that must be configured on a VPS.
It is recommended you refer to other Moodle documents for the LAMP install as it is assumed you have done it before and have a basic understanding of the steps taken.
First, obtain your server. There are many companies that will offer one shared VCPU and 1 GB of RAM for around $5 a month, adequate for a small number of students and scalable almost without limit. All that is required is a generic Ubuntu server so there is no need for a GUI or management services as everything will be done on the command line. This has been tested on a Ubuntu 20.04 image.
After setting up your Linux server, you need to know 3 things:
- User (usually this will be root)
- User Password
- IP address (this will be in the form of 4 groups of 3 digits, separated by a dot)
Second, get a FQDN or domain name. Many companies offer this and the price can be as low as $1 a year for a .xyz suffix. You can buy your domain name and hire your VPS from different companies. There is no need for any other services from the domain provider as we already have a VPS.
You now need to link your server IP address to the FQDN. This is done under the DNS Management page on the site where you purchased the domain name. You need to set the "A record" to the IP address of your VPS. This can take a few minutes to ripple through but you should be able to browse to your FQDN soon
Using either a Windows or Linux terminal enter this command.
ssh root@mydomainname.xyz
Now you will be on the command line of your Linux VPS. Add a new user with your name.
sudo adduser user1
You will now be prompted for a password. The extra information requested can be ignored. Now give your new user sudo privileges, meaning they have admin power.
sudo usermod -aG sudo user1 su user1
quit
On your desktop terminal, log on to your remote server as user1
ssh user1@mydomainname.xyz
Now you should be logged in as user1, not as root as it is safer to access your system without using root.
Now we can create the LAMP stack by installing Apache, mysql and php. This is the cheat sheet of commands. Refer to Step by Step for a more detailed explanation, If you leave this page, don't start the web based install of Moodle until https is configured,
sudo apt update && sudo apt upgrade sudo apt install apache2 mysql-client mysql-server php libapache2-mod-php sudo service mysql restart sudo mysql_secure_installation sudo apt install graphviz aspell ghostscript clamav php7.4-pspell php7.4-curl php7.4-gd php7.4-intl php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-ldap php7.4-zip php7.4-soap php7.4-mbstring sudo service apache2 restart cd /opt sudo git clone git://git.moodle.org/moodle.git cd moodle sudo git branch -a sudo git branch --track MOODLE_311_STABLE origin/MOODLE_311_STABLE sudo git checkout MOODLE_311_STABLE sudo cp -R /opt/moodle /var/www/html/ sudo mkdir /var/moodledata sudo chown -R www-data /var/moodledata sudo chmod -R 777 /var/moodledata sudo mysql -u root -p
mysql> CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; mysql> create user 'moodledude'@'localhost' IDENTIFIED BY 'passwordformoodledude'; mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'moodledude'@'localhost'; mysql> quit;
Once the LAMP is complete, we can set up the firewall.
sudo ufw allow 22/tcp sudo ufw enable sudo ufw default deny incoming sudo ufw default allow outgoing sudo ufw allow www sudo ufw allow 'Apache Full' sudo ufw status Status: active To Action From -- ------ ---- 22/tcp ALLOW Anywhere 80/tcp ALLOW Anywhere Apache Full ALLOW Anywhere 22/tcp (v6) ALLOW Anywhere (v6) 80/tcp (v6) ALLOW Anywhere (v6) Apache Full (v6) ALLOW Anywhere (v6)
On a browser, check the Ubuntu Apache page appears at http://mydomainname.xyz HMy preference is to have my Moodle page open at this domin name so edit my sites-available file.
sudo nano /etc/apache2/sites-available/000-default.conf
Now set the document root to /var/www/html/moodle to have Moodle at www.mydomainname.xyz
ServerAdmin webmaster@mydomainname.xyz ServerName mydomainname.xyz ServerAlias www.mydomainname.xyz DocumentRoot /var/www/html/moodle ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined
We really need a https connection to safeguard data. It is also required for some Moodle functions such as recording audio. To set the connection to https:
sudo apt install snapd sudo snap install core; sudo snap refresh core sudo snap install --classic certbot sudo ln -s /snap/bin/certbot /usr/bin/certbot sudo certbot --apache
You should
- Enter your email (certicates may need renewal)
- Register the account
- Please enter the domain name(s) you would like on your certificate (comma and/or
space separated)
- Optional to share your email address with the Electronic Frontier Foundation
This will create
- a new Certificate: /etc/apache2/sites-available/mydomainname-le-ssl.conf
- a new available site: /etc/apache2/sites-available/mydomainname-le-ssl.conf
If you go to your domain, it now redirects to https://mydomainname.xyz and there is a padlock on the brower bar.
Now go to https://mydomainname on your browser and finish the install. Don't forget to set up cron
sudo crontab -u www-data -e * * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php >/dev/null
Enhancements
Swap space can improve performance.
Create 1G swap space (or same size as your RAM)
sudo fallocate -l 1G /swapfile sudo chmod 600 /swapfile sudo mkswap /swapfile sudo swapon /swapfile sudo swapon --show You should see 1024 Mb of Swap file. Edit the fstab table by adding this line to make it permanent. sudo nano /etc/fstab /swapfile swap swap defaults 0 0
Using a password to log in each time is neither convenient not secure. Close your VPS and go back to your desktop terminal. The user name must be the same on both machines. Enter
ssh-keygen -t rsa
Accept the file location suggested. On my Linux system it is /home/jimmy/.ssh/id_rsa.pub Push enter when a passphrase is suggested as it is not necessary. It will then create a random image and a 256SHA fingerprint. Enter
ssh-copy-id -i ~/.ssh/id_rsa.pub mydomainname.xyz
Now create a config file.
sudo nano ~/.ssh/config Host myserver HostName mydomainname.xyz Port 22 User user1 IdentityFile ~/.ssh/id_rsa
Now log in to your VPS with
ssh myserver
Virtual Hosts
It is possible to have multiple domains on one VPS. For example, you could have www.mymooodle.xyz and www.myblog.xyz running on the same machine using Apache Virtual Hosts.