I am using Symfony's debug bundle:
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
...
new Symfony\Bundle\DebugBundle\DebugBundle()
);
Temporarily, I would like to enable the dump() method in my production environment (and is configured to work like that in AppKernel.php).
Unfortunately the dump is not outputting anything, unlike in dev mode. Do I always need to set the dump_destination parameter if I want to enable it in production?
Add in the config_prod.yml files the line (or simply add the debug key if you have other configuration in the ):
config_prod.yml
# Twig Configuration
twig:
debug: "%kernel.debug%"
Related
I am setting up a Symfony 5.2 app, using doctrine/doctrine-bundle 2.4 and doctrine/orm 2.9. My doctrine.yaml config file looks like this:
doctrine:
dbal:
url: '%env(resolve:DATABASE_URL)%'
driver: 'pdo_mysql'
server_version: '5.7'
# IMPORTANT: You MUST configure your server version,
# either here or in the DATABASE_URL env var (see .env file)
#server_version: '13'
orm:
auto_generate_proxy_classes: true
naming_strategy: doctrine.orm.naming_strategy.underscore_number_aware
auto_mapping: true
mappings:
App:
is_bundle: false
type: annotation
dir: '%kernel.project_dir%/src/Entity'
prefix: 'App\Entity'
alias: App
The problem is that when I run doctrine:fixtures:load, I get the following output:
In AbstractPostgreSQLDriver.php line 102:
An exception occurred in driver: could not find driver
In Exception.php line 18:
could not find driver
In PDOConnection.php line 39:
could not find driver
It looks like Doctrine is trying to use the Postgre driver, though I have specified MySQL. Is there another place where I need to configure this? If so, how?
===
EDIT: It looks like DATABASE_URL is not available inside my Docker container, which is probably the source of the problem. I've verified that DATABASE_URL is defined in my .env file, and that my .env file is in the same folder as my docker-compose.yml file. Also, I have a setting like this for the environment variable in that docker-compose file:
environment:
- DATABASE_URL
So I'm not quite sure what's wrong here.
I think you have a wrong DATABASE_URL in your .env file. Please check if it starts with mysql://.
I believe symfony uses dotenv package to load the values from .env to the S_ENV superglobal. You need to debug whether your dotenv (and there is a .env in your project and it is not .env.local or .env.dist) is loaded properly.
It has happened to me sometimes when I was starting, typically when cloning a Github project which has a default .env file created by Doctrine when it's installed through composer that by default Doctrine uses PostgreSQL URL.
See how many .env files have you document and I'm sure that someone overrides your URL connection.
See this StackOverflow post to know the difference between the .env.* files What is the difference between .env.local and .env.development.local
I have a Symfony instance running on Linux with apache y NGINX. I'am starting the project using the built-in server:start command:
php bin/console server:start
Back to my browser, it loads me the Symfony start page but it also shows me the debug bar.
I have checked the config_dev.yml file and I think it is correct:
imports:
- { resource: config.yml }
framework:
router:
resource: '%kernel.project_dir%/app/config/routing_dev.yml'
strict_requirements: true
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: false
However, if I try to access another route that I don't have, the debug bar is also shown:
You can access the prod env with:
http://127.0.0.1:8000/app.php
And accessing http://127.0.0.1:8000/app.php/a will give you an error page without the debug bar.
It is designed like this because the Symfony built-in web server is only meant to be used in development not in production. So the default environment is the "dev" one.
I've installed on my Ubuntu server, Symfony 3.3.6.
The problem is that it shows me the default page, also if I delete all code on "index.html.twig" or if I edit the code with my code. If I add views and Controllers, Symfony doesn't consider them and it shows me a 404 error.
I can't understand why and I don't find any error in config.php or app.php files.
I've also tried to set auto_reload: true on my config.yml but it doesn't matter... what I've to do? I'm quiet desperate...
EDIT: I've forgotten to say that if I delete index.html.twig, it shows me an error, so I'm not in wrong path
My twig parameters in config.yml
twig:
# debug: '%kernel.debug%'
strict_variables: '%kernel.debug%'
auto_reload: true
debug: true
cache: false
Sounds like you might need to clear the cache
To clear the dev cache do
php bin/console cache:clear
To clear the prod cache do
php bin/console cache:clear --env=prod
You can also tell twig not to cache like this. Amend your
# app/config/config_dev.yml
twig:
cache: false
debug: true
This assumes you are working in the dev environment
If you don't see the debug toolbar at the bottom of your web pages then you are probably working on a prod environment. In that case you may need to move that twig config to your app/config/config.yml
I am working on a Symfony2 project, I am trying to enable the profiler so i can do further debugging. I expect to see X-debug-token-link under Response Headers but i dont see it and i cant see the toolbar at the bottom of my page.
In my routing_dev.yml it seems that these options are enabled:
framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
profiler: { only_exceptions: true }
web_profiler:
toolbar: true
intercept_redirects: false
Yet I cannot reach the profiler. Is there anything I am missing...?
Make sure you run your application in dev or test environment. Even though the cookbook states that collect is enabled by default, I had to set it explicitly to activate the profiler. At least in version 2.7. Here's the configuration I use:
# app/config/dev/config.yml
framework:
# activate profiler in framework
profiler:
collect: true
# configure profiler
web_profiler:
# display the web debug toolbar at the bottom of pages with a summary of profiler info
toolbar: true
# gives you the opportunity to look at the collected data before following the redirect
intercept_redirects: false
# Exclude AJAX requests in the web debug toolbar for specified paths
excluded_ajax_paths: ^/bundles|^/_wdt
Further reading:
FrameworkBundle Configuration ("framework") profiler
WebProfilerBundle Configuration ("web_profiler")
Make sure your app_dev.php or other entry point enables the debugging:
Debug::enable();
Also make sure your routing_dev.yml contains the profiler routes:
_profiler:
resource: "#WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
I've declared a configuration in app/config/config_prod.yml so I can execute commands on the remote database.
imports:
- { resource: config.yml }
doctrine:
dbal:
driver: %database_driver%
host: the-ip
dbname: the-database
user: the-user
password: the-password
But when I run php app/console doctrine:schema:update --dump-sql -e=prod it still uses the configuration set in parameters.yml.
A var_dump($this->getApplication() in the execute method in Doctrine\Bundle\DoctrineBundle\Command\Proxy\UpdateSchemaDoctrineCommand shows the right environment doesn't get the configuration from config_prod.yml
public $parameters =>
array(428) {
...
'kernel.environment' =>
string(4) "prod"
...
'database_host' =>
string(9) "127.0.0.1"
Did I encounter a bug or is this command not capable of dealing with different environments?
Short: You have to clear the cache after every configuration change in the prod environment. In the dev environment the cache is rebuild (some parts not) on every request. But not in prod.
Indeed, configuration is compiled into cache. Loading the configuration from YAML/XML on every request would be too heavy. Look for the method getDefaultParameters() in app/cache/prod/appProdProjectContainer.php and you can see, all configuration parameters are merged in a huge big array.
You will notice, the parameters in this array, are not often the same, you configure in your config.yml. The injecting of these parameters depends on the bundle and their specific extension class. See Semantic Configuration for further infos.