The open_basedir function defines the locations or paths from which PHP is allowed to access files using functions like fopen(), fwrite(), file_get_contents(), file_put_contents().
If a file path is outside the paths defined by open_basedir, PHP will refuse to open it - keeping your server safe from unauthorized access.
For example, a site can be hacked and infected with malware that wants to hack your whole server - open_basedir will prevent it - allowing a hacker to infect only that site - not the entire server.
However, sometimes your PHP scripts need to access the files outside your site's public_html folder.
In that case, you need to expand the open_basedir restriction of your site.
For example, let's say you want to put wide open_basedir for example.com domain.
First, check what PHP version you run on the example.com domain.
In your SSH run:
Code: Select all
sudo /usr/local/vesta/bin/v-get-php-version-of-domain example.com
Code: Select all
8.0
Now in your SSH, as root account, edit it's fpm conf file:
Code: Select all
sudo mcedit /etc/php/8.0/fpm/pool.d/example.com.conf
Now let's go to edit this conf file.
Now you will see this line:
That is a line:
Code: Select all
php_admin_value[open_basedir] = /home/admin/web/example.com/public_html:/home/admin/tmp:etc...
Code: Select all
php_admin_value[open_basedir] = /home/admin/web/example.com/public_html: ...
Code: Select all
php_admin_value[open_basedir] = /home/admin/web/example.com: ...
Code: Select all
php_admin_value[open_basedir] = /home/admin/web: ...
Code: Select all
php_admin_value[open_basedir] = /home/admin: ...
Press F2 on your keyboard and confirm saving:
Press ESC twice on your keyboard to exit the editor.
In the end, restart your PHP-FPM by running:
Code: Select all
sudo systemctl restart php8.0-fpm