1. Continuous Integration / Continuous Delivery (CI/CD)
In an enterprise environment, you never edit code on the server. Use a pipeline.
Typical Pipeline Steps
- Linting: PHPCS with Moodle Standard (
moodle-cs). - Unit Tests: PHPUnit tests for backend logic.
- Behat Tests: BDD tests for UI interactions.
- Build: Compile SCSS, minify JS (Grunt).
- Deploy: Push code to servers (Git pull or artifact deployment).
- Post-Deploy: Run
admin/cli/upgrade.phpandadmin/cli/purge_caches.php.
2. Moodle Upgrades
Upgrading Moodle is a critical process. Always backup DB and Dataroot first.
# 1. Put site in maintenance mode
php admin/cli/maintenance.php --enable
# 2. Backup Database
mysqldump -u user -p moodle > moodle_backup.sql
# 3. Update Code (Git)
git fetch
git checkout MOODLE_403_STABLE
# 4. Run Upgrade Script
php admin/cli/upgrade.php --non-interactive
# 5. Disable Maintenance
php admin/cli/maintenance.php --disable
3. High Availability Architecture
For 500k+ users, a single server won't suffice.
- Load Balancer: Nginx/HAProxy distributing traffic.
- Web Servers: Multiple stateless PHP-FPM nodes.
- Database Cluster: Master-Slave replication (PostgreSQL or MySQL).
- Shared Storage: NFS or S3 (via object storage plugin) for
moodledata. - Cache Store: Redis Cluster for MUC (Application and Session caches).
4. Automated Testing
Enterprise quality assurance relies on automated tests, not manual clicking.
PHPUnit (Unit & Integration Tests)
Tests PHP classes and logic. Requires a separate test database.
# Initialize Test DB
php admin/tool/phpunit/cli/init.php
# Run all tests in a plugin
vendor/bin/phpunit --group=local_myplugin
Data Generators
Don't manually insert records in tests. Use the Data Generator to create courses, users, and enrolments instantly.
$generator = $this->getDataGenerator();
$course = $generator->create_course();
$user = $generator->create_user();
$generator->enrol_user($user->id, $course->id, 'student');
$module = $generator->create_module('forum', ['course' => $course->id]);
Behat (Acceptance Tests)
Tests the UI by simulating a real browser. Written in Gherkin syntax (Given/When/Then).
Feature: User login
In order to access the course
As a student
I need to be able to log in
Scenario: Login with valid credentials
Given I am on the homepage
When I follow "Log in"
And I set the following fields to these values:
| Username | student1 |
| Password | Moodle@123 |
And I press "Log in"
Then I should see "My courses"
# Run Behat
vendor/bin/behat --tags=@local_myplugin
5. Docker for Development
Stop using XAMPP/MAMP. Use moodle-docker for a consistent environment.
# 1. Clone moodle-docker
git clone https://github.com/moodlehq/moodle-docker.git
# 2. Configure environment
export MOODLE_DOCKER_WWWROOT=/path/to/moodle
export MOODLE_DOCKER_DB=pgsql
# 3. Start containers
bin/moodle-docker-compose up -d
# 4. Run tests inside container
bin/moodle-docker-compose exec webserver php admin/tool/phpunit/cli/init.php