What should I do if the PHP open_basedir error occurs in the VestaCP panel?

Solving the PHP open_basedir error in the VestaCP panel

What is PHP open_basedir?

  • The PHP open_basedir protection tweak is a safe-mode security measure that prevents users from using PHP to open files or scripts located outside of their home directory, unless that folder has been explicitly excluded.
  • Enabling the PHP open_basedir setting will ensure that all file operations are restricted to files under a certain directory, preventing php scripts from a specific user from accessing files in unauthorized user accounts.
  • When the script tries to open the file with e.g. fopen() or gzopen(), the location of the file is checked.

There are more related tutorials on VestaCP panels here ▼

When a file exceeds the specified or allowed directory tree, PHP will refuse to open it, an error similar to the following may occur:

PHP Warning: require(): open_basedir restriction in effect. File(/home/admin/web/project/www/app/autoload.php) is not within the allowed path(s): (/home/admin/web/project/public_shtml:/home/admin/tmp) in /home/admin/web/project/www/web/app.php on line 6

PHP Warning: require(/home/admin/web/project/www/app/autoload.php): failed to open stream: Operation not permitted in /home/admin/web/project/www/web/app.php on line 6

PHP Fatal error: require(): Failed opening required '/home/admin/web/project/www/web/../app/autoload.php' (include_path='.:/usr/share/php') in /home/admin/web/project/www/web/app.php on line 6

Solution

Step 1: Access the corresponding domain name "WEB Service".

Step 2: Modify "Web Template HTTPD"

  • Please change "Web Template HTTPD" from "default" to "phpcgi" ▼

In the VestaCP panel, change "Web Template HTTPD" from "default" to "phpfcgid".

Step 3: Restart the Apache service using the following command ▼

service httpd restart

This is a common problem in Linux systems. Just follow the steps above; no code modification is required, and it can be quickly resolved in just 3 steps. It's very simple! ^_^

Attention points

  • Never choose "phpfcgid", because it is easy to consume too much memory and cause frequent 500 error problems.

If you insist on using the "phpfcgid" template, Chen Weiliang suggests optimizing its settings before use. ▼

Comment

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

Scroll to Top