Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

armyofda12mnkeys's avatar

artisan errors, cant run, unless i install dev-dependencies

So i am using a deploy system that basically runs 'composer install --no-dev' on my production box. But then right afterwards it tries to run 'php artisan optimize' and 'php artisan migrate' and its not working (note: about the latter, i heard laravel 5.6 got rid of artisan's optimize but I'm running 5.5). I logged into box and tried running a 'php artisan list' and realized no artisan command works.

I see this error:

2018-03-22 12:52:16] staging.ERROR: Class 'Way\Generators\GeneratorsServiceProvider' not found {"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Class 'Way\Generators\GeneratorsServiceProvider' not found at /var/www/my_app/releases/1/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php:208)

if i make the deploy system do a 'composer install' without the --no-dev option so it includes my dev dependencies, then 'php artisan' suddenly works. Any idea why?

Here is my app's composer.json file:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "barryvdh/laravel-debugbar": "^2.4",
        "brozot/laravel-fcm": "^1.2",
        "chumper/zipper": "^1.0",
        "davejamesmiller/laravel-breadcrumbs": "3.*.*",
        "firebase/php-jwt": "^5.0",
        "guzzlehttp/guzzle": "~5.3|~6.0",
        "hmazter/laravel-schedule-list": "^0.2.0",
        "laravel/framework": "5.*.*",
        "laravel/tinker": "~1.0",
        "laravelcollective/html": "~5.0",
        "maatwebsite/excel": "~2.1.0",
        "nesbot/carbon": "^1.22",
        "pendonl/laravel-schedulelogger": "^1.1",
        "spatie/laravel-activitylog": "^2.0",
        "webpatser/laravel-uuid": "2.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "krlove/eloquent-model-generator": "^1.2",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.7",
        "xethron/migrations-generator": "^2.0",
        "orangehill/iseed": "dev-master"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist",
        "sort-packages": true
    }
}

Here is some info from that box:

$ php -v PHP 7.1.3 (cli) (built: Apr 13 2017 18:45:36) ( NTS ) Copyright (c) 1997-2017 The PHP Group Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

$ composer -V Composer version 1.5.2 2017-09-11 16:59:25

Pretty sure I am on laravel 5.5 since i see in /var/www/my_app/releases/1/vendor/laravel/framework/composer.json :

    ...
    "extra": {
        "branch-alias": {
            "dev-master": "5.5-dev"
        }
    },

Thanks for any ideas, Ari

PS I'm using a Capistrano-like deploy system called Deployer.org (more php-based than ruby-based). I don't think its doing anything funky, I can see the exact composer default options (which is a tiny bit more complicated than the 'composer install --no-dev' i posted earlier):

composer install --verbose --prefer-dist --no-progress --no-interaction --optimize-autoloader --no-dev

Note: also asked this on laravel.io but seems like more active here (i'll delete that thread over weekend if get an answer here)

0 likes
6 replies
rin4ik's avatar

Have you ran composer update ?

and try

composer dump-autoload

Cronix's avatar
Cronix
Best Answer
Level 67

In your require-dev, you have xethron/migrations-generator. That package (one of its subpackages) uses Way\Generators\GeneratorsServiceProvider.

I'm assuming that you're using that migrations-generator somewhere in your production code, which means you need the package in the require section.

1 like
skliche's avatar

Sounds like you are referencing xethron/migrations-generator somewhere, e.g. your config/app.php.

1 like
armyofda12mnkeys's avatar

Thanks all! Yes it is references that in my config/app.php in my providers section i see: Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class,

so artisan still kinda looks at config/app.php, interesting didn't suspect that.

I'll research how to keep this plugin as a dev dependency ONLY as we were only using in sparingly at beginning of project as our offshore devs didnt write migrations to populate the db, but created new tables manually then used this new artisan command 'php artisan migrate:generate' to create our migration files for other servers hehe. https://github.com/Xethron/migrations-generator

Cronix's avatar

You can conditionally add them depending on the environment. In AppServiceProvider.php's register() method:

public function register()
{
    if ($this->app->environment() !== 'production') {
        $this->app->register(\Xethron\MigrationsGenerator\MigrationsGeneratorServiceProvider::class);
    }
}

and remove it from config/app.php

I do that for the debugbar, and a few others, since you don't really want that on your production server. Then you can keep it as a dev dependency since it will only register it if the env isn't production.

Cronix's avatar

so artisan still kinda looks at config/app.php, interesting didn't suspect that.

It does, unless you use artisan config:cache, which is recommended for production. You'd want to use that in your deploy script. See the docs, and also heed the big warning about only using env() calls in config files and nowhere else in your app: https://laravel.com/docs/5.6/configuration#configuration-caching

Please or to participate in this conversation.