To set up Moodle on Ubuntu using Git, install the LAMP stack, clone the official Moodle Git repository, configure your database, and run the built-in installer. [1, 2, 3, 4, 5]
Using Git allows you to seamlessly track stable branches and upgrade Moodle core code later with a simple
git pull command. [1, 2]1. Install System Dependencies
bash
sudo apt update && sudo apt upgrade -y
sudo apt install -y apache2 git mysql-server graphviz aspell ghostscript clamav
sudo apt install -y php php-cli php-fpm php-mysql php-zip php-gd php-xml php-intl php-mbstring php-curl php-soap php-bcmath php-xmlrpc
Use code with caution.
2. Configure PHP Settings
Moodle requires a higher input variables limit than the standard PHP default. [1]
- Open your PHP configuration file (adjust the PHP version number
8.xas needed):bashsudo nano /etc/php/8.x/apache2/php.iniUse code with caution. - Find
max_input_vars, uncomment it by removing the semicolon;, and change its value to at least5000:inimax_input_vars = 5000Use code with caution. - Save and close the file (
Ctrl+O,Enter,Ctrl+X), then restart Apache:[1, 2, 3, 4, 5]bashsudo systemctl restart apache2Use code with caution.
3. Clone Moodle via Git
bash
# Navigate to the opt directory and clone Moodle
cd /opt
sudo git clone git://git.moodle.org/moodle.git
cd moodle
# List all available branches
sudo git branch -a
# Track and check out your desired stable branch (e.g., MOODLE_405_STABLE)
sudo git branch --track MOODLE_405_STABLE origin/MOODLE_405_STABLE
sudo git checkout MOODLE_405_STABLE
# Copy the repository code to your web server root directory
sudo cp -R /opt/moodle /var/www/html/
Use code with caution.
4. Create the Moodle Data Directory
bash
sudo mkdir /var/moodledata
sudo chown -R www-data:www-data /var/moodledata
sudo chmod -R 777 /var/moodledata
Use code with caution.
bash
sudo chown -R www-data:www-data /var/www/html/moodle
sudo chmod -R 0755 /var/www/html/moodle
Use code with caution.
5. Create the MySQL Database
bash
sudo mysql -u root -p
Use code with caution.
sql
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'YourSecurePasswordHere';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Use code with caution.
6. Finish the Web Installation
- Confirm Paths: Ensure the Web Address matches your URL, the Moodle Directory is
/var/www/html/moodle, and the Data Directory points to/var/moodledata. - Database Driver: Select Improved MySQL (
mysqli). - Database Settings: Enter
localhostas the host,moodleas the database name,moodleuseras the user, and the secure password you generated in Step 5. - Save config.php: If Moodle cannot automatically write to your directory, copy the text block provided on screen, create the file manually via
sudo nano /var/www/html/moodle/config.php, paste it inside, and save. [1, 2, 3, 4, 5]
If you want to make sure your background tasks run properly, let me know if you would like help setting up the Moodle system cron job.
0 Comments