2017-08-31 53 views
1

我的SF3應用程序在開發內置的PHP服務器中工作得很好。但是,有些資產在進入生產Apache服務器時給我一個錯誤:圖像顯示404錯誤,Bundle觸發505代碼。這裏的鉻控制檯的兩個屏幕,你可以看到錯誤:Symfony3 - 資產在生產中無法正常工作

Dev

Prod

我一直想很多事情(檢查Apache的conf文件,清空緩存,安裝:資產即使你使用了命令,我只是使用經典的Twig語法,而沒有使用Assetic等等),並且徒勞地瀏覽了互聯網上的大量主題。

這是我的config.yml文件,以防萬一:

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 }

我真的卡在這一塊,所以預先感謝您的傢伙。

回答

0

你試過了嗎:php bin/console assetic:dump --env=prod --no-debug

另外,您的資產應在src/YourBundle/Resources/public目錄中。然後當你安裝他們php bin/console assets:install --symlink他們應該被複制或符號鏈接到web/bundles/your目錄

+0

因此到控制檯, 此命令不會SF3下存在: [Symfony的\元器件\控制檯\異常\ CommandNotFoundException] 命令「assetic」沒有定義。 你的意思是? 資產:安裝 – Pigbug

+0

這可能是因爲您沒有安裝Assetic。 http://symfony.com/doc/current/assetic/asset_management.html –

+0

我安裝了Assetic並運行命令,但這並沒有解決問題。儘管謝謝你的回答! 我通常將資源放在/ web文件夾中,正如文檔所建議的(「將資源存儲在web /目錄中」:http://symfony.com/doc/current/best_practices/web-assets.html) 。這是一個錯誤嗎? – Pigbug

0

所以問題是,我的資產是在網絡文件夾,而不是資源。然後資產:轉儲命令完美地工作。 非常感謝

+0

我很高興! –

相關問題