How can I relax PHP's open_basedir restriction?

How can I relax PHP's open_basedir restriction?

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Relaxing open_basedir Restrictions in PHP

The open_basedir directive acts as a virtual chroot jail for PHP scripts, restricting file system access to specific directory trees defined in your server configuration. This is a critical security feature designed to prevent scripts from reading sensitive files outside their intended scope, such as /etc/passwd or private user directories. In your specific scenario, you are attempting to include libraries located at /var/www/vhosts/domain.tld/zend while your web root is restricted to /var/www/vhosts/domain.tld/httpdocs.

When PHP encounters an attempt to access a file outside these boundaries—such as when using realpath() or including a library—it throws an open_basedir restriction in effect error. The error message explicitly lists the allowed paths: (/var/www/vhosts/domain.tld/httpdocs:/tmp). Any path outside this list is blocked immediately.

To resolve this for your specific directory structure, you must modify the server configuration to include the zend directory within the allowed paths. Since you are using Apache with Plesk and have root SSH access, you have several options depending on where your application logic resides versus where the restriction is applied.

Modifying the Server Configuration

The most direct approach is to update the php.ini file or use a virtual host configuration block to append the required directories. If you are managing multiple domains via Plesk, editing the global php.ini might not be ideal if you want to keep configurations isolated per domain. Instead, consider creating a virtual host-specific configuration file (e.g., /etc/php.d/domain.conf or within the Apache .htaccess/php_vhost.ini equivalent in Plesk).

You need to edit the open_basedir directive to include both your current web root and the library directory. The syntax is a colon-separated list of absolute paths:

open_basedir = /var/www/vhosts/domain.tld/httpdocs:/var/www/vhosts/domain.tld/zend:/tmp

If you are using Plesk, navigate to Websites & Domains > select your domain > PHP settings. Look for the open_basedir setting. If it is set to a specific value or empty (inheriting global), you can input the combined path there. Ensure that the path includes the parent directories if necessary, though including the immediate parent of the library usually suffices:

open_basedir = /var/www/vhosts/domain.tld:/tmp

By including /var/www/vhosts/domain.tld, you effectively allow access to both httpdocs and zend since they share the same root. This is often cleaner than listing every subdirectory individually.

The Security Trade-off

Relaxing these restrictions introduces a specific security trade-off. By adding /var/www/vhosts/domain.tld/zend to the allowed list, you are acknowledging that the application has legitimate needs to read files from that location. However, you must ensure that:

  1. File Permissions: The files in the zend directory should still have restrictive permissions (e.g., 644 for config files and 755 for directories) so that only the web server process and potentially the owner can read or execute them.
  2. No Execution of Malicious Scripts: If your application logic inadvertently includes a file from a subdirectory within zend that was intended to be private, you must rely on file permissions rather than open_basedir to prevent unauthorized execution. The open_basedir check happens at the filesystem access level, but once inside the allowed tree, standard permission checks apply.

Alternative: Adjusting the Application Logic

Before altering server-wide configurations, evaluate if your application structure can be adjusted without changing php.ini. If the libraries are essential for multiple domains and cannot be copied into every web root, ensure that the open_basedir setting is configured globally or per-virtual host to include the shared library path.

If you are running PHP-FPM alongside Apache, remember that configuration changes in Plesk might apply only to the Apache module. You may need to check the PHP-FPM pool configuration as well. The directive must be present in the php-fpm.conf or the specific pool's php.ini override for the process handling your requests to recognize the new restrictions.

Conclusion

The error you are facing is a direct consequence of the strict path isolation enforced by open_basedir. By updating the configuration to include /var/www/vhosts/domain.tld/zend in the allowed paths, you grant your application the necessary permissions to load external libraries while maintaining the integrity of the rest of the filesystem. Just as with any security relaxation, verify that the added directory contains only trusted, static assets and does not expose sensitive data or allow unintended script execution. If you are managing a Laravel project specifically, ensuring that APP_PATH and storage directories are correctly aligned with these permissions is crucial for deployment stability.

Our network