Symfony shows default page also if it doesn't exist anymore - php

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

Related

Doctrine insists on trying to use PostgreSQLDriver despite contrary config

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

Symfony, don't show the debug bar when the paged is served from the built in server

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.

enable twig's debug in production

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%"

How to stop Symfony from logging Doctrine's sql queries?

I have a weird issue, when I checked my app/log/dev.log I can see almost all of my queries in my dev.log being logged in real time:
[2015-01-27 06:57:22] doctrine.DEBUG: SELECT t0.username A ....
[2015-01-27 06:57:23] doctrine.DEBUG: SELECT t0.username A ...
[2015-01-27 06:57:23] doctrine.DEBUG: SELECT s0_.id ......
I have no idea why this is happening, since I am running the site on production mode also when I check monolog in my config.yml, this is what I see:
monolog:
handlers:
pictures:
type: stream
path: %kernel.logs_dir%/pictures_%kernel.environment%.log
level: info
instagram:
type: stream
path: %kernel.logs_dir%/instagram_%kernel.environment%.log
level: info
here's what my config_dev.yml looks like:
imports:
- { resource: config.yml }
framework:
router: { resource: "%kernel.root_dir%/config/routing_dev.yml" }
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
intercept_redirects: false
monolog:
handlers:
main:
type: stream
path: %kernel.logs_dir%/%kernel.environment%.log
level: debug
firephp:
type: firephp
level: info
assetic:
use_controller: false
hip_mandrill:
disable_delivery: true
any idea how this could be happening?
You should use prod env on your production server. In the prod env doctrine's logging is disabled by default.
But if you want to disable logging at all (in all environments) you need to set up a config.yml like that:
doctrine:
dbal:
connections:
conn1:
driver: ...
...
logging: false
profiling: false
Reference: https://symfony.com/doc/current/bundles/DoctrineBundle/configuration.html
I encountered a similar issue with dev.log being generated on prod environment. I figured out from the log entries that what was causing my issue was a scheduled cron job calling a custom symfony command. Modifying the entry to app/console with --env=prod for my crontab since stopped dev.log being generated. i.e.
app/console --env=prod custom:command
Must have missed that section of the book :)
As I struggled with the same problem and my .log file was increasing its size the straight solution was when running the consumer use the flag --no-debug
php bin/console messenger:consume async_email_handler --no-debug

Symfony2 dev environment works, prod environment gives 404 error

I have recently successfully installed Symfony2 on my machine.
I can access http:/localhost/app_dev.php (dev environment)
However, when I try to access the prod environment:
http:/localhost/app.php
I get the following error message in the browser:
Oops! An Error Occurred
The server returned a "404 Not Found".
Something is broken. Please e-mail us at [email] and let us know what
you were doing when this error occurred. We will fix it as soon as
possible. Sorry for any inconvenience caused.
I have checked the obvious: The file app.php does exist in the same folder as app_dev.php - so I don't know whats causing this.
Does anyone have a solution to fix this?
[[Edit]]
I have cleared the cache by typing: sudo php app/console cache:clear env=prod no-debug as recommended. I now get a blank screen. Worryingly, there are no error messages logged in app/logs/prod.log, so I have not got the faintest idea as to what is wrong (prod environment still works just fine).
Contents of my app/config/routing.yml file:
### fos routing, remove later
fos_user_security:
resource: "#FOSUserBundle/Resources/config/routing/security.xml"
fos_user_profile:
resource: "#FOSUserBundle/Resources/config/routing/profile.xml"
prefix: /profile
fos_user_register:
resource: "#FOSUserBundle/Resources/config/routing/registration.xml"
prefix: /register
fos_user_resetting:
resource: "#FOSUserBundle/Resources/config/routing/resetting.xml"
prefix: /resetting
fos_user_change_password:
resource: "#FOSUserBundle/Resources/config/routing/change_password.xml"
prefix: /profile
###
# Internal routing configuration to handle ESI
#_internal:
# resource: "#FrameworkBundle/Resources/config/routing/internal.xml"
# prefix: /_internal
Here is my app/config/routing_dev.yml file
_welcome:
pattern: /
defaults: { _controller: AcmeDemoBundle:Welcome:index }
_demo_secured:
resource: "#AcmeDemoBundle/Controller/SecuredController.php"
type: annotation
_demo:
resource: "#AcmeDemoBundle/Controller/DemoController.php"
type: annotation
prefix: /demo
_assetic:
resource: .
type: assetic
_wdt:
resource: "#WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "#WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_configurator:
resource: "#SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix: /_configurator
_main:
resource: routing.yml
I just noticed that I DO NOT have a routing_prod.yml**
(alarm bells ringing) - does Symfony2 not ship with a production routing config file?
My Apache configuration file content is shown below:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /path/to/symfony/web
ServerName localhost
# Custom log file
Loglevel warn
ErrorLog /path/localhost.error.log
CustomLog /path/localhost.access.log combined
<Directory /path/to/symfony/web>
AllowOverride None
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</Directory>
</VirtualHost>
[[Further Details]]
Contents of app/logs/prod.log
[2012-08-10 18:10:38] security.INFO: Populated SecurityContext with an
anonymous Token [] [] [2012-08-10 18:10:38] request.ERROR:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route
found for "GET /" (uncaught exception) at
/path/to/symfony/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php
line 83 [] []
Have you turned on the production environment and cleared the cache?
Run the console and do this:
app/console --env=prod cache:clear
I think I had a similar problem. I believe warming up the cache solved my instance if it.
php app/console cache:warmup --env=prod --no-debug
Having recently installed Symfony 2.2 I ran into this issue too but it's actually the normal behavior. Meaning out of the box Symfony 2.x (as of this writing) doesn't ship with any routes/content for
the production environment.
In your case it looks you installed the Friends of Symfony bundle, which did setup some routes in your production route (routing.yml), but at a glance none of the routes seem to be targeting the root of your production environment i.e. http:/localhost/app.php/ so the 404 is probably expected. I can't be totally sure though since it's importing routes so the details are obscured. A great way to check your routes is to read up on Visualizing & Debugging Routes where you can learn about the app/console router:debug CLI command.
routing.yml is the default place for routes in your production environment (meaning routing_prod.yml isn't a thing). You'll notice routing_dev.yml imports routing.yml. That means that everything that you put in production is (out of the box) accesible in the development. The demo content you see is exclusive to the dev environment so that's why you're not seeing it in the production. Feel free to move some stuff around to suite your needs but it's generally a good idea for the dev to import the production but not vice versa.
Any time you want to test out the changes in your production you'll want to clear your cache as #tolgap recommends. The production environment leans heavily on the precompiled cache, so that command will force your production cache to refresh. The dev environment is always refreshing it's cache. Understanding this is crucial to working with Symfony. Though the Book on Symfony.org is a great entry point it doesn't exactly drive home this point about the subtitles of caching and workflow. I was definitely confused for a minute before I realized the relationship between routing.yml and routing_dev.yml and the soft caching of the dev versus the hard caching of the production.
I tried the solution #gilden gave in his comment; it works.
I ran php bin/console cache:clear --env=prod instead of rm -rf app/cache/*.
I'm surprised that nobody told you:
you have no route for / on the prod environment.
write this in app/config/routing.yml
_welcome:
pattern: /
defaults: { _controller: AcmeDemoBundle:Welcome:index }
You need to install APC for your local server, and everything will work in prod mod for you.
Also try to hit correct database in parameters.yml, because dev is adding DATABASENAME_dev.
Today I had the same problem and tried various solutions. Until I remembered that it is important to have the mod_rewrite apache service enabled. To do this run the following command (on Ubuntu)
sudo a2enmod rewrite
And then restart the server
sudo service apache2 restart
I hope that someone can be helpful.
Regards!
My symfony cache folder was not writable. It worked when i made the cache complete directory and its files as writable.
sudo chmod -R 777 .
(Agrega esto dentro del archivo routing_dev.yml) Add this in routing_dev.yml
_wellcome:
pattern: /
defaults: { _controller:AppBundle:Default:index }

Categories