Skip to main content

Drush open_basedir restriction error

PHP Warning:  include(): open_basedir restriction in effect. File(/usr/share/drush/includes/startup.inc) is not within the allowed path(s): (/var/www/vhosts/{domain}/:/tmp/) in /usr/share/drush/drush on line 113
PHP Warning:  include(/usr/share/drush/includes/startup.inc): Failed to open stream: Operation not permitted in /usr/share/drush/drush on line 113
PHP Warning:  include(): Failed opening '/usr/share/drush/includes/startup.inc' for inclusion (include_path='.:/opt/plesk/php/8.1/share/pear') in /usr/share/drush/drush on line 113
PHP Fatal error:  Uncaught Error: Call to undefined function drush_startup() in /usr/share/drush/drush:115
Stack trace:
#0 {main}
  thrown in /usr/share/drush/drush on line 115

 

The error message you're encountering indicates that PHP's open_basedir restriction is preventing your script from including a file outside the specified allowed paths. The open_basedir directive in PHP is used for security purposes, limiting the files that can be accessed by PHP to the specified directory-tree, which includes the file's directory and its subdirectories. In this situation, PHP is configured to only allow file operations within /var/www/vhosts/{domain}/ and /tmp/, but the script is trying to include a file from /usr/share/drush/includes/, which is not allowed under the current open_basedir configuration.

 

Steps to resolve this issue

Temporary solution

1. Check the PHP version

php -v

Response

PHP 8.2.16 (cli) (built: Feb 16 2024 11:02:00) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.16, Copyright (c) Zend Technologies
    with Zend OPcache v8.2.16, Copyright (c), by Zend Technologies

 

2. Set the export path

Knowing the PHP version from the previous command.. use it as follows:

export PATH=/opt/plesk/php/8.2/bin:$PATH;

 

3. Test Drush

Test if Drush is now running... using

drush status

Response

Drupal version   : 10.2.4
Site URI         : http://default
DB driver        : mysql
DB hostname      : localhost
DB port          : 3306
DB username      : {{some-db-username}}
DB name          : {{some-db-name}}
Database         : Connected
Drupal bootstrap : Successful
Default theme    : {some-theme}}
Admin theme      : {{some-admin-theme}}
PHP binary       : /opt/plesk/php/8.2/bin/php
PHP config       : /opt/plesk/php/8.2/etc/php.ini
PHP OS           : Linux
Drush script     : /var/www/{{some-domain}}/vendor/bin/drush
Drush version    : 12.4.4.0
Drush temp       : /tmp
Drush configs    : /var/www/{some-domain}}/vendor/drush/drush/drush.yml
Install profile  : complex
Drupal root      : /var/www/{some-domain}}

 

Permanent solution

1. Modify the open_basedir configuration

You need to add /usr/share/drush/ to the list of allowed paths in your open_basedir configuration. This can be done in different ways, depending on where the restriction is defined:

php.ini: Find your php.ini file (the location can vary depending on how PHP is set up on your system). Look for the open_basedir directive and modify it to include the path to drush, 

Currently the open_basedir is set to 

open_basedir = "/var/www/vhosts/{domain}/:/tmp/"

Updated to include :/usr/share/drush/

open_basedir = "/var/www/vhosts/{domain}/:/tmp/:/usr/share/drush/"

Apache or Nginx Configuration: If you're running PHP under a web server like Apache or Nginx, the open_basedir directive might be set in the virtual host configuration. Locate the configuration file for your site and add the path to drush in the open_basedir directive.
.user.ini or PHP-FPM pool configuration: If you're using PHP-FPM, you might have a .user.ini file or a specific pool configuration file (www.conf or a domain-specific configuration) where open_basedir is set. Add the path to drush similarly to the php.ini modification.

 

2. Use drush as a project-specific dependency

Another approach, which avoids modifying server-wide configurations, is to use drush as a project-specific dependency managed by Composer. This way, drush would be located within your project's directory structure, inherently complying with the open_basedir restrictions. To do this:

Navigate to your project's root directory.
Run composer require drush/drush.
Use the local version of drush for your Drush commands (located in vendor/bin/drush).

 

3. Review your workflow

If drush does not need to be called from the location triggering the error, consider adjusting your workflow to use drush from a location that is within the open_basedir paths, or from within your project as a Composer dependency.

After making these changes, restart your web server or PHP-FPM service for the changes to take effect. Always ensure to test your application thoroughly after making configuration changes to avoid unintended side effects.

 

Related articles

Andrew Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...