FOSUserBundle身份验证无法在生产服务器上运行

时间:2014-09-02 09:32:49

标签: php security symfony fosuserbundle

我是Symfony的新手,也许这就是为什么我似乎无法定位某些错误产生的地方。 当我将我的网站放在生产服务器上时出现了一个新问题,FOSUserBundle身份验证似乎无法正常工作

注意:这在localhost上运行得非常好,但是只要我把它放在远程服务器上,它就不会验证任何用户。

web / config.php文件建议使用i:

    1) Install and enable the php_posix extension (used to colorize the CLI output).
    2) Install and enable the intl extension (used for validators)
    3) Install and enable a PHP accelerator like APC (highly recommended).
    4) Set short_open_tag to off in php.ini*.

这会导致身份验证出现问题吗?

我的config.yml文件

    imports:
        - { resource: parameters.yml }
        - { resource: security.yml }

    framework:
        #esi:             ~
        translator:      { fallback: "%locale%" }
        translator:      ~
        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:        [ LesCouvertsBundle , LesRestaurantBundle , LesVirtualMarketBundle , LesShopBundle ]
        #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

    # Swiftmailer Configuration
    swiftmailer:
        transport: "%mailer_transport%"
        host:      "%mailer_host%"
        username:  "%mailer_user%"
        password:  "%mailer_password%"
        encryption: ssl
        auth_mode:  login
        spool:     { type: memory }

    fos_user:
        db_driver: orm # other valid values are 'mongodb', 'couchdb' and 'propel'
        firewall_name: main
        user_class: Les\UserBundle\Entity\User
        registration:
            confirmation:
                from_email:
                     address:        registration@lescouverts.com
                     sender_name:    Lescouverts Registration
                enabled:    false
        from_email:
            address:        noreply@lescouverts.com
            sender_name:    LesCouverts

    services:
        resto_module:
            class:        Les\RestoModule\Module
            arguments:    [module]
        lists_module:
            class:        Les\RestoParam\Param
            arguments:    [parameters]

我的security.yml文件

    security:
        encoders:
            FOS\UserBundle\Model\UserInterface: sha512

        role_hierarchy:
            ROLE_CLIENT:      ROLE_USER
            ROLE_RESTO:       ROLE_CLIENT
            ROLE_SHOP:        ROLE_CLIENT
            ROLE_ADMIN:       [ ROLE_USER, ROLE_CLIENT, ROLE_RESTO , ROLE_SHOP ]
            ROLE_SUPER_ADMIN: ROLE_ADMIN

        providers:
            fos_userbundle:
                id: fos_user.user_provider.username

        firewalls:
            main:
                pattern: ^/
                form_login:
                    provider: fos_userbundle
                    login_path:     fos_user_security_login
                    csrf_provider: form.csrf_provider
    #                        check_path: /login_check
                    check_path: fos_user_security_check
                    default_target_path: /
                    csrf_provider: form.csrf_provider

                logout:
                    path: fos_user_security_logout

                anonymous:    true

        access_control:
             - { path: ^/booking, role: ROLE_CLIENT }
             - { path: ^/party_calendar, role: ROLE_CLIENT }
             - { path: ^/restaurant_admin, role: ROLE_RESTO }
             - { path: ^/shop_admin, role: ROLE_SHOP }
             - { path: ^/virtual_market, role:  [ ROLE_RESTO, ROLE_SHOP ] }
             - { path: ^/root, role: ROLE_ADMIN }

             - { path: ^/secure_area/login, role: IS_AUTHENTICATED_ANONYMOUSLY }
             - { path: ^/secure_area/connect, role: IS_AUTHENTICATED_ANONYMOUSLY }
             - { path: ^/secure_area, role: ROLE_USER }

我不确定如何调试此问题!

在开发模式中,我收到错误

      RuntimeException: Failed to write cache file    
          "/var/www/vhosts/httpdocs/app/cache/dev/classes.php".

所以我甚至无法看到分析器是否指出任何错误!

1 个答案:

答案 0 :(得分:1)

一个常见问题是app / cache和app / logs目录必须可由Web服务器和命令行用户写入。

http://symfony.com/doc/current/book/installation.html#configuration-and-setup