Skip to content

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.

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-plugin unless allow-plugins permits 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 in activators.file.statuses-file). The package registers enabled modules only, and any module missing from this file is disabled.

  • The npm lock file. npm ci requires a committed package-lock.json. Run npm install once and commit it if your project does not have one.

  1. Install Composer dependencies without interaction.

    Terminal window
    composer install --no-dev --optimize-autoloader --no-interaction
  2. Build assets using the workflow from Build module assets with Vite. Ensure modules_statuses.json is in place first, because the root Vite loader reads it to find enabled modules.

    For one root Vite build:

    Terminal window
    npm ci
    npm run build

    For standalone per-module builds:

    Terminal window
    for module in Modules/*/; do
    (cd "$module" && npm install && npm run build)
    done
  3. Publish static module assets, if any module ships them.

    Terminal window
    php artisan module:publish --all

    This copies resources/assets from every module on disk (enabled and disabled) to public/modules/<name>. Pass module names instead of --all to publish only specific modules.

  4. Run database migrations.

    Terminal window
    php artisan migrate --force

    This runs pending migrations for the application and every enabled module in one batch. --force skips 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

    --all migrates enabled modules only. To migrate a disabled module, pass its name explicitly (for example php artisan module:migrate Blog --force).

  5. Cache configuration, events, routes, and views.

    Terminal window
    php artisan optimize

    With cached config, module providers skip scanning module config/ directories on web requests. Re-run php artisan optimize whenever you enable, disable, or add a module on a server with cached routes.

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):

Terminal window
rm bootstrap/cache/modules.php

See How modules boot for full details on what the package caches.

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:

config/modules.php
'vapor_maintenance_mode' => true,

After deploying, verify the active modules and routes:

Terminal window
php artisan module:list
php artisan route:list

module:list shows your modules as enabled, route:list includes module routes, and bootstrap/cache/modules.php exists.