Moodle – Simple Upgrade Shell Script

Moodle administrators often need to upgrade their Moodle core to the latest stable version (recommended best-practice), along with other PHP and web server relevant components and dependencies. The upgrade process consists of a number of repeated and predefined steps and procedures, therefore, it might be a time-consuming process if it has been done manually. So, I have developed a simple bash script, that was tested and applied on an Ubuntu 16.04 server, to facilitates Moodle upgrade. This script will first upgrade PHP and then will start Moodle upgrade process.

Script Phases

  1. Activates Moodle Maintenance Mode (To prevent potential data loss)
  2. Stops Apache web server
  3. Starts PHP upgrade process
  4. Starts Apache web server
  5. Starts Moodle upgrade process
  6. Deactivates Moodle Maintenance Mode

Script Anatomy

  1. Activates Moodle Maintenance Mode:
    sudo php /var/www/moodle/admin/cli/maintenance.php --enable
  2. Upgrades PHP:
    1. Stopping Apache web server
      sudo service apache2 stop
    2. Install PHP 7.1 & its common dependencies
      sudo apt-get install -y php7.1-zip php7.1-dev php7.1-ldap php7.1-readline php7.1-xsl php7.1 php7.1-enchant php7.1-mbstring php7.1-recode php7.1-zip php7.1-bcmath php7.1-fpm php7.1-mcrypt php7.1-snmp php7.1-bz2 php7.1-gd php7.1-mysql php7.1-soap php7.1-cgi php7.1-gmp php7.1-odbc php7.1-sqlite3 php7.1-cli php7.1-imap php7.1-opcache php7.1-sybase php7.1-common php7.1-interbase php7.1-pgsql php7.1-tidy php7.1-curl php7.1-intl php7.1-phpdbg php7.1-xml php7.1-dba php7.1-json php7.1-pspell php7.1-xmlrpc
    3. Enables PHP 7.1
      sudo a2enconf php7.1-fpm
    4. Starts Apache web server
      sudo service apache2 start
  3. After the script finishes upgrading PHP it will display the current upgraded version
  4. Upgrades Moodle to Moodle 3.4 Stable
    1. Selects the Moodle root directory
      cd /var/www/moodle
    2. Fetches recent updates from the Moodle main Git repository
      sudo git fetch
    3. Tracks the Moodle 3.4 stable branch
      sudo git branch --track MOODLE_34_STABLE origin/MOODLE_34_STABLE
    4. Checks out “selects” the Moodle 3.4 stable branch
      sudo git checkout MOODLE_34_STABLE
    5. Starts the non-interactive Moodle upgrade process
      sudo php admin/cli/upgrade.php --non-interactive
    6. After the Moodle upgrade process finishes, the script will purge Moodle cache
      sudo php /var/www/moodle/admin/cli/purge_caches.php
    7. Finally, the script will disable the maintenance mode
      sudo php /var/www/moodle/admin/cli/maintenance.php --disable

Getting the script

The script can be downloaded from my GitHub site: https://github.com/ms8277/Moodle-Upgrade-Script

Next Step

Moodle and PHP versions are hardcoded in this script. Therefore, having an interactive script that allows us to choose the required versions to upgrade to, during the runtime, is the next step in developing this script.

Advertisements

2 thoughts on “Moodle – Simple Upgrade Shell Script

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: