简体   繁体   中英

Symfony3 Export To Production

I have a server running on apache2 with some virtual hosts and I want to deploy a Symfony3 application on it. However, I cannot deploy it correctly to the production environment, it works perfectly on development environment. Whenever I do execute

sudo composer install --no-dev --optimize-autoloader 

I get the error:

PHP Fatal error: Class 'Sensio\\Bundle\\GeneratorBundle\\SensioGeneratorBundle' not found in /my/path/app/AppKernel.php on line 25 Script Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache handling the post-install-cmd event terminated with an exception

[RuntimeException]
An error occurred when executing the "'cache:clear --no-warmup'" command: PHP Fatal error:  Class 'Sensio\Bundle\GeneratorBundle\SensioGeneratorBundle'not found in /my/path/app/AppKernel.php on line 25.

After getting this error I went to read the documentation again and it said that I need to export this the Symfony environment to production. So I did that:

export SYMFONY_ENV=prod

After that I executed the composer install command again but, same results.

Some people on Stackoverflow (and other sources) said that I need to clear my cache by executing

sudo bin/console cache:clear --env=prod

So I did that but same results. Anyone any idea?

Other solutions tried: Actually it works great whenever I execute the command this way:

sudo SYMFONY_ENV=prod composer install --no-dev --optimize-autoloader 

However, whenever everything was installed correctly, I went to try to visit the URL and I got a 500. So I went to the Apache2 logs to check if something was wrong and I saw the same RuntimeException again.

EDIT

So I've also followed the instructions of this link but unfortunately, same results. I also checked if I've got everything installed correctly such as ACL and I did.

I also did an getfacl /my/path/var/cache and it showed the correct information based on this link .

EDIT #2

I've also already run php bin/symfony_requirements and it showed me that 'My system is ready to run Symfony Projects', even after php bin/console cache:clear --env=prod --no-debug

I'm not certain what the problem could be, but since this is a new deploy, make sure you have setup the correct install requirements. For apache, normally the user is apache and group is apache.

In a production environment an easy way to set the correct owner:group is the following command:

$sudo chown -R apache:apache /var/www/html/test.karljohnchow.com/

Also, this link: http://symfony.com/doc/current/book/installation.html#checking-symfony-application-configuration-and-setup

Describes how to setup the ACL permissions on Linux (and MacOS), and the var directory needs special permissions.

Make sure you check those things and see if that helps.

Edit #2. I saw your comment. One of those links is for Symfony2 and it's old. I don't suggest using references that are old. They may refer to Symfony2 which is different than Symfony3.

Take a look at this link: http://symfony.com/doc/current/cookbook/deployment/tools.html

Have you run the php bin/symfony_requirements command yet? This is important that this passes. It'll point out problems. Also the command to clear (and warm-up) the cache is:

$ php bin/console cache:clear --env=prod --no-debug

That's different from what you show above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM