Updated: 28 September 2026 · Applies to: Moodle 5.2 on Ubuntu 24.04, AlmaLinux 9 and Rocky Linux 9

Ubuntu 16.04 is end of life. This guide installs Moodle 5.2 (the current release) with Apache on Ubuntu 24.04.

Requirements for Moodle 5.2

  • PHP 8.3 or newer (64-bit) with the sodium, intl, zip, gd, soap and xml extensions, and max_input_vars of at least 5000.
  • MariaDB 10.11 or newer, MySQL 8.4, or PostgreSQL 16. Ubuntu 24.04 includes MariaDB 10.11. On AlmaLinux/Rocky 9, enable a newer stream before installing: dnf module enable mariadb:10.11.
  • A server with at least 2 GB RAM for a small site.

Before you start

  • A VPS or dedicated server with a fresh Ubuntu 24.04 / Debian 12 or AlmaLinux 9 / Rocky Linux 9 installation, and root or sudo access.
  • A domain or subdomain pointing to the server (an A record), if you want HTTPS.
  • The system updated: apt update && apt upgrade or dnf upgrade.

Install Apache, MariaDB and PHP

Ubuntu 24.04 / Debian 12:

apt install apache2 mariadb-server php libapache2-mod-php php-mysql php-xml php-mbstring php-curl php-zip php-gd php-intl
systemctl enable --now apache2 mariadb

AlmaLinux 9 / Rocky Linux 9 (choose a current PHP stream first):

dnf module reset php && dnf module enable php:8.3
dnf install httpd mariadb-server php php-fpm php-mysqlnd php-xml php-mbstring php-gd php-intl php-opcache php-pecl-zip
systemctl enable --now httpd mariadb php-fpm

Secure MariaDB (set a root password or keep socket login, remove test data): mariadb-secure-installation.

Also install: apt install php-soap php-intl php-zip php-gd php-xml php-curl (Ubuntu/Debian) and restart Apache.

On AlmaLinux/Rocky, the AppStream PHP 8.3 has no sodium extension, which Moodle requires. Switch to the PHP 8.3 packages from the Remi repository:

dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
dnf module reset php && dnf module enable php:remi-8.3
dnf distro-sync 'php*'
dnf install php-sodium php-soap php-intl php-pecl-zip php-gd
systemctl restart php-fpm httpd

Set max_input_vars = 5000 in /etc/php/8.3/apache2/php.ini (Ubuntu) or /etc/php.ini (AlmaLinux/Rocky).

Create a database

mariadb -u root -p
CREATE DATABASE moodle CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'Strong-Password';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Get Moodle

cd /var/www
git clone -b MOODLE_502_STABLE --depth 1 https://github.com/moodle/moodle.git moodle
mkdir -p /var/moodledata
chown -R www-data:www-data /var/moodledata    # apache on AlmaLinux/Rocky
chmod 770 /var/moodledata

Since Moodle 5.1 the web server must serve Moodle's public folder. Keep moodledata outside the web folder.

Create the Apache site

Create /etc/apache2/sites-available/example.com.conf (Ubuntu/Debian) or /etc/httpd/conf.d/example.com.conf (AlmaLinux/Rocky):

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/moodle/public
    <Directory /var/www/moodle/public>
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Ubuntu/Debian: a2ensite example.com && a2enmod rewrite && systemctl reload apache2. AlmaLinux/Rocky: apachectl configtest && systemctl reload httpd.

Run the installer

Open http://example.com, choose the language, confirm the paths (data directory /var/moodledata), choose MariaDB (native/mariadb) and enter the database details. If the installer cannot write config.php, it shows the content for you to save manually.

Cron

Moodle needs its cron task every minute. Add it for the web server user: crontab -u www-data -e (apache on AlmaLinux/Rocky) with:

* * * * * /usr/bin/php /var/www/moodle/admin/cli/cron.php >/dev/null

Add a free SSL certificate

apt install certbot python3-certbot-apache                     # Ubuntu / Debian
dnf install epel-release && dnf install certbot python3-certbot-apache   # AlmaLinux / Rocky
certbot --apache -d example.com -d www.example.com

Certbot installs a timer that renews the certificate automatically; test it with certbot renew --dry-run.

Note: On AlmaLinux 9 / Rocky Linux 9 SELinux is on. Let Apache/Nginx write where the application needs it, for example: semanage fcontext -a -t httpd_sys_rw_content_t "/var/moodledata/storage(/.*)?" && restorecon -R /var/moodledata, and allow outgoing connections if the app calls APIs: setsebool -P httpd_can_network_connect 1.

Tip: On Ucartz cPanel hosting you can install many of these applications in a few clicks with Software › Softaculous Apps Installer, which also handles updates and backups.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket