Automated Moodle update script with comprehensive backup, security checks, and maintenance mode handling.
- Automated Updates: Download and install any Moodle version from GitHub releases
- Smart Backup System: Automatic backup of code, database, and critical data
- PHP Compatibility: Automatic PHP version checking and upgrade support
- Version Validation: Prevents downgrades and validates target versions
- Maintenance Mode: Automatic maintenance mode during updates
- Database Support: MySQL, MariaDB, and PostgreSQL backup support
- Security Focused: Proper permissions and security hardening
- Progress Tracking: Real-time progress with colored output
- Web Server Integration: Automatic web server restart after updates
- Operating System: Ubuntu/Debian (preferred), CentOS/RHEL compatible
- Privileges: Root access (sudo) required
- PHP: Version 7.4+ (script can auto-upgrade)
- Database: MySQL/MariaDB or PostgreSQL
- Web Server: Apache2 or Nginx
- Tools: curl, tar, sed, grep, systemctl
# Download directly from GitHub
curl -o updater.sh https://raw.githubusercontent.com/EverHype-Systems/moodle-update/main/updater.sh
chmod +x updater.sh# Clone the repository
git clone https://github.com/EverHype-Systems/moodle-update.git
cd moodle-update
chmod +x updater.sh# Check script integrity
sha256sum updater.sh
# Compare with hash from GitHub releases# Interactive mode - will prompt for version
sudo ./updater.sh /var/www/html/moodle /var/www/moodledata
# Specify target version
sudo ./updater.sh /var/www/html/moodle /var/www/moodledata 5.0.1
# Update to latest available version
sudo ./updater.sh /var/www/html/moodle /var/www/moodledata latestStandard Moodle Installation:
sudo ./updater.sh /var/www/html/moodle /var/www/moodledataCustom Paths:
sudo ./updater.sh /opt/moodle /opt/moodledata 4.4.2Development/Testing Environment:
sudo ./updater.sh /home/user/moodle /home/user/moodledata 5.0.0The script expects the following structure:
/var/www/html/moodle/ # Moodle code directory
├── admin/ # Moodle admin directory
├── config.php # Moodle configuration
├── version.php # Version information
└── ... # Other Moodle files
/var/www/moodledata/ # Moodle data directory
├── cache/ # Cache files
├── sessions/ # Session data
├── temp/ # Temporary files
└── ... # Other data files
- Automatic Backups: Created before any changes
- Multiple Backup Types: Code, database, and configuration
- Timestamp Naming: Easy identification of backup versions
- Safe Location: Stored in
/tmp/moodle_backup_YYYYMMDD_HHMMSS/
- Secure Defaults: Proper file and directory permissions
- Web Server User: Automatic detection of web server user (www-data, apache, nginx)
- Config Protection: Secured config.php with restricted access
- Maintenance Mode: Automatic activation during updates
- Downgrade Prevention: Blocks dangerous downgrades
- PHP Compatibility: Validates PHP version requirements
- Version Comparison: Intelligent semantic version comparison
Permission Denied:
# Ensure script has execute permissions
chmod +x updater.sh
# Run with sudo
sudo ./updater.sh [paths]PHP Version Too Old:
# Script will prompt to auto-upgrade PHP
# Or manually upgrade PHP first:
sudo apt-get update
sudo apt-get install php8.3Download Failures:
# Check internet connection
curl -I https://github.com
# Verify GitHub access
curl -s https://api.github.com/repos/moodle/moodle/tags | headDatabase Backup Issues:
# Ensure database tools are installed
sudo apt-get install mysql-client # For MySQL/MariaDB
sudo apt-get install postgresql-client # For PostgreSQL
# Verify database credentials in config.phpThe script automatically enables debug mode during updates. To manually enable:
// In config.php
$CFG->debug = 32767;
$CFG->debugdisplay = 1;Check these locations for detailed error information:
- Web server logs:
/var/log/apache2/error.logor/var/log/nginx/error.log - PHP logs:
/var/log/php/error.log - Moodle logs: Via Admin → Reports → Logs in Moodle interface
-
Pre-flight Checks
- Validate paths and permissions
- Check current Moodle version
- Verify PHP compatibility
- Fetch available versions
-
Backup Phase
- Create timestamped backup directory
- Backup Moodle code
- Backup database
- Backup configuration files
-
Maintenance Mode
- Enable maintenance mode
- Display maintenance message to users
-
Update Phase
- Download target Moodle version
- Extract and install new files
- Preserve existing configuration
- Set proper permissions
-
Upgrade Process
- Run Moodle CLI upgrade script
- Update database schema
- Clear caches
-
Finalization
- Disable maintenance mode
- Restart web server
- Verify installation
- Display success status
If an update fails, recovery steps:
-
Automatic Recovery:
# Restore from automatic backup BACKUP_DIR="/tmp/moodle_backup_YYYYMMDD_HHMMSS" sudo cp -r $BACKUP_DIR/moodle_code/* /var/www/html/moodle/ sudo cp $BACKUP_DIR/config.php.backup /var/www/html/moodle/config.php
-
Database Recovery:
# Restore database from backup mysql -u username -p database_name < $BACKUP_DIR/database_backup.sql
-
Manual Maintenance Mode Disable:
# If maintenance mode is stuck sudo sed -i '/maintenance_enabled.*true/d' /var/www/html/moodle/config.php
# If PHP is in non-standard location
export PATH="/opt/php8.3/bin:$PATH"
./updater.sh [paths]# The script auto-detects, but you can modify the script:
# Edit line: WEB_USER="${3:-www-data}"
# Change www-data to your web server user# Ensure outbound HTTPS is allowed
sudo ufw allow out 443
sudo ufw allow out 80- Check Requirements: Ensure all prerequisites are met
- Review Logs: Check web server and PHP error logs
- Test Manually: Verify Moodle works after update
- Backup Status: Confirm backups were created successfully
- GitHub Issues: Report bugs or request features
- GitHub Discussions: Community support and questions
- Moodle Community: moodle.org/support
- Documentation: docs.moodle.org
We welcome contributions! Please see our Contributing Guidelines.
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
When reporting issues, include:
- Operating system and version
- Current Moodle version
- Target Moodle version
- PHP version
- Error messages
- Relevant log excerpts
Important Security Considerations:
- Always test updates in a staging environment first
- Ensure you have complete system backups before major updates
- Review Moodle security announcements before updating
- Keep PHP and web server software updated
- Monitor file permissions after updates
- Verify database integrity after updates
This script is provided as-is for educational and operational purposes. Use at your own risk and always maintain proper backups.
- Initial release
- Automated Moodle updates with backup
- PHP compatibility checking
- Database backup support
- Maintenance mode handling
- Multi-platform support
- Comprehensive error handling
Happy Updating!
For the latest version and updates, visit: https://github.com/EverHype-Systems/moodle-update