How do I limit PHP apps to their own directories and their own php.ini?

前端 未结 6 737
走了就别回头了
走了就别回头了 2021-01-01 00:38

I am running multiple PHP apps on my Mac, running OS X 10.5.6, Apache 2, PHP 5. I have subdomains setup for each project, a host file entries for each subdomain, and Virtua

相关标签:
6条回答
  • 2021-01-01 01:18

    If you want to use full path name, you can use that:

    <?php
    include  dirname( __FILE__ ) . '/includes/include.php';
    ?>
    

    Possible solution for php.ini file

    0 讨论(0)
  • 2021-01-01 01:21

    I believe it's possible to set a php.ini per virtual host

    <VirtualHost *:80>
        ...
    
        PHPINIDir /full/path/to/php/ini/
    
    </VirtualHost>
    

    this way you can customize open_basedir and others

    0 讨论(0)
  • 2021-01-01 01:22

    Try a relative path! Like:

    <?php
    include("./includes/include.php");
    ?>
    

    or

    <?php
    include("includes/include.php");
    ?>
    
    0 讨论(0)
  • 2021-01-01 01:30

    You can limit a scripts ability to see anything above a specific folder tree by adding the open_basedir directive a folder block in the httpd.conf file. It should look like:

    <DIRECTORY /full/path/to/folder/containing/script/>

    php_admin_value open_basedir "/full/path/to/top/folder/of/desired/tree/"

    </DIRECTORY>

    One thing - if you don't end the path with a / then it's a wildcard match. In other words, "/var/etc/my" will match "/var/etc/myFolder" as well as "/var/etc/myMothersFolder", while "/var/etc/my/" will only match that exact folder name.

    0 讨论(0)
  • 2021-01-01 01:33

    Best way to do so is to use PHP via FCGI (mod_fcgid). This way you can run PHP using a different user and a different php.ini per vHost.

    Here's an example how to set up such a configuration on Ubuntu: http://www.howtoforge.com/how-to-set-up-apache2-with-mod_fcgid-and-php5-on-ubuntu-8.10

    0 讨论(0)
  • 2021-01-01 01:38

    Regarding application isolation ~ is this in regards to securing PHP scripts so they cannot access others? Please elaborate -

    Regarding php.ini - I am not aware of any way to use a specific php.ini per directory, but you could certainly create a php include page with a bunch of ini_set() lines, perhaps something like this ..

    <?php
      // in your header or along top of all php modules in your pap
      require_once ( '/path/to/includes/ini_set.php' );
    
      // ...
    
    ?>
    

    and the ini_set.php script:

    <?php
      // one of these for each override of defaults set in php.ini file --
      ini_set ( $varname, $newvalue );
      ini_set ( $varname, $newvalue );
      ini_set ( $varname, $newvalue );
    ?>
    

    If you are interested in learning more about the ini_set() function, here is the documentation page on php.net: http://us3.php.net/ini_set

    Hope this was somewhat helpful ~

    0 讨论(0)
提交回复
热议问题