Reputation: 617
I have an application developed with Symfony 5, which is working fine in my local environment (Vagrant running Laravel Homestead box), but when I deploy it to the live server it crashes with an empty white page and responds with 500 Internal Server Error.
When I SSH into the server and manually change the APP_ENV
variable's value to dev
from prod
inside my .env file, I can see the error:
Attempted to load class "WebProfilerBundle" from namespace "Symfony\Bundle\WebProfilerBundle". Did you forget a "use" statement for another namespace?
I'm using Github Actions to deploy my application and in my action I'm installing the PHP dependencies like this
- name: Install dependencies
run: |
export APP_ENV=prod
composer install --no-dev --optimize-autoloader
So I don't want development only dependencies in my production server, hence the --no-dev
flag, and if I understand correctly the WebProfilerBundle is used for inspecting the request in development, so it's indented to be used only in the dev
environment.
Why does Symfony think it has to load this bundle?
Also, I supposed to have my custom error pages configured for 404 and 500 errors (adding a bundles/TwigBundle/Exception/error.html.twig
file under the templates
folder), why isn't my custom error page shown? Why am I getting an empty white page?
I'm suspecting it's something with the way I'm deploying (since it work on my local machine).
I've tired removing the flags from the composer install (so just running composer install
as is), but that also resulted in an error.
You can view my deployment action here. Also here's the link to the repository.
The app's supposed to run on this domain: https://thebedechkacase.com/
Upvotes: 2
Views: 2934
Reputation: 617
Both the comment of @floGalen and @Gordy's answer were pointing me in the right direction, so thanks for that. But the exact anwser came from reading Symfony's guide on deployment.
If you get a “class not found” error during this step, you may need to run export APP_ENV=prod (or export SYMFONY_ENV=prod if you’re not using Symfony Flex) before running this command so that the post-install-cmd scripts run in the prod environment.
Since I wasn't using Symfony Flex I also needed the SYMFONY_ENV
variable set to prod
.
In addition I had my .env
in the repo - which was actually only the one with development data and APP_ENV=dev
, the "real" .env
file was created during the deployment processes on the runner, retrieving it's value from Github's secret's store. Now the additional problem was that I first checked out my code to the runner, then run composer install
then created the production .env (overwriting the one checked out from the repo), so composer install
actually run with the dev settings. To fix this I moved the creation of my env file right before running composer install --no-dev --optimize-autoloader
, then also did export SYMFONY_ENV=prod
.
The combination of these two solved my issue!
Upvotes: 3
Reputation: 159
Check your config/bundles.php
and be sure to set Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true]
. If i understood correctly your app is trying to load class which is not present under composer. Also be sure to clear cache on prod (php bin/console cache:clear
). Also be sure that your production server have no .env.local
file (or it's APP_ENV
should also be prod
)
Upvotes: 3