PHP open_basedir Security and use _php tutorial

Source: Internet
Author: User
The role of Open_basedir is to specify the directory location, which means that the files that PHP can open are restricted to the specified directory tree, including the file itself, and are not affected by security mode.


The following is the original description in php.ini and the default configuration:
; Open_basedir, if set, limits all file operations to the defined directory
; and below. This directive makes more sense if used in a per-directory or
; Per-virtualhost Web server configuration file. This directive is
; *not* affected by whether Safe Mode was turned on or Off.
Open_basedir =.
Open_basedir can limit the active scope of user access files to the specified area, usually the path of their home directory, or
Available symbols "." To represent the current directory. Note that the limit specified with Open_basedir is actually a prefix, not a directory name.
For example: if "Open_basedir =/dir/user", then the directory "/dir/user" and "/dir/user1" are
You can access the. So if you want to restrict access to only the specified directory, end the path name with a slash. For example, set to:
"Open_basedir =/dir/user/"


Open_basedir can also set up multiple directories at the same time, separate directories in Windows with semicolons, and in any other system
Colon-delimited directory. When it acts on the Apache module, the Open_basedir path in the parent directory is automatically inherited.


There are three ways to make a separate setting for a specified user in Apache:


(a) The appropriate Setup method for the directory in Apache httpd.conf:


Php_admin_value open_basedir/usr/local/apache/htdocs/
#设置多个目录可以参考如下:
Php_admin_value open_basedir/usr/local/apache/htdocs/:/tmp/


(b) The corresponding setup method for VirtualHost in Apache httpd.conf:
Php_admin_value open_basedir/usr/local/apache/htdocs/
#设置多个目录可以参考如下:
Php_admin_value open_basedir/var/www/html/:/var/tmp/


(c) Since Open_basedir is set in VirtualHost, this virtual user will no longer automatically inherit php.ini
Open_basedir setting values, it is difficult to achieve flexible configuration measures, so we recommend that you do not virtualhost
This limit is set in the. For example, you can set Open_basedir = in php.ini.:/ tmp/, this setting means allowing
Access the current directory (that is, the directory where the php script files are located) and the/tmp/directory.


Please note: If the upload file temp directory set in php.ini is/tmp/, then setting Open_basedir must be
Include/tmp/, which will cause the upload to fail. The new PHP will prompt "Open_basedir restriction in effect"
Warning message, but the Move_uploaded_file () function can still successfully remove the upload file from the/tmp/directory without knowing
This is a bug or a new feature.

http://www.bkjia.com/PHPjc/632827.html www.bkjia.com true http://www.bkjia.com/PHPjc/632827.html techarticle The role of Open_basedir is to specify the directory location, which means that the files that PHP can open are restricted to the specified directory tree, including the file itself, and are not affected by security mode. ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.