How can I enable production mode in Symfony 4? - symfony

I have a copy of my Symfony 4 application on my server. When it is in developement mode it works fine.
In my .env file I have dev mode active:
APP_ENV=dev
But now I want my project on the server turn to production mode. So I changed the line to
APP_ENV=prod
But now I see only a blank page. The error log is not updated. What can I do? If I change the line back again to dev, everything works fine...
(I am on a shared host so I am not sure if this is Apache or Nginx)

I think you still have to clear (and if you want) warmup the cache of your new environment. You can do this from the command line:
php bin/console cache:clear
then
php bin/console cache:warmup

Related

How can I make my git changes visible in production mode (Symfony)?

I make changes local on my mac in dev mode.
After committing the changes I login via ssh to my server.
There I make the command git pull
Now I see my changes on my webpage.
Unfortunately this only works in dev mode.
When I change the mode to production mode in my .env file, then I do not see any updates. What can I do?
You probably need to clear the cache. This can be done with the following command :
php bin/console cache:clear
The following command solved the problem:
rm -rf var/cache/
php bin/console cache:clear --env=prod
to be sure
If you use phpfpm on your server, it can also be required to restart phpfpm service after the cache:clear.
This should not be used in production environemment :
rm -rf var/cache

How can I turn my Symfony 4 application from dev mode into production mode?

On my local host I am able to turn the environment from development mode into production mode by changing in .env:
APP_ENV=dev
into
APP_ENV=prod
and after this I clear the cache in the terminal:
php bin/console cache:clear --env=prod
This works fine on the local machine. But on my server I am not able to clear the cache with this command.
The terminal outputs the error:
Parse error: syntax error, unexpected '?' in www/project/bin/console
So on my page I see only:
Oops! An Error Occurred The server returned a "404 Not Found".
Something is broken. Please let us know what you were doing when this
error occurred. We will fix it as soon as possible. Sorry for any
inconvenience caused.
Check your console selecte php version. It can differ to the version of php-fpm configured in your nginx virtual host. You need at least 7.1
Check
php -v
If you have multiple php versions installed, you can change current console php version with this:
sudo update-alternatives --config php
I will provide your with a list of possible php versions that currently installed on your server.

How to permanently resolve Symfony2 twig_upper_filter error?

Situation:
Production mode
Change a file
One of the pages on the site returns the following 500 internal error.
Run composer update, and the error goes away.
Change a file and the problem returns.
The code calling the twig_upper_filter is buried deep inside the now embedded in symfony bootstrap templates.
What does composer update do that might fix this? It is repeatable (on one server only).
UndefinedFunctionException: "Attempted to call function
"twig_upper_filter" from the global namespace." at
Symfony 2.6.
Because at the end of composer update it does a cache clear, everytime you change something somewhere you need to clear the cache for the change to be visible in the production enviroment.
This is automatic on the development enviroment.
You need to run this from console:
cd /your/symfony/app
php ./app/console cache:clear --env=prod
Letting the web server build the cache resolved the problem. The command line environment must not be exactly the same as the web server php. On this server it is difficult to actually run command line scripts as the web server user.
Therefore, clearing the cache on the command line with no warmup is the work around:
php ./app/console cache:clear --no-warmup --env=prod

Symfony2 trying to write to the previous server it was running on?

I've been developing a Symfony2 app locally and am now at the stage where I would like to deploy it in it's production environment on a server.
I've uploaded all my files and tried to run:
php app/console cache:clear --env=prod
Which gives the following error:
As you can see, it's trying to write to my C:/ drive for some reason. Doing a regular cache:clear works fine, but I can't swap it to the production environment.
At this point, trying to use the app.php version simply loads a blank page. I can't figure out why my app would be trying to write to a directory on a previous server.
Help?
Try empty the cache folder
rm -rf app/cache/*
After this the cache:clear --env=prod command work properly.

symfony 2, demo not working on remote server

I created fresh symfony 2 app which includes AcmeDemoBundle. It works fine.
I commented out in app_dev.php so that it can be accessed from remote server (openshift cloud). On localhost it works without any problem. I git pushed to openshift, and app_dev.php worked as expected.
Then I moved demo routes to route.yml (for production).
On localhost app.php worked without any problem. So I git pushed to openshift but then app.php threw an error:
failed to open stream Acme/DemoBundle/Resources/views/Welcome/index.html.twig
So, I put back demo routes to routes_dev.yml, git pushed, but openshift error persists.
What might be the problem?
EDIT: The problem is that on my localhost path to twig template is "/var/www/html/jba/php/src/JBA/MainBundle/Resources/views/Default/index.html.twig" but on openshift it still looks to the same directory. But openshift dir layout is different, so it can't find the template. I guess I have to configure openshift to look at right directory. Just don't know how.
Have you cleared the cache for the prod environment?
php app/console cache:clear --env=prod
You might also have a look at the server logs/ the sf2 logs within app/logs/prod.log if this won't help.
I issued the following commands before uploading, but somehow cache seems to be not cleared yet.
php /var/www/html/jba/php/app/console cache:clear --env=prod --no-debug
php /var/www/html/jba/php/app/console cache:clear
Only deleting prod and dev directories under app/cache explicitly helped.
See also
Symfony2: access same route in production as development

Resources