I've been working on an experimental way to manage the code of a Moodle site as one single Composer project. This means that both Moodle itself and all third-party plugins are dependencies of the project.
The benefits of this approach are:
- It's easy to duplicate the code between environments (developer1, developer2, staging, production) so that it is completely identical between them all.
- Possibility to update both Moodle core and all third-party plugins to latest version (within the version constraints defined in composer.json) with one single `composer update` command.
- Possibility for automation
- For example the `composer install` command could be configured to also automatically run upgrades via admin/cli/upgrade.php.
- Composer is de-facto standard package manager for PHP. Learn it once, and you will be able to use it with all kinds of PHP applications!
My project can be found here: https://github.com/juho-jaakkola/moodle-project. I would very much like to get feedback about it.
In order to test it, you need command line access to git and composer.
You can try out the project like this (change the name of "your_project"):
- git clone https://github.com/juho-jaakkola/moodle-project.git your_project
- cd your_project
- composer install
After this you should have the following directory structure:
composer.json
composer.lock
README.md
vendor/
web/
Now you can install plugins with the `composer require` command.
For example:
composer require netspotau/moodle-mod_lightboxgallery
Thanks to a special Composer installer, the plugin will get automatically installed to `web/mod/lightboxgallery/`.
Both composer.json and composer.lock will get updated automatically. Composer uses these two files to save the status of the project. Thanks to them, the same versions of the same plugins get installed also to the other environments. (Once shared to other devs e.g. through git.)
Once installed, the domain of the site should be configured to point to the `web/` directory.
Known issues:
The only challenge with the project is that only a handful of Moodle plugins currently support Composer.
I believe the main reasons for this are:
- Many people do not manage their Moodle code through command line (and don't even want to, which is OK)
- It hasn't been possible to use Composer properly with Moodle before
I'm hopeful that popularity of Composer will increase in time in the Moodle community. Also there are different kinds of workarounds that allow Composer to install also plugins that do not yet have support for it.
Please post any questions about the project's usage here in the forums, and report any found bugs to the Github issue tracker!