How to Setup Moodle using Git

 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
Update your repository index and install Apache, MySQL, Git, and the required PHP extensions: [1, 2, 3, 4, 5]
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]
  1. Open your PHP configuration file (adjust the PHP version number 8.x as needed):
    bash
    sudo nano /etc/php/8.x/apache2/php.ini
    
    Use code with caution.
  2. Find max_input_vars, uncomment it by removing the semicolon ;, and change its value to at least 5000:
    ini
    max_input_vars = 5000
    
    Use code with caution.
  3. Save and close the file (Ctrl+O, Enter, Ctrl+X), then restart Apache:
    bash
    sudo systemctl restart apache2
    
    Use code with caution.
    [1, 2, 3, 4, 5]
3. Clone Moodle via Git
Keep your Git repository organized by downloading it to /opt, which makes staging and ignoring plugin upgrades easier down the road. [1, 2]
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
Moodle needs a separate directory located outside of the public web root to securely store files and caches. [1, 2]
bash
sudo mkdir /var/moodledata
sudo chown -R www-data:www-data /var/moodledata
sudo chmod -R 777 /var/moodledata
Use code with caution.
Next, fix permissions on your public web files so Apache can read them: [1, 2, 3]
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
Log into your MySQL server to set up a dedicated environment for Moodle: [1, 2]
bash
sudo mysql -u root -p
Use code with caution.
Run the following SQL commands inside the prompt to configure a database utilizing the required character set configuration: [1, 2]
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
Open your web browser and navigate to http://your_server_ip/moodle. Follow these steps in the wizard: [1, 2]
  • 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 localhost as the host, moodle as the database name, moodleuser as 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]
Once the web installer executes its environment checks and database migrations, fill out your Administrator profile to complete your site configuration. [1, 2]
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.

Post a Comment

0 Comments