Symfony3 - Assets not working properly in Production - php

My SF3 application is working just fine in dev built-in PHP server. However some assets give me an error when getting to a production Apache server : the images are showing a 404 error, and a Bundle triggers a 505 code. Here's 2 screens of the Chrome console where you can see the errors :
Dev:
Prod:
I've been trying many things (checking the Apache conf files, emptying the cache, the install:assets command even thoug I'm just using the classic Twig syntax and no Assetic, etc) and browsed tons of topics over the internet in vain.
Here's my config.yml file just in case :
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#ABundle/Resources/config/services.yml" }
- { resource: "#AnotherBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration/framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
# save_path: /var/lib/php/sessions
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
paths:
"%kernel.root_dir%/../app/Resources/views/modules": modules
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/../var/data/data.sqlite"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
#path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
I'm really stuck on this one, so thank you in advance guys.

have you tried: php bin/console assetic:dump --env=prod --no-debug ?
also, your assets should be in src/YourBundle/Resources/public directory. Then when you install them with php bin/console assets:install --symlink they should be copied or symlinked to web/bundles/your directory

So the problem was that my assets were in the web folder instead of the Resources. Then the assetic:dump command worked perfectly.
Thanks a lot

Related

Degbug toolbar does not appear in symfony 3.3 in dev environment in my website

I am using symfony 3.3. But i cannot see the debug toolbar(_profiler) even though I did which google says correctly.
I went to _profiler route also.But it says 404 error.
Can someone help me?
Following is my config.yml and config_dev.yml
config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
parameters:
locale: en
framework:
profiler:
collect: false
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig','php']
default_locale: "%locale%"
usted_proxies: ~
session:
# http://symfony.com/doc/current/reference/configuration /framework.html#handler-id
handler_id: session.handler.native_file
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
php_errors:
log: true
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
kms_froala_editor:
language: 'en_ca'
config_dev.yml
imports:
- { resource: config.yml }
framework:
router:
resource: "%kernel.root_dir%/config/routing_dev.yml"
strict_requirements: true
profiler: { only_exceptions: false }
web_profiler:
toolbar: true
position: bottom
intercept_redirects: false
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
channels: [!event]
console:
type: console
bubble:
verbosity_levels:
VERBOSITY_VERBOS : NOTICE
VERBOSITY_DEBUG : DEBUG
VERBOSITY_VERY_VERBOSE : NOTICE
channels: [!event, !doctrine]
# uncomment to get logging in your browser
# you may have to allow bigger header sizes in your Web server
configuration
firephp:
type: firephp
level: info
chromephp:
type: chromephp
level: info
If you send response that has not correct html structure, you do not see debug toolbar. You should have the following content in response to see debug toolbar:
<html>
<head>
</head>
<body>
</body>
</html>
If you see 404, that means that you has not controller for this route, you can see your routes by:
php bin/console debug:route
Or your server is closed. You can start them by command:
php bin/console server:run
Anyway you should read about error status codes. It will save you a lot of time:
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes

Redirecting with a route in Symfony2.8

I'm trying to redirect with a route and I', following the official doc Symfony doc
But I've edited the config.yml file with the route field
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
- { resource: "#UserBundle/Resources/config/services.yml" }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
translator: { fallbacks: [en] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#default_locale: "%locale%"
default_locale: es
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
root:
path: /crearUser
defaults:
_controller: UserBundle:Default:create
route: crear
permanent: true
But I get this error
InvalidArgumentException in YamlFileLoader.php line 399: There is no extension able to load the configuration for "root" (in /home/user/pruebasym/app/config/config.yml). Looked for namespace "root", found "framework", "security", "twig", "monolog", "swiftmailer", "doctrine", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution"
It looks like a missed somenthing but I haven't seen anything diferrent a the official doc
The identation level is not correct, If you want to set it in your config.yml, you must follow this indentation level :
framework:
router:
root:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /app
permanent: true
Or simpler, in your routing.yml (like the symfony doc suggests) :
root:
path: /
defaults:
_controller: FrameworkBundle:Redirect:urlRedirect
path: /app
permanent: true

Symfony internationalization

I am having a strange problem with translation in Symfony 2.
This is my config.yml
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
# Put parameters here that don't need to change on each machine where the app is deployed
# http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
framework:
#esi: ~
translator: { fallbacks: ['%locale%'] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
mapping_types:
enum: string
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
fos_user:
db_driver: orm
firewall_name: main
user_class: AppBundle\Entity\User
profile:
form:
type: app_user_profile
parameters.yml
...
locale: ru
And, of course, I have messages.en.yml and messages.ru.yml.
Even when locale is set to 'ru' it displays English text, and $request->getLocale() is always returning 'en'.
What could be the problem and where is it overset to 'en' if not in configs?
The locale parameter in the config.yml file is just a fallback in case a translation for the requested language is not available.
Calling $request->getLocale() will return the language configuration of the browser from which the HTTP-Request was sent.
If you want the translation to be forced into another language take a look at this answer: https://stackoverflow.com/a/14331838/1173391
You need to create a twig extension that allows you to replace ru with en in your path route (and vice versa) :
{# yourProject/app_dev.php/ru #}
Look at this tutorial
http://blog.viison.com/post/15619033835/symfony2-twig-extension-switch-locale-current-route
put in your routing.yml a prefix with the locale like this:
routing.yml
app:
resource: "#AppBundle/Controller/"
type: annotation
prefix: /{_locale}
requirements:
_locale: "%app.locales%"
config.yml
parameters:
locale: en
app.locales: en|ru
Did you add:
{% trans_default_domain "message" %}
on top of your twig template file where the translation keys exist and did you clear cache?

Symfony3 Generate Entites from DB

New to Symfony... Trying to create Entities from an existing DB. I am attempting to following the instructions at http://symfony.com/doc/current/cookbook/doctrine/reverse_engineering.html
Long story short it seems that I simply need 3 commands:
$ php bin/console doctrine:mapping:import --force AppBundle xml
$ php bin/console doctrine:mapping:convert annotation ./src
$ php bin/console doctrine:generate:entities AppBundle
Note: I Modified the name of the bundle from AcmeBlogBundle to AppBundle because I am just using the default bundle. I also am using Symfony 3, everything I look up online seems to reference symfony2
Anyway, first command seems to run fine. I get orm.xml files generated in my ./src/AppBundle/Resources/config/doctrine/ path
Commands 2 and 3 seem to be where my troubles begin.
Command 2 results in
No Metadata Classes to process
Command 3 results in (obviously command 2 didnt work correctly but tried anyway)
[RuntimeException] Bundle "AppBundle" does not contain any mapped entities.
I'm at a loss here.
Contents of config.yml are:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
- { resource: services.yml }
Put parameters here that don't need to change on each machine where the app is deployed
http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
locale: en
framework:
#esi: ~
#translator: { fallbacks: ["%locale%"] }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
#serializer: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
save_path: "%kernel.root_dir%/../var/sessions/%kernel.environment%"
fragments: ~
http_method_override: true
assets: ~
Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
Doctrine Configuration
doctrine:
dbal:
driver: pdo_mysql
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver:
# 1. add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# 2. Uncomment database_path in parameters.yml.dist
# 3. Uncomment next line:
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
naming_strategy: doctrine.orm.naming_strategy.underscore
auto_mapping: true
Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
I did end up getting past this by adding i think the "--from database" flag in one of the commands above. I think the second command. I'm pretty sure youre correct that my config is not expecting the xml files so thats why it cant find them.
you can run the following command straightaway after configuring your parameters.yml.
php bin/console doctrine:mapping:import --force AppBundle annotation
then you can run this command to generate entities
php bin/console doctrine:generate:entities AppBundle
It's also important to try your database connection before running any of those commands. Try to fetch values with
php bin/console doctrine:query:sql "SELECT * FROM your_table_name"

Clear Cache: You have requested a non-existent service "sensio_distribution.webconfigurator"

When run app/console cache:clear, no problem. But when I try to clear prod cache (app/console cache:clear --env prod) I get:
[Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException] You have requested a non-existent service "sensio_distribution.webconfigurator".
I dont have the first clue what am I doing wrong.
my config:
imports:
- { resource: parameters.yml }
- { resource: security.yml }
framework:
#esi: ~
#translator: { fallback: "%locale%" }
secret: "%secret%"
router:
resource: "%kernel.root_dir%/config/routing.yml"
strict_requirements: ~
form: ~
csrf_protection: ~
validation: { enable_annotations: true }
templating:
engines: ['twig']
#assets_version: SomeVersionScheme
default_locale: "%locale%"
trusted_hosts: ~
trusted_proxies: ~
session:
# handler_id set to null will use default session handler from php.ini
handler_id: ~
fragments: ~
http_method_override: true
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
# Assetic Configuration
assetic:
debug: "%kernel.debug%"
use_controller: false
bundles: [ ]
#java: /usr/bin/java
filters:
cssrewrite: ~
#closure:
# jar: "%kernel.root_dir%/Resources/java/compiler.jar"
#yui_css:
# jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"
# Doctrine Configuration
doctrine:
dbal:
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
charset: UTF8
# if using pdo_sqlite as your database driver, add the path in parameters.yml
# e.g. database_path: "%kernel.root_dir%/data/data.db3"
# path: "%database_path%"
orm:
auto_generate_proxy_classes: "%kernel.debug%"
auto_mapping: true
# Propel
propel:
dbal:
#driver: "%database_driver%"
driver: "%database_driver%"
user: "%database_user%"
password: "%database_password%"
dsn: "mysql:host=localhost;dbname=symfony;charset=UTF-8%"
# Swiftmailer Configuration
swiftmailer:
transport: "%mailer_transport%"
host: "%mailer_host%"
username: "%mailer_user%"
password: "%mailer_password%"
spool: { type: memory }
# FOS
fos_user:
db_driver: propel
firewall_name: main
user_class: FOS\UserBundle\Propel\User
Remove manually all directories under app/cache/

Categories