Apache

How to:- set specific path/directory for “open_basedir” in PHP or Apache?

open_basedir function used to define the locations or paths from which PHP is allowed to access files using function like fopen() and gzopen(). If the file is outside of the location or paths defined by open_basedir, PHP will refuse to open and read it. You can also not use a symbolic link as a workaround because the path that the symbolic link resolves to falls under the restrictions of the open_basedir function.

The default open_basedir restrictions for shared Linux hosting accounts have no value. PHP scripts can access all directories within your hosting account.

You can turned off the open_basedir restrictions editing Apache configuration file httpd.conf using the following line : php_admin_value open_basedir none

Set open_basedir in Apache

You can set the open_basedir restriction in httpd.conf file like below.

php_admin_value open_basedir "/var/www/vhosts/httpdocs"

Set open_basedir globally

You can also set the open_basedir restriction globally editing php.ini file. Put the below line in php.ini fine.

open_basedir = /var/www/vhosts/httpdocs

Now restart the apache service to apply changes.

Set open_basedir in php.ini

To edit the open_basedir paths, open php.ini and add your directories using this format:

open_basedir = "/path/to/first/folder:/path/to/second/folder"

Verify open_basedir

You can create a phpinfo page under your document root path to verify the open_basedir set or not.

# cd /var/www/html/
# vim phpinfo.php
<?php phpinfo(); ?>

Save and closer file. Open your web browser and enter below URL and check the open_basedir value.

http://Domain_Name_or_IP_Address/phpinfo.php

phpinfo_page

Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website www.looklinux.com. To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author

mm

Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment