What is Open BaseDir and how it works?

Banko StoyanovJuly 2, 20252min0
zen6-coolice-host-PHP-Settings-1280x498.png

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.

Banko Stoyanov

This blogpost is written by Banko Stoyanov. Stoyanov is a Marketing manager at CooliceHost. Stoyanov holds an MBA in Marketing strategy and Business developing. He's passionate about data analysis, consumer behavior, cloud technology, and marketing. He is a lifelong learner who regularly keeps himself updated with the latest technologies and industry advancements. In his free time, he explores coffee scene and stays active through running and fitness. Find him on Linkedin and Facebook.


Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2026 – CooliceHost.com – All Rights Reserved.