Deploy an application that uses modules
At the end, your deploy script installs dependencies, builds module assets, runs migrations, and caches the application. Prerequisite: your modules live in Modules/ inside the application repository.
Prepare the repository
Section titled “Prepare the repository”Commit three things before deploying:
-
The Composer merge plugin configuration. Non-interactive deploys do not prompt to trust plugins, so Composer skips
wikimedia/composer-merge-pluginunlessallow-pluginspermits it. Without it, module classes do not autoload:composer.json "config": {"allow-plugins": {"wikimedia/composer-merge-plugin": true}},"extra": {"merge-plugin": {"include": ["Modules/*/composer.json"]}} -
The status file. Commit
modules_statuses.json(or deploy the custom path inactivators.file.statuses-file). The package registers enabled modules only, and any module missing from this file is disabled. -
The npm lock file.
npm cirequires a committedpackage-lock.json. Runnpm installonce and commit it if your project does not have one.
Write the deploy script
Section titled “Write the deploy script”-
Install Composer dependencies without interaction.
Terminal window composer install --no-dev --optimize-autoloader --no-interaction -
Build assets using the workflow from Build module assets with Vite. Ensure
modules_statuses.jsonis in place first, because the root Vite loader reads it to find enabled modules.For one root Vite build:
Terminal window npm cinpm run buildFor standalone per-module builds:
Terminal window for module in Modules/*/; do(cd "$module" && npm install && npm run build)done -
Publish static module assets, if any module ships them.
Terminal window php artisan module:publish --allThis copies
resources/assetsfrom every module on disk (enabled and disabled) topublic/modules/<name>. Pass module names instead of--allto publish only specific modules. -
Run database migrations.
Terminal window php artisan migrate --forceThis runs pending migrations for the application and every enabled module in one batch.
--forceskips the production confirmation prompt.To run each enabled module’s migrations in its own batch (in ascending priority order), use
module:migrate --all --force:Terminal window php artisan module:migrate --all --force--allmigrates enabled modules only. To migrate a disabled module, pass its name explicitly (for examplephp artisan module:migrate Blog --force). -
Cache configuration, events, routes, and views.
Terminal window php artisan optimizeWith cached config, module providers skip scanning module
config/directories on web requests. Re-runphp artisan optimizewhenever you enable, disable, or add a module on a server with cached routes.
The providers manifest
Section titled “The providers manifest”Laravel caches enabled module providers in bootstrap/cache/modules.php during boot and rebuilds it automatically whenever the provider list changes. Ensure bootstrap/cache is writable by the application user, and do not commit this file.
To force a rebuild manually, delete the file (php artisan optimize:clear does not remove it):
rm bootstrap/cache/modules.phpSee How modules boot for full details on what the package caches.
Deploy to Laravel Vapor
Section titled “Deploy to Laravel Vapor”On Laravel Vapor, bootstrap/cache is read-only at runtime. Enable vapor_maintenance_mode in config/modules.php (or set VAPOR_MAINTENANCE_MODE=true in the environment) so the providers manifest writes next to the writable configuration cache:
'vapor_maintenance_mode' => true,Check the result
Section titled “Check the result”After deploying, verify the active modules and routes:
php artisan module:listphp artisan route:listmodule:list shows your modules as enabled, route:list includes module routes, and bootstrap/cache/modules.php exists.
Related
Section titled “Related”vapor_maintenance_modeandactivatorsmodule:publishmodule:migrate- Installation
- Build module assets with Vite
- Prohibit destructive commands in production
- Expose the modules on the actuator: read the modules of a deployed application over HTTP
- How modules boot and Module status and activators: what is cached, and whether to commit the statuses file