A comprehensive collection of scripts to simplify Moodle updates and plugin management. These tools automate many of the manual steps required for Moodle maintenance, making the process faster, safer, and more reliable.
MoodleUpdateTool provides three main scripts for different Moodle maintenance tasks:
update-moodle-from-zip.sh- Update Moodle from a ZIP archive (Recommended)update-moodle.sh- Update Moodle from extracted directoriesupdate-moodle-plugins.sh- Manage and update Moodle plugins
These scripts automate several steps defined in the official Moodle upgrade documentation.
- β Safety First: Automatic maintenance mode management
- β Backup Support: Database and file backup options
- β Error Handling: Comprehensive error checking and rollback capabilities
- β Logging: Detailed timestamped logs for troubleshooting
- β Permission Management: Automatic file permission fixes
- β PHP Version Selection: Automatic detection or manual selection
- β Validation: Pre-flight checks for disk space, dependencies, and file integrity
- π Direct ZIP Processing: No need to manually extract archives
- π¦ Smart Plugin Preservation: Automatically preserves custom plugins
- π‘οΈ Enhanced Safety: ZIP structure validation and rollback mechanisms
- π§ Automatic Configuration: Preserves settings and applies safe defaults
- π Progress Tracking: Real-time progress updates with emoji indicators
- π Plugin Status Checking: Dry-run mode to check what needs updating
- π Detailed Upgrade Info: Comprehensive analysis of available updates
- π― Selective Updates: Choose which plugins to update
- π§Ή Cache Management: Automatic cache purging after updates
- π Remote Update Detection: Check for plugin updates from repositories
- π Directory-based Updates: Works with pre-extracted Moodle directories
- π Plugin Migration: Copies custom plugins between installations
./update-moodle-from-zip.sh /path/to/current/moodle /path/to/moodle-4.3.zipExample:
./update-moodle-from-zip.sh /var/www/html/moodle ~/Downloads/moodle-4.3.2.zip./update-moodle-plugins.sh /path/to/moodleExample:
./update-moodle-plugins.sh /var/www/html/moodle./update-moodle.sh /path/to/current/moodle /path/to/new/moodle- Bash 4.0+ (macOS/Linux)
- PHP 7.4+ with CLI access
- MySQL/MariaDB with mysqldump
- unzip utility
- sudo access for www-data user
- Read/write access to Moodle directory
- Sudo access for www-data operations
- Database access for backups (optional)
- Minimum 2GB free space (for ZIP method)
- Minimum 1GB free space (for other methods)
- π Compatibility Check: Visit
https://yourmoodle.com/admin/environment.php - π¦ Backup Everything: Database, files, and configuration
- π Update Plugins: Update all plugins to latest compatible versions
- π§ͺ Test Environment: Test the update in a staging environment first
- π Check Disk Space: Ensure sufficient free space
- π₯ Notify Users: Inform users about planned maintenance
# Check current Moodle version
grep '$release' /path/to/moodle/version.php
# Check disk space
df -h /path/to/moodle
# Verify PHP version
php -v
# Test database connection
mysql -u moodleuser -p moodledb -e "SELECT 1;"-
Download Moodle ZIP
wget https://download.moodle.org/download.php/direct/stable43/moodle-4.3.2.tgz
-
Run the Update Script
./update-moodle-from-zip.sh /var/www/html/moodle moodle-4.3.2.zip
-
Follow Interactive Prompts
- Confirm update proceeding
- Choose database backup option
- Confirm installation replacement
- Choose to run upgrade immediately
-
Verify Update
- Check Moodle admin interface
- Verify all plugins are working
- Test critical functionality
-
Check Plugin Status
./update-moodle-plugins.sh /var/www/html/moodle # Select option 2: Check plugin status (dry run) -
Get Detailed Information
# Select option 3: Get detailed upgrade info -
Update Plugins
# Select option 4: Update plugins
# Custom log file location
export LOGFILE="/var/log/moodle_update.log"
# Custom PHP binary
export PHP_BINARY="/usr/bin/php8.1"
# Custom backup directory
export BACKUP_DIR="/backups/moodle"You can modify the following variables in the scripts:
REQUIRED_SPACE_MB: Minimum disk space requirementPLUGIN_DIRS: Additional plugin directories to processBACKUP_RETENTION: Number of backups to keep
| Option | Description | Safe Mode |
|---|---|---|
| 1 | List installed plugins | β Read-only |
| 2 | Check plugin status (dry run) | β Read-only |
| 3 | Get detailed upgrade info | β Read-only |
| 4 | Update plugins | |
| 5 | Purge caches | |
| 6 | Enable maintenance mode | |
| 7 | Disable maintenance mode | β Restores access |
| 8 | Check for remote plugin updates | β Read-only |
| 9 | Exit | β Safe |
Fixed in v1.1 - This error occurred when the script tried to kill processes that had already finished.
Fixed in v1.1 - Improved input handling to prevent logging interference.
# Fix ownership
sudo chown -R www-data:www-data /path/to/moodle
# Fix permissions
sudo chmod -R 755 /path/to/moodle# Test database connection
mysql -u root -p -e "SHOW DATABASES;"
# Check Moodle config
grep -E "(dbhost|dbname|dbuser)" /path/to/moodle/config.php# Check available space
df -h /path/to/moodle
# Clean up old backups
find /path/to/backups -name "moodle_backup_*" -mtime +30 -delete# View recent errors
tail -f moodle_update_*.log | grep ERROR
# Search for specific issues
grep -i "failed\|error\|warning" moodle_update_*.log- Fixed: "kill: No such process" error in plugin status checking
- Fixed: Menu input handling issues
- Improved: Error handling and logging
- Enhanced: Plugin update detection accuracy
- Added: Better progress reporting
- Added: ZIP file structure validation
- Added: Automatic rollback capabilities
- Added: Timestamped backups and logs
- Added: Comprehensive error checking
- Improved: Database backup with credential extraction
- Enhanced: User experience with better prompts
- Initial release with basic functionality
- Manual extraction required
- Limited error handling
- Scripts set appropriate ownership (root:root for core, www-data:www-data for plugins)
- Maintains secure file permissions (755 for directories, 644 for files)
- Attempts to use existing Moodle credentials before prompting for root
- Backup files are created with restricted permissions
- No passwords are logged or stored
- Timestamped backups prevent accidental overwrites
- Automatic cleanup of temporary files
- Rollback capabilities in case of failure
- β Ubuntu 18.04, 20.04, 22.04
- β CentOS 7, 8
- β macOS 10.15+ (with Homebrew)
- β Debian 10, 11
- β Moodle 3.9+ (LTS)
- β Moodle 4.0+ (Current)
- β Moodle 4.1+ (Latest)
- β English (EN) - Fully supported
- β Spanish (ES) - Fully supported
β οΈ Other languages - May require minor adjustments
- Check existing issues in the repository
- Provide detailed error logs
- Include system information (OS, PHP version, Moodle version)
- Describe steps to reproduce
- Plugin-specific update management
- Integration with Git repositories
- Web-based interface
- Automated scheduling
- β Automate Moodle core updates
- β Preserve custom plugins and themes
- β Handle database and file backups
- β Manage maintenance mode
- β Fix file permissions
- β Provide detailed logging
- β Update PHP or system packages
- β Update plugin code (only detect updates)
- β Modify database schema (Moodle handles this)
- β Update web server configuration
- β Handle SSL certificates
- Always test in staging first
- Keep multiple backups
- Monitor disk space
- Update during low-traffic periods
- Have a rollback plan
- Keep logs for troubleshooting
- Check the logs - Most issues are documented in the log files
- Review this README - Common solutions are documented here
- Test in staging - Reproduce issues in a safe environment
- Check Moodle forums - Community support for Moodle-specific issues
If an update fails:
- Don't panic - Backups are created automatically
- Check maintenance mode - Disable if needed:
php admin/cli/maintenance.php --disable - Restore from backup - Use the timestamped backup directories
- Check logs - Review error messages for specific issues
- Seek help - Contact your system administrator or Moodle community
This project is licensed under the terms specified in the LICENSE file.
If these scripts save you time and effort, consider buying the author a coffee! Your support helps maintain and improve these tools.
π Last Updated: December 2024 π Version: 1.1 π¨βπ» Author: Daniel Seixas