Moodle VPS template on HostAfrica
Moodle Implementation on HostAfrica
Russell
Last Update 2 months ago
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.
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.
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
| Component | Description |
| Ubuntu 24.04 | Long-term support base operating system |
| CloudPanel | Web-based server control panel for site, database, and SSL management |
| Moodle 5.1 | Latest Stable Version |
| NGINX | High-performance web server with optimized Moodle 5.1 configuration |
| PHP-FPM 8.3 | PHP version with curl, zip, gd, mbstring, xml, xmlrpc, soap, intl, mysql extensions |
| MySQL 8.4 | Database server with Moodle-optimized configuration |
| Moodle CLI | Moodle command-line interface for advanced management |
| Let's Encrypt | Free automatic SSL certificate provisioning |
| UFW Firewall | Pre-configured with secure port rules |
| Cloud-init | Automated provisioning and configuration system |

| Service | URL | Port |
| Moodle Site | https://{domain} | 443 |
| CloudPanel GUI | https://cp.{domain} | 443 |
| CloudPanel Direct | https://{server_ip}:8443 | 8443 |
| SSH Access | {server_ip} | 22 |
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 automates the complete Moodle deployment process during the first VM boot. The script:
Sets the hostname and root password
Waits for CloudPanel to be ready (30 seconds)
Creates CloudPanel admin user with provided credentials
Configures reverse proxy for CloudPanel access via custom domain
Installs SSL certificate for CloudPanel domain
Installs all required PHP 8.3 extensions (curl, zip, gd, mbstring, xml, xmlrpc, soap, intl, mysql)
Creates PHP 8.3 site for the main domain
Creates MySQL database with secure credentials
Installs SSL certificate for Moodle domain (before Moodle installation)
Downloads and extracts Moodle 5.1
Creates Moodle data directory with proper permissions
Configures optimized NGINX vhost for Moodle 5.1 with /r.php routing
Runs Moodle CLI installer with database connection
Sets correct file permissions for security
Sets up Moodle cron job
Purges Moodle caches
Total Deployment Time: 7-10 minutes from provisioning to production-ready
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.
After deployment, access your Moodle admin dashboard:
URL: https://{domain}
Click on Login
Username: admin
Password: Auto-generated (provided in provisioning confirmation)


To Edit Profile:
Top-right corner → click your name/avatar → click Profile
On the profile page, click Edit profile
Update your details (email, name, city, country, description, profile picture, password)
Scroll down → click Update Profile



Primary URL: https://cp.{domain}
Fallback URL: https://{server_ip}:8443
Username: admin (same as Moodle)
Password: Same password as Moodle

Login to Moodle
Go to Home
Click on Add a new course
Fill in course details and save

Login to CloudPanel Admin Area
Go to Settings
Ensure you create an A record for your new domain in your DNS manager, pointing to the Moodle VPS IP
Add the domain in CloudPanel and save
Your CloudPanel URL should now be the new domain

Ensure you create an A record for your new domain in your DNS manager, pointing to the Moodle VPS IP.
Login to the CloudPanel GUI
Navigate to Sites → Your Domain → Manage
Navigate to the vhost settings
Change the server_name for both ports 80 and 443 to your new domain
Click Save
At this point, the new domain should load without SSL.
Run via terminal:
Then reload nginx:
Administrators can reset both CloudPanel and Moodle passwords:
Access your server via SSH and execute password reset commands:
The server comes with UFW (Uncomplicated Firewall) pre-configured with secure rules:
| Port | Protocol | Purpose |
| 22 | TCP | SSH access |
| 80 | TCP | HTTP (redirects to HTTPS) |
| 443 | TCP/UDP | HTTPS + HTTP/3 |
| 8443 | TCP | CloudPanel interface |
Cause: Cloud-init script failed to run or SSL installation failed
Solution:
Cause: Firewall blocking ports or service not running
Solution:
Cause: Database credentials mismatch
Solution:
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
Cause: CloudPanel doesn't accept certain special characters
Solution: Use alphanumeric passwords only (A-Z, a-z, 0-9)
Cause: Incorrect ownership of Moodle files
Solution:
Cause: PHP limits not configured properly
Solution: Login to CloudPanel → Sites → click on your domain → under PHP Settings, adjust the configuration.

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
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
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
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
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
Moodle Documentation: https://docs.moodle.org/
Moodle Administrator Guide: https://docs.moodle.org/en/Admin_quick_guide
CloudPanel Documentation: Introduction | CloudPanel | Documentation
Moodle CLI Scripts: https://docs.moodle.org/en/Administration_via_command_line
NGINX Optimization: F5 Blog | NGINX
Let's Encrypt: Documentation
Moodle Forums: All courses | Moodle.org
Moodle Plugins Directory: Moodle Plugins directory | Moodle.org
