symfony2 - how to switch from dev to prod?
By default, Symfony 2 is delivered with a demo bundle which is just accessible from the development environment.
The production environment doesn't contain any route, so it's normal you get a 404 error page.
EDIT :
Are you sure your bundle is enable in the AppKernel.php ?
If yes, clear the cache with the following command : ./app/console cache:clear
Check if the route is enable with the following command : ./app/console router:debug
Symfony change dev to prod
If you want to debug code in a production server, or something similar, I'd say there's at least a golden rule: Don't modify app_dev.php nor app.php. You can keep your prod env as usual, and meanwhile, you can run the webserver bundle with the corresponding environment (i.e. 'dev', you already have 'prod') and port. As you surely know, any changes in the code are compiled on-the-fly in dev, and in prod you have to clear the cache (and even give the proper webserver permissions). As far as I've understood, you don't want anything different to this, so I suggest revert the changes to the app*.php scripts and run the webserver bundle accordingly.
Moving app to production mode in Symfony 2
Couple more things to consider:
php app/console cache:clear --env=prod --no-debug
php app/console assets:install web_directory
php app/console assetic:dump web_directory
You might also run into permission issues with the cache directory. I would actually first make sure everything works in development mode on the server before switching to production mode. And if all you get is blank screens in production mode then set debug to true. And of course know how to check your error logs.
Symfony2, How to change environment?
The two constructor arguments for Symfony\Component\HttpKernel\Kernel are $environment
and $debug
.
So, to answer your question directly, app.php already uses the production environment. You'll notice that app_dev.php instantiates the kernel like this
$kernel = new AppKernel('dev', true);
So, the environment name that you pass to the kernel constructor maps to the environment name you'd use in console commands (i.e., the --env
).
Does that clear it up for you?
How to use symfony environments dev and prod
I think you have the following problems: regardless of which DirectoryIndex
you define, the server also picks ups some settings from .htaccess
. Could it be possible that you have another reference to app.php
in there, like RewriteRule ^(.*)$ app.php [QSA,L]
?
Then you could do the following: move that exact setting from .htaccess
to your server configuration, both locally and on the production server. Then you can keep all other settings independent from your enviroment.
If this does not help yet, please share the content of .htaccess
.
Another way of solving could be to use a recent Symfony version and put everything that might change between environments in the .env
file. Don't put it under version control, as this file might contain sensitive information. Then have a look at the current basics: you no longer have a app.php
and app_dev.php
, as the changes were only little. A common index.php
is used, and it reads all current settings from .env
How to deploy symfony2 - my dev env works but not prod
In your production environment when you run the app/console cache:warmup command you need to make sure you run it like this: app/console cache:warmup --env=prod --no-debug
Also, remember that the command will warmup the cache as the current user, so all files will be owned by the current user and not the web server user (eg: www-data). That is probably why you get a 500 server error. After you warmup the cache run this: chown -R www-data.www-data app/cache/prod
(be sure to replace www-data
with your web server user.
Make sure your parameters.ini file has any proper configs in place since its common for this file to not be checked in to whatever code repository you might be using. Or (and I've even done this) its possible to simply forget to put parameters from dev into the prod parmeters.ini file.
You'll also need to look in your app/logs/prod.log to see what happens when you attempt to login.
Related Topics
How to Force Formrequest Return JSON in Laravel 5.1
PHP Random Url Names (Short Url)
Improve This PHP Bitfield Class for Settings/Permissions
Blank Spaces in Column Names with MySQL
Utf8 Filenames in PHP and Different Unicode Encodings
Problem with Adding Root Path Using PHP Domdocument
PHP Get Actual Maximum Upload Size
Merge 2 Arrays and Sum the Values (Numeric Keys)
How to Run Yii2 Application on Hosting
What Is the Overhead of Using PHP Int
How to Remove a Key and Its Value from an Associative Array
MySQL Database Won't Start in Xampp Manager-Osx
Most Efficient Way to Do Language File in PHP
Where Exactly Do I Put a Session_Start
The Correct Way to Delete All Files Older Than 2 Days in PHP