Symfony2 open_basedir restriction in effect

。_饼干妹妹 提交于 2021-01-28 05:49:46

问题


i'm trying to deploy a symfony 2.7 project to shared hosting. Everything works fine on localhost but on the server i got big fat error...

When i try to hit the site:

http://infinityproperty.sitetester.biz/

I was getting a error :

Warning: is_dir(): open_basedir restriction in effect. File(/srv/www/infinityproperty.sitetester.biz/web) is not within the allowed path(s):

When I try to enter 3-4 times it removes the error and i can see the structure. But the issue is there. Also no images from the liipimage are shown.

I have remove the check for the locale and the error can be seen :

http://infinityproperty.sitetester.biz/app_dev.php

I know that it is very dangerous and i will completely remove it after resolving my issue.

The app, bin, and so on are one directory up in a private folder.

Here is the basic config:

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: bg
    kernelRootDir: %kernel.root_dir%
    web: "/../../web"
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:  ~
    fragments:       ~
    http_method_override: true

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    globals:
        kernelRootDir: %kernel.root_dir%
    form_themes:
        # other form themes
        - 'CoreBundle:VichForm:fields.html.twig'
# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [CoreBundle,FOSUserBundle,PagesBundle]
    #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
        # 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 # other valid values are 'mongodb', 'couchdb' and 'propel'
    firewall_name: main
    user_class: George\UserBundle\Entity\User
simple_things_entity_audit:
    audited_entities:
        - George\PageBundle\Entity\Page
        - George\UserBundle\Entity\User
stof_doctrine_extensions:
    orm:
        default:
            sluggable: true
            sortable: true
            timestampable: true
vich_uploader:
    db_driver: orm
    mappings:
        product_image:
            uri_prefix:         /images/products
            upload_destination: %kernel.root_dir%/../../web/images/products
            inject_on_load:     false
            delete_on_update:   true
            delete_on_remove:   true
        apartment_image:
            uri_prefix:         /images/apartment
            upload_destination: %kernel.root_dir%/../../web/images/apartment
            inject_on_load:     false
            delete_on_update:   true
            delete_on_remove:   true
        slide_image:
            uri_prefix:         /images/slider
            upload_destination: %kernel.root_dir%/../../web/images/slider
            inject_on_load:     false
            delete_on_update:   true
            delete_on_remove:   true
        point_image:
            uri_prefix:         /images/point
            upload_destination: %kernel.root_dir%/../../web/images/point
            inject_on_load:     false
            delete_on_update:   true
            delete_on_remove:   true
        object_image:
            uri_prefix:         /images/object
            upload_destination: %kernel.root_dir%/../../web/images/object
            inject_on_load:     false
            delete_on_update:   true
            delete_on_remove:   true
        gallery_image:
            uri_prefix:         /images/gallery
            upload_destination: %kernel.root_dir%/../../web/images/gallery
            inject_on_load:     false
            delete_on_update:   true
            delete_on_remove:   true
        company_image:
            uri_prefix:         /images/company
            upload_destination: %kernel.root_dir%/../../web/images/company
            inject_on_load:     false
            delete_on_update:   true
            delete_on_remove:   true
liip_imagine:
    resolvers:
       default:
          web_path: ~

    filter_sets:
        cache: ~
        my_thumb:
            quality: 75
            filters:
                thumbnail: { size: [120, 90], mode: outbound }
        720x534:
            quality: 75
            filters:
                thumbnail: { size: [720,534],  mode: outbound }
        1920x1440:
            quality: 75
            filters:
                thumbnail: { size: [1920,1440],  mode: outbound }
oneup_uploader:
    mappings:
        gallery:
            frontend: fineuploader # or any uploader you use in the frontend
            allowed_mimetypes: [image/jpeg,image/png,image/gif]
            namer:  oneup_uploader.namer.uniqid

a2lix_translation_form:
    locale_provider: default       # [1]
    locales: [bg, en]          # [1-a]
    default_locale: bg             # [1-b]
    required_locales: [bg]         # [1-c]
    manager_registry: doctrine      # [2]
    templating: "A2lixTranslationFormBundle::default.html.twig"      # [3]
swiftmailer:
    transport: '%mailer_transport%'
    host:      '%mailer_host%'
    username:  '%mailer_user%'
    password:  '%mailer_password%'
stfalcon_tinymce:
        tinymce_jquery: true
        selector: ".tinymce"
        # Get current language from the parameters.ini
        language: %locale%
        # Custom buttons
        tinymce_buttons:
            stfalcon: # Id of the first button
                title: "Stfalcon"
                image: "http://stfalcon.com/favicon.ico"
        theme:
            # Simple theme: same as default theme
            simple: ~
            # Advanced theme with almost all enabled plugins
            advanced:
                 plugins:
                     - "advlist autolink lists link image charmap print preview hr anchor pagebreak"
                     - "searchreplace wordcount visualblocks visualchars code fullscreen"
                     - "insertdatetime media nonbreaking save table contextmenu directionality"
                     - "emoticons template paste textcolor"
                 toolbar1: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
                 toolbar2: "print preview media | forecolor backcolor emoticons | stfalcon | example"
                 image_advtab: true
                 templates:
                     - {title: 'Three columns', content: '<div class="firstColumn">aaaaaa</div><div class="secondColumn">aaaaaa</div><div class="thirdColumn">ccccc</div>'}
                     - {title: 'checklist', content: '<ul><li>Chek 1</li><li>Chek 1</li></ul>'}
            # BBCode tag compatible theme (see http://www.bbcode.org/reference.php)
            bbcode:
                 plugins: ["bbcode, code, link, preview"]
                 menubar: false
                 toolbar1: "bold,italic,underline,undo,redo,link,unlink,removeformat,cleanup,code,preview"

EDIT

It was not the open_basedir the problem... It was the first deployment of the project so it has some problems with the paths... So the solution was to clear all the cache and make all directories with the proper permissions also the config file was needed to be twig a bit basically where should stay the core symfony.


回答1:


Please note that using 'open_basedir' directive will disable usage of 'realpath_cache'.

When you set PHP's open_basedir restriction, PHP will deactivate the realpath cache. This will decrease the performance of any PHP application which uses multiple files (include_once, require_once) like WordPress, Drupal and Magento -- just to mention a few. The decision to deactivate the realpath cache when using open_basedir (and the previous safe_mode) restriction was made when the PHP team fixed CVE-2006-5178. Please see PHP's bug report 52312 for further information.

I`ve been digging for a few days till finding that out. This literraly sky-rocketed my project with performance from ~1000ms to ~60ms as Symfony is heavily cache-dependent. But you must consider possible security risks...




回答2:


You can just remove the open_basedir restriction entirely. Either modify your php.ini file manually or modify it in the control panel found at WebSites -> Your Site -> Options -> Custom php.ini settings to this:

open_basedir =

This should solve your issue. If you are still worried about this being dangerous, you can also manually set the base directory to your folder:

open_basedir = /srv/www/infinityproperty.sitetester.biz/web


来源:https://stackoverflow.com/questions/34858986/symfony2-open-basedir-restriction-in-effect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!