skip to Main Content

Following what symfony says on their deployment page (https://symfony.com/doc/4.2/deployment.html) I created the SSH commands that run post deployment:

cd /var/www/upr/ <-- move into project folder
composer install --no-dev --optimize-autoloader <-- install dependencies on a prod env
bin/console doctrine:migrations:migrate <-- migrate any new DB updates
bin/console cache:clear <-- clear cache

My .env file has the following variables for productions: APP_ENV=prod APP_DEBUG=0

This is the error I get:

Loading composer repositories with package information
Installing dependencies from lock file
Nothing to install or update
Generating optimized autoload files
ocramius/package-versions:  Generating version class...
ocramius/package-versions: ...done generating version class
Executing script cache:clear [KO]
 [KO]
Script cache:clear returned with error code 255
!!  PHP Fatal error:  Uncaught Error: Class 'DoctrineBundleDoctrineCacheBundleDoctrineCacheBundle' not found in /var/www/upr/src/Kernel.php:23
!!  Stack trace:
!!  #0 /var/www/upr/vendor/symfony/http-kernel/Kernel.php(429): AppKernel->registerBundles()
!!  #1 /var/www/upr/vendor/symfony/http-kernel/Kernel.php(130): SymfonyComponentHttpKernelKernel->initializeBundles()
!!  #2 /var/www/upr/vendor/symfony/framework-bundle/Console/Application.php(159): SymfonyComponentHttpKernelKernel->boot()
!!  #3 /var/www/upr/vendor/symfony/framework-bundle/Console/Application.php(65): SymfonyBundleFrameworkBundleConsoleApplication->registerCommands()
!!  #4 /var/www/upr/vendor/symfony/console/Application.php(149): SymfonyBundleFrameworkBundleConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
!!  #5 /var/www/upr/bin/console(42): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput))
!!  #6 {main}
!!    thrown in /var/www/upr/src/Kernel.php on line 23
!!  
Script @auto-scripts was called via post-install-cmd
PHP Fatal error:  Uncaught Error: Class 'DoctrineBundleDoctrineCacheBundleDoctrineCacheBundle' not found in /var/www/upr/src/Kernel.php:23
Stack trace:
#0 /var/www/upr/vendor/symfony/http-kernel/Kernel.php(429): AppKernel->registerBundles()
#1 /var/www/upr/vendor/symfony/http-kernel/Kernel.php(130): SymfonyComponentHttpKernelKernel->initializeBundles()
#2 /var/www/upr/vendor/symfony/framework-bundle/Console/Application.php(159): SymfonyComponentHttpKernelKernel->boot()
#3 /var/www/upr/vendor/symfony/framework-bundle/Console/Application.php(65): SymfonyBundleFrameworkBundleConsoleApplication->registerCommands()
#4 /var/www/upr/vendor/symfony/console/Application.php(149): SymfonyBundleFrameworkBundleConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#5 /var/www/upr/bin/console(42): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput))
#6 {main}
  thrown in /var/www/upr/src/Kernel.php on line 23
PHP Fatal error:  Uncaught Error: Class 'DoctrineBundleDoctrineCacheBundleDoctrineCacheBundle' not found in /var/www/upr/src/Kernel.php:23
Stack trace:
#0 /var/www/upr/vendor/symfony/http-kernel/Kernel.php(429): AppKernel->registerBundles()
#1 /var/www/upr/vendor/symfony/http-kernel/Kernel.php(130): SymfonyComponentHttpKernelKernel->initializeBundles()
#2 /var/www/upr/vendor/symfony/framework-bundle/Console/Application.php(159): SymfonyComponentHttpKernelKernel->boot()
#3 /var/www/upr/vendor/symfony/framework-bundle/Console/Application.php(65): SymfonyBundleFrameworkBundleConsoleApplication->registerCommands()
#4 /var/www/upr/vendor/symfony/console/Application.php(149): SymfonyBundleFrameworkBundleConsoleApplication->doRun(Object(SymfonyComponentConsoleInputArgvInput), Object(SymfonyComponentConsoleOutputConsoleOutput))
#5 /var/www/upr/bin/console(42): SymfonyComponentConsoleApplication->run(Object(SymfonyComponentConsoleInputArgvInput))
#6 {main}
  thrown in /var/www/upr/src/Kernel.php on line 23

From what I understand, the errors I’m getting are from the maker bundle, but I thought using -no--dev on composer install eliminates that issue. So why am I receiving these errors?

Also another question for deployment: Do I delete everything BUT the build folder, because that’s what the site is using? Do I need anything in particular for the production server?

3

Answers


  1. What you try is ok so you could add a git pull to your script to fetch new changes first. Then you should try to run a composer install to install new dependencies from your get repository that are added after composer update to your composer.lock file.

    When you use Webpack then you have to run yarn encore production to generate the files for CSS and Javascript. If you can’t run that files on the server side you could run the command on your machine and upload the generated files. I have some projects where i can’t run node and yarn on the server.

    Some user use Jenkins for deployment and run that script on a deployment server.

    Login or Signup to reply.
  2. This is working for me on a cloud server with ansible:

    a) set env variables:

    export APP_DEBUG= 0
    export APP_ENV=prod
    export DATABASE_URL="mysql://username:pwd@host:port/dbname"
    

    b) Install dependencies

    cd /var/www/upr/     
    composer install --no-dev --optimize-autoloader
    

    or

    sudo -u www-data composer install --no-dev --optimize-autoloader
    

    c) run migrations

    ./bin/console doctrine:migrations:migrate
    

    d) clear cache

     ./bin/console cache:clear
    

    e) install required extensions:

    I am not sure what OS you are using on production. The first error in your comment means you have not setup your production env properly e.g installing required extensions and libs. If you are on ubuntu linux you can try:

    sudo apt-get install php-mysql
    sudo service apache2 restart
    

    The second error means your development env has latest php than your production env. You can either upgrade production server to latest php which more risky depending on your setting or downgrade your development server.
    A quick fix would be, on production server remove composer.lock and run composer again, if you dont have any libs which require php 7.3 it will work nicely otherwise you have to upgrade php.

    Make sure you do not have undesired .env files in project root directory.

    Login or Signup to reply.
  3. DoctrineBundle is deprecated, you can removed this line (23) into your kernel class (src/Kernel.php).

    Gary

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search