
open_basedir is a PHP configuration directive used to restrict the directories that PHP scripts can access on the server. It’s a security measure to prevent PHP scripts from accessing files or directories outside of a defined set of paths.
Purpose:
It limits PHP’s file system operations (like fopen(), include(), require(), etc.) to a specified directory tree. This helps prevent unauthorized file access, especially in shared hosting environments.
How it works:
If open_basedir is set to /home/user/public_html/, then PHP scripts can only access files within that directory and its subdirectories.
Example in php.ini:
open_basedir = /home/user/public_html/:/tmp/
This setting allows PHP scripts to access files in /home/user/public_html/ and /tmp/ only.
What happens if a script tries to access a file outside this path?
PHP will throw a warning/error like:
Warning: open_basedir restriction in effect. File(/etc/passwd) is not within the allowed path(s)…
Where it can be set:
- php.ini (global)
- .htaccess (if using Apache with mod_php)
- httpd.conf
- Virtual host configurations
- Hosting control panels (like cPanel, Directadmin or Plesk)
Use Cases:
Shared hosting: Isolate users from each other.
Security: Prevent access to sensitive system files.
Custom apps: Lock scripts to a defined app folder.



