How to install Moodle in Ubuntu July 2026

 https://www.youtube.com/watch?v=O4BU14qbTag&t=257s

sudo apt update

sudo apt install -y mysql-client mysql-server apache2 php php-mysql php-mbstring php-xml php-curl php-zip php-gd php-intl php-soap

Go to Moodle.org then Downloads

Go to Other releases supported: https://download.moodle.org/releases/supported/

Download the TGZ

Copy the link using click here to download manually

wget https://download.moodle.org/download.php/direct/stable501/moodle-latest-501.tgz

sudo mv moodle-latest-501.tgz /var/www/html/

tar -xf moodle-latest-501.tgz

ls

ip a


Update Web Server Root:

  • If using Apache / cPanel: Update the DocumentRoot directive in your Apache configuration file or .htaccess so it points to the /public directory (e.g., /var/www/html/moodle/public)
If Using Apache (VPS or Dedicated Server)
You need to update the VirtualHost configuration file via SSH.
  1. Open your config file: Locate your site's configuration file (usually found in /etc/apache2/sites-available/ on Ubuntu/Debian or /etc/httpd/conf.d/ on CentOS/RHEL).
  2. Edit the DocumentRoot: Find the DocumentRoot directive and update it to point to the public folder.
    apache
    <VirtualHost *:80>
        ServerName yourdomain.com
        DocumentRoot /var/www/html/moodle/public
    
        <Directory /var/www/html/moodle/public>
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    
    Use code with caution.
  3. Restart Apache: Save the file and run sudo systemctl restart apache2 (Ubuntu) or sudo systemctl restart httpd (CentOS) to apply the changes. [1, 2, 3, 4, 5]
To help you map this out correctly, could you tell me:
  • Are you on a VPS/Dedicated server or Shared cPanel hosting?
  • Is this for your primary domain or a subdomain?
  • What CMS or framework (like Moodle) are you configuring


<?php  // Moodle configuration file

unset($CFG);
global $CFG;

$CFG = new stdClass();

// 1. DATABASE SETUP
$CFG->dbtype    = 'mysqli';       // options: 'mysqli', 'mariadb', 'pgsql', 'sqlsrv', 'oci'
$CFG->dblibrary = 'native';       // 'native' is required
$CFG->dbhost    = 'localhost';    // database server hostname or IP address
$CFG->dbname    = 'moodle_db';    // name of your Moodle database
$CFG->dbuser    = 'moodle_user';  // database username
$CFG->dbpass    = 'secure_password_here'; // database user password
$CFG->prefix    = 'mdl_';         // prefix for database tables
$CFG->dboptions = array (
  'dbpersist' => 0,
  'dbport' => '',
  'dbsocket' => '',
  'dbcollation' => 'utf8mb4_unicode_ci', // recommended collation for MySQL/MariaDB
);

// 2. WEB ROOT URL
// Must be an exact, fixed public URL. Do not use dynamic PHP server hooks here.
$CFG->wwwroot   = 'https://yourmoodle.com'; 

// 3. FILE SYSTEM PATHS
// Path to the primary Moodle web directory
$CFG->dirroot   = '/var/www/html/moodle'; 

// Path to data files. MUST be outside the public web server directory.
$CFG->dataroot  = '/var/moodledata'; 

// 4. SITE PERMISSIONS & CACHING
$CFG->directorypermissions = 0777;

// 5. EXECUTE MOODLE CORE SETUP
// Crucial: No trailing white spaces or line breaks are allowed after the final internal code logic.
require_once(__DIR__ . '/lib/setup.php');

To remove a current Moodle installation from Ubuntu completely, you need to delete three main components: the Moodle code directory, the Moodle data directory, and the database. [1, 2]
Here is how to do it in 4 simple steps:
1. Back up your site
If you need to keep your courses, take a backup of your moodledata folder and use mysqldump to export your database before deleting anything.
2. Remove the Moodle code folder
Navigate to where your Moodle code was installed (usually in /var/www/html/ or /opt/) and delete the folder: [1, 2]
bash
sudo rm -rf /var/www/html/moodle
Use code with caution.
3. Remove the Moodle data folder
Delete the separate moodledata directory where all your uploaded files, caches, and sessions are stored: [1, 2, 3]
bash
sudo rm -rf /var/moodledata
Use code with caution.
(Note: Your folder might be named differently, e.g., /var/www/moodledata. Adjust the path accordingly.) [1, 2]
4. Delete the database
Drop the database and database user associated with your Moodle installation: [1, 2]
  1. Log into MySQL/MariaDB:
    bash
    sudo mysql -u root -p
    
    Use code with caution.
  2. Run the following commands (replace moodle_db and moodle_user with your actual database and user names):
    sql
    DROP DATABASE moodle_db;
    DROP USER 'moodle_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
    
    Use code with caution.
    [1, 2, 3]

Post a Comment

0 Comments