CentOSRHEL Based

How To Install Moodle on CentOS Stream 10

Install Moodle on CentOS Stream 10

In this tutorial, we will show you how to install Moodle on CentOS Stream 10. Moodle stands as one of the most powerful and widely-adopted open-source learning management systems (LMS) available today. Organizations worldwide rely on this robust platform to deliver comprehensive online education experiences. CentOS Stream 10, with its enterprise-grade stability and security features, provides an ideal foundation for hosting Moodle installations that can scale from small educational institutions to large corporate training environments.

This comprehensive guide will walk you through every step of installing Moodle on CentOS Stream 10, from initial system preparation to final configuration. Whether you’re a system administrator setting up your first Moodle instance or an experienced Linux professional looking for best practices, this tutorial provides detailed instructions that ensure a successful deployment.

System Requirements and Prerequisites

Before beginning the installation process, understanding the system requirements ensures optimal performance and prevents common installation issues.

Hardware Requirements

Moodle’s hardware requirements vary significantly based on expected user load and content complexity. For a basic installation supporting up to 50 concurrent users, a minimum of 2GB RAM is recommended, though 4GB or more provides better performance margins. The processor should be at least a dual-core 2GHz CPU, with quad-core processors recommended for production environments expecting higher user loads.

Storage requirements extend beyond the basic Moodle installation files. While the core Moodle application requires approximately 200MB of disk space, you’ll need additional storage for user-uploaded content, course materials, and system logs. Plan for at least 10GB of available storage for small installations, with larger deployments requiring substantially more space based on anticipated content volume.

Software Dependencies

The LAMP stack (Linux, Apache, MariaDB, PHP) forms the foundation of your Moodle installation. CentOS Stream 10 requires PHP 8.0 or higher for optimal Moodle compatibility, with PHP 8.1 or 8.2 recommended for the latest Moodle versions. Essential PHP extensions include mbstring, xml, json, curl, zip, gd, and intl, which handle various Moodle functionality from internationalization to file processing.

Database compatibility is crucial for long-term stability. MariaDB 10.4 or higher, MySQL 8.0+, or PostgreSQL 13+ all provide excellent compatibility with current Moodle versions. MariaDB is often preferred on CentOS systems due to its seamless integration and performance characteristics.

Preparing CentOS Stream 10 Environment

System preparation involves updating packages, configuring security settings, and installing core components that support Moodle’s operation.

System Updates and Security Configuration

Begin by ensuring your CentOS Stream 10 system has the latest security updates and package versions:

sudo dnf update -y
sudo dnf install -y epel-release

Firewall configuration requires opening ports 80 (HTTP) and 443 (HTTPS) for web traffic. Configure firewalld to allow these connections:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

SELinux configuration requires careful attention to prevent permission conflicts while maintaining security. Set appropriate SELinux contexts for web directories:

sudo setsebool -P httpd_can_network_connect 1
sudo setsebool -P httpd_can_sendmail 1

Installing Core Components

Install Apache web server and configure it for optimal Moodle performance:

sudo dnf install -y httpd
sudo systemctl enable httpd
sudo systemctl start httpd

Install MariaDB database server and secure the installation:

sudo dnf install -y mariadb-server mariadb
sudo systemctl enable mariadb
sudo systemctl start mariadb
sudo mysql_secure_installation

PHP installation requires specific modules for Moodle functionality:

sudo dnf install -y php php-mysqlnd php-xml php-json php-mbstring php-zip php-gd php-curl php-intl php-soap php-xmlrpc php-opcache

Verify installations by checking service status:

sudo systemctl status httpd mariadb
php -v

Database Configuration

Database setup involves creating a dedicated Moodle database and user with appropriate permissions for security and functionality.

MariaDB Setup and Security

Access the MariaDB console as root and create the Moodle database structure:

sudo mysql -u root -p

CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'moodleuser'@'localhost' IDENTIFIED BY 'StrongPassword123!';
GRANT ALL PRIVILEGES ON moodle.* TO 'moodleuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

The utf8mb4 character set ensures full Unicode support, including emojis and international characters that users might include in course content.

Database Optimization

Configure MariaDB for optimal Moodle performance by editing /etc/mysql/mariadb.conf.d/50-server.cnf:

[mysqld]
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
max_connections = 200
query_cache_type = 1
query_cache_size = 64M

Restart MariaDB to apply configuration changes:

sudo systemctl restart mariadb

Test database connectivity using the credentials created earlier to ensure proper access before proceeding with Moodle installation.

Downloading and Installing Moodle

Obtaining Moodle files from official sources ensures you receive the latest stable release with all security updates.

Obtaining Moodle Files

Download the latest stable Moodle release directly from the official repository:

cd /tmp
wget https://download.moodle.org/download.php/stable500/moodle-5.0.tgz
tar -xzf moodle-5.0.tgz
sudo mv moodle /var/www/html/

Verify the download integrity by checking file sizes and comparing with official documentation. The extracted Moodle directory should contain standard subdirectories including admin, course, lib, and theme.

File System Configuration

Create the Moodle data directory outside the web root for security:

sudo mkdir /var/www/moodledata
sudo chown apache:apache /var/www/html/moodle
sudo chown apache:apache /var/www/moodledata
sudo chmod -R 755 /var/www/html/moodle
sudo chmod -R 755 /var/www/moodledata

The data directory must remain outside the web-accessible path to prevent direct access to uploaded files and temporary data. This configuration prevents serious security vulnerabilities while allowing Moodle proper file access.

Set SELinux contexts for web directories:

sudo setsebool -P httpd_can_network_connect_db 1
sudo semanage fcontext -a -t httpd_exec_t "/var/www/html/moodle(/.*)?"
sudo restorecon -R /var/www/html/moodle

Web Server Configuration

Apache virtual host configuration ensures proper request handling and SSL implementation for secure Moodle access.

Apache Virtual Host Setup

Create a dedicated virtual host configuration file for Moodle at /etc/httpd/conf.d/moodle.conf:

<VirtualHost *:80>
    ServerName your-domain.com
    DocumentRoot /var/www/html/moodle
    
    <Directory /var/www/html/moodle>
        Options -Indexes
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog /var/log/httpd/moodle_error.log
    CustomLog /var/log/httpd/moodle_access.log combined
</VirtualHost>

Enable necessary Apache modules:

sudo a2enmod rewrite ssl
sudo systemctl restart httpd

PHP Configuration Optimization

Edit /etc/php.ini to optimize PHP settings for Moodle requirements:

memory_limit = 256M
post_max_size = 64M
upload_max_filesize = 64M
max_execution_time = 300
max_input_vars = 5000
session.save_handler = files
session.auto_start = 0

These settings accommodate larger file uploads and longer processing times common in educational environments. Restart Apache to apply PHP configuration changes:

sudo systemctl restart httpd

Moodle Installation Process

Moodle offers both web-based and command-line installation methods, each with specific advantages for different deployment scenarios.

Web-Based Installation

Navigate to your server’s IP address or domain name in a web browser to access the Moodle installation wizard. The installer will guide you through several configuration screens:

  1. Language Selection: Choose your preferred installation language
  2. Path Confirmation: Verify web and data directory paths
  3. Database Configuration: Enter the database connection details created earlier
  4. Environment Check: Review system requirements and resolve any missing dependencies
  5. Administrator Account: Create the primary site administrator account

Install Moodle on CentOS Stream 10

During database configuration, use these settings:

  • Database host: localhost
  • Database name: moodle
  • Database user: moodleuser
  • Database password: [Your chosen password]

The installation process creates necessary database tables and configures initial site settings. This process may take several minutes depending on server performance.

Install Moodle on CentOS Stream 10

Command-Line Installation Alternative

For automated deployments or server environments without web access, use Moodle’s CLI installer:

sudo -u apache php /var/www/html/moodle/admin/cli/install.php \
    --lang=en \
    --wwwroot=http://your-domain.com \
    --dataroot=/var/www/moodledata \
    --dbtype=mariadb \
    --dbhost=localhost \
    --dbname=moodle \
    --dbuser=moodleuser \
    --dbpass=YourPassword \
    --fullname="Your Site Name" \
    --shortname="YourSite" \
    --adminuser=admin \
    --adminpass=AdminPassword \
    --adminemail=admin@your-domain.com \
    --non-interactive \
    --agree-license

The CLI installation method provides better control for scripted deployments and production environments where consistency across multiple installations is required.

Post-Installation Configuration

Completing the installation involves security hardening, performance optimization, and establishing maintenance procedures.

Security Hardening

Configure SSL/TLS encryption by obtaining and installing SSL certificates. For testing environments, create self-signed certificates:

sudo openssl req -new -x509 -days 365 -nodes -out /etc/ssl/certs/moodle.crt -keyout /etc/ssl/private/moodle.key

Update the Apache virtual host configuration to include SSL settings and redirect HTTP traffic to HTTPS for enhanced security.

Implement regular security updates by configuring automatic notifications for Moodle releases. Set appropriate file permissions to prevent unauthorized access while maintaining functionality:

sudo find /var/www/html/moodle -type d -exec chmod 755 {} \;
sudo find /var/www/html/moodle -type f -exec chmod 644 {} \;

Performance Optimization

Enable PHP OPCache for improved performance by adding these settings to /etc/php.ini:

opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=10000
opcache.revalidate_freq=2

Configure Moodle caching through the administration interface. Navigate to Site Administration > Server > Caching and enable appropriate cache stores based on your server configuration. File-based caching works well for smaller installations, while Redis or Memcached provide better performance for larger deployments.

Set up automated maintenance by creating a cron job for the Moodle maintenance script:

sudo crontab -u apache -e

Add this line to run Moodle maintenance every minute:

* * * * * /usr/bin/php /var/www/html/moodle/admin/cli/cron.php

Troubleshooting Common Issues

Understanding common installation problems and their solutions helps ensure smooth deployment and ongoing operation.

Installation Problems

Database connection errors often result from incorrect credentials or MariaDB access permissions. Verify database connectivity independently:

mysql -u moodleuser -p -h localhost moodle

File permission issues prevent Moodle from writing to necessary directories. Ensure the Apache user has appropriate access to both the Moodle installation and data directories. SELinux conflicts may require additional context configuration or temporary enforcement disabling during installation.

PHP extension conflicts typically generate clear error messages during the environment check phase. Install missing extensions using dnf and restart Apache to resolve these issues.

Performance Issues

Memory limit problems manifest as blank pages or timeout errors. Increase PHP memory limits and monitor Apache process memory usage to identify optimal settings. Database optimization becomes crucial as content volume grows, requiring regular table optimization and index maintenance.

Apache tuning for concurrent users involves adjusting MaxRequestWorkers and other MPM settings based on available system memory and expected load patterns. Monitor server logs to identify performance bottlenecks and adjust configurations accordingly.

Best Practices and Maintenance

Establishing proper maintenance procedures ensures long-term stability and security for your Moodle installation.

Security Best Practices

Implement regular backup procedures for both database content and file uploads. Create automated backup scripts that store data in secure, off-site locations. Test backup restoration procedures periodically to ensure data recovery capabilities.

User access management requires ongoing attention to prevent unauthorized access while maintaining usability. Implement strong password policies and consider two-factor authentication for administrator accounts. Regular security audits help identify potential vulnerabilities before they become problems.

Monitor system logs for suspicious activity and implement intrusion detection systems for production environments. Keep detailed documentation of configuration changes and maintenance procedures for consistency across team members.

Ongoing Maintenance

Update procedures should include both Moodle application updates and underlying system security patches. Test updates in staging environments before applying to production systems. Maintain compatibility between Moodle versions and PHP/database versions to prevent functionality issues.

Performance monitoring involves tracking database query performance, Apache response times, and overall system resource utilization. Establish baseline performance metrics and monitor trends to identify capacity planning needs.

User management and capacity planning require ongoing assessment of storage usage, concurrent user patterns, and feature utilization. Scale resources proactively based on growth trends rather than reactive performance problems.

Congratulations! You have successfully installed Moodle. Thanks for using this tutorial for installing Moodle Learning Platform or course management system on CentOS Stream 10 system. For additional help or useful information, we recommend you check the official Moodle website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button