Moodle VPS template on HostAfrica

Moodle Implementation on HostAfrica

Russell

Last Update 2 months ago

What is Self-Hosted Moodle:

Self-Hosted Moodle gives you complete control of your Learning Management System on a dedicated VPS environment. Unlike shared hosting, your Moodle site runs on isolated resources with a dedicated IP for improved performance, security, and reliability. With full root access, you can customize your server, install additional plugins and themes, integrate third-party tools, and scale as needed—perfect for educational institutions, corporate training departments, and anyone who wants a powerful, flexible LMS setup.

Example Use Case

Educational Institutions: Run complete online learning platforms for schools, colleges, and universities with full control over student data, course content, and assessment systems.

Corporate Training: Host internal training programs, compliance courses, and professional development with dedicated resources ensuring secure access and reliable performance.

Online Course Platforms: Create and sell online courses with Moodle's powerful course management, enrollment systems, and payment gateway integrations.

Blended Learning Programs: Combine traditional classroom teaching with online resources, assignments, and assessments in a unified platform.

Professional Certification: Deliver certification programs with advanced quiz systems, completion tracking, and automated certificate generation.

K-12 Virtual Schools: Manage complete virtual school environments with parent portals, grade books, and student progress tracking.

Implementation Details:

Our Self-Hosted Moodle implementation includes CloudPanel, a modern server control panel that makes managing Moodle simple and efficient. The setup provides:

  • Dual Admin Interfaces: CloudPanel for server management (cp.yourdomain.com) and Moodle admin for content management (yourdomain.com)

  • Automatic SSL: Let's Encrypt certificates automatically installed and renewed for both domains

  • Moodle CLI Integration: Command-line tools for advanced Moodle management

  • Single Sign-On: One set of credentials (admin username) for both CloudPanel and Moodle

  • Automated Deployment: Complete setup in 5-7 minutes via Cloud-init automation

  • Pre-configured PHP: All required PHP extensions installed and configured

Software Components:
ComponentDescription
Ubuntu 24.04Long-term support base operating system
CloudPanelWeb-based server control panel for site, database, and SSL management
Moodle 5.1Latest Stable Version
NGINXHigh-performance web server with optimized Moodle 5.1 configuration
PHP-FPM 8.3PHP version with curl, zip, gd, mbstring, xml, xmlrpc, soap, intl, mysql extensions
MySQL 8.4Database server with Moodle-optimized configuration
Moodle CLIMoodle command-line interface for advanced management
Let's EncryptFree automatic SSL certificate provisioning
UFW FirewallPre-configured with secure port rules
Cloud-initAutomated provisioning and configuration system
Moodle 5.1 Directory Structure
Moodle 5.1 introduces a new directory structure with a public subdirectory for enhanced security:
Service Endpoints
ServiceURLPort
Moodle Sitehttps://{domain}443
CloudPanel GUIhttps://cp.{domain}443
CloudPanel Directhttps://{server_ip}:84438443
SSH Access{server_ip}22
Default Configuration
  • Admin Username: admin (used for both CloudPanel and Moodle)

  • Admin Password: Auto-generated 16-character alphanumeric password

  • Database Name: moodle

  • Database User: moodle

  • Database Password: Auto-generated during deployment

  • PHP Version: 8.3

  • PHP Memory Limit: 512M

  • Max Upload Size: 64M

  • Max Execution Time: 300 seconds

  • CloudPanel Domain: cp.{domain}

Cloud-init Functionality

Cloud-init automates the complete Moodle deployment process during the first VM boot. The script:

  1. Sets the hostname and root password

  2. Waits for CloudPanel to be ready (30 seconds)

  3. Creates CloudPanel admin user with provided credentials

  4. Configures reverse proxy for CloudPanel access via custom domain

  5. Installs SSL certificate for CloudPanel domain

  6. Installs all required PHP 8.3 extensions (curl, zip, gd, mbstring, xml, xmlrpc, soap, intl, mysql)

  7. Creates PHP 8.3 site for the main domain

  8. Creates MySQL database with secure credentials

  9. Installs SSL certificate for Moodle domain (before Moodle installation)

  10. Downloads and extracts Moodle 5.1

  11. Creates Moodle data directory with proper permissions

  12. Configures optimized NGINX vhost for Moodle 5.1 with /r.php routing

  13. Runs Moodle CLI installer with database connection

  14. Sets correct file permissions for security

  15. Sets up Moodle cron job

  16. Purges Moodle caches

Total Deployment Time: 7-10 minutes from provisioning to production-ready

Why CloudPanel Reverse Proxy

The CloudPanel reverse proxy is created to allow access to the CloudPanel web interface via a custom domain name (cp.yourdomain.com) instead of the default IP address and port (https://server-ip:8443). This makes it easier for users to remember and access the panel.

Additionally, the reverse proxy handles SSL termination, allowing secure HTTPS connections with a valid SSL certificate (via Let's Encrypt), without requiring CloudPanel itself to manage certificates directly. It also provides flexibility for managing traffic, improving security, and allowing CloudPanel to coexist with other services on the same server.

How To Access Moodle & CloudPanel
Moodle Admin Access

After deployment, access your Moodle admin dashboard:

  1. URL: https://{domain}

  2. Click on Login

  3. Username: admin

  4. Password: Auto-generated (provided in provisioning confirmation)

To Edit Profile:

  1. Top-right corner → click your name/avatar → click Profile

  2. On the profile page, click Edit profile

  3. Update your details (email, name, city, country, description, profile picture, password)

  4. Scroll down → click Update Profile

CloudPanel Access
Note: Both CloudPanel and Moodle use the same login credentials for simplicity.
How to Create a Course
  1. Login to Moodle

  2. Go to Home

  3. Click on Add a new course

  4. Fill in course details and save

How To Change CloudPanel Custom Domain
  1. Login to CloudPanel Admin Area

  2. Go to Settings

  3. Ensure you create an A record for your new domain in your DNS manager, pointing to the Moodle VPS IP

  4. Add the domain in CloudPanel and save

  5. Your CloudPanel URL should now be the new domain

How To Change Moodle Site Domain/URL
Step 1: Update DNS

Ensure you create an A record for your new domain in your DNS manager, pointing to the Moodle VPS IP.

Step 2: Update NGINX Configuration
  1. Login to the CloudPanel GUI

  2. Navigate to Sites → Your Domain → Manage

  3. Navigate to the vhost settings

  4. Change the server_name for both ports 80 and 443 to your new domain

  5. Click Save

At this point, the new domain should load without SSL.

Step 3: Install SSL for the New Domain

Run via terminal:

Then reload nginx:

Step 4: Update Moodle URLs via CLI
Replace {OLD_DOMAIN} and {NEW_DOMAIN} with your actual domains:
Step 5: Clear Moodle Cache
Step 6: Verify
Password Management
Password Reset (Admin)

Administrators can reset both CloudPanel and Moodle passwords:

Access your server via SSH and execute password reset commands:

Note: Passwords must be alphanumeric only (A-Z, a-z, 0-9) for CloudPanel - no special characters. Moodle accepts special characters but for consistency, use alphanumeric.
Firewall Configuration

The server comes with UFW (Uncomplicated Firewall) pre-configured with secure rules:

PortProtocolPurpose
22TCPSSH access
80TCPHTTP (redirects to HTTPS)
443TCP/UDPHTTPS + HTTP/3
8443TCPCloudPanel interface
Troubleshooting
1. Domain Not Accessible (ERR_SSL_PROTOCOL_ERROR)

Cause: Cloud-init script failed to run or SSL installation failed

Solution:

2. CloudPanel Not Accessible

Cause: Firewall blocking ports or service not running


Solution:

3. Moodle Shows Database Connection Error

Cause: Database credentials mismatch

Solution:

4. SSL Certificate Installation Failed

Cause: DNS records not propagated or ports 80/443 blocked


Solution:

  • Verify DNS A record points to server IP

  • Check ports are open: ufw status

  • Wait 5-10 minutes for DNS propagation

  • Retry SSL installation via CloudPanel

5. Password Contains Special Characters Not Accepted

Cause: CloudPanel doesn't accept certain special characters


Solution: Use alphanumeric passwords only (A-Z, a-z, 0-9)

6. File Permission Issues

Cause: Incorrect ownership of Moodle files

Solution:

7. Upload Size Too Small

Cause: PHP limits not configured properly

Solution: Login to CloudPanel → Sites → click on your domain → under PHP Settings, adjust the configuration.

8. Slow Performance

Cause: Cache not configured or insufficient resources

Solution:

  • Enable Moodle caching in Site Administration → Plugins → Caching

  • Install Redis or Memcached for improved performance

  • Check system resources: htop

  • Optimize MySQL: mysqltuner

9. Moodle Styles Not Loading (Moodle 5.1 Specific)

Cause: NGINX not configured for Moodle 5.1's new directory structure


Solution: Ensure NGINX configuration has:

  • root pointing to /home/moodle/htdocs/{domain}/moodle/public

  • try_files $uri $uri/ /r.php; for the Moodle 5.1 router

Best Practices
Security
  • Change default admin username after first login

  • Use strong alphanumeric passwords (16+ characters)

  • Keep Moodle core, themes, and plugins updated regularly

  • Install a security plugin or enable Moodle's built-in security features

  • Enable two-factor authentication for admin accounts

  • Regular database backups via CloudPanel

  • Restrict file upload types in Moodle settings

  • Review user roles and permissions regularly

  • Monitor failed login attempts

  • Keep PHP and system packages updated

Performance
  • Enable Moodle caching (File cache, Redis, or Memcached)

  • Use a CDN for static assets (themes, images)

  • Optimize images before uploading

  • Remove unused themes and plugins

  • Enable NGINX caching for static files

  • Configure Moodle session handling properly

  • Set up cron to run every minute (configured automatically)

  • Monitor disk space for moodledata directory

  • Use database query optimization

  • Consider external database server for large deployments

Maintenance
  • Schedule regular backups (daily recommended)

  • Monitor disk space usage (especially moodledata directory)

  • Review CloudPanel logs periodically

  • Test updates on staging environment before production

  • Keep SSH keys secure and rotate regularly

  • Document any custom configurations

  • Monitor server resources (CPU, RAM, disk I/O)

  • Set up email notifications for system alerts

  • Regularly review and clean up old course backups

  • Archive old courses to free up resources

Additional Resources

Was this article helpful?

0 out of 0 liked this article

Still need help? Message Us