open_basedir problem on servers with Plesk

Solution to a problem in domains hosted on servers with the Plesk control panel, related to the PHP directive open_basedir.

We are using a new server that has support for PHP 5. (So far we were working with PHP 4, but it was time to change). As always, migrating to a new server brings its problems, but fortunately with the help of technical support and with the documentation found on the Internet, they are being fixed.

In this article I want to explain an error that we have encountered when configuring the domain, which I have later seen is common to many people who have the Plesk control panel as server resource manager. So I am going to try to express the problem and the solution that we have found.

The problem with open_basedir

Plesk has its own configuration of the PHP directive open_basedir (which is defined in the php.ini). Due to the Plesk configuration of open_basedir, you can only include files that hang from the domain’s publishing directory, that is, the domain’s httpdocs directory.

The state of open_basedir configured by Plesk by default is as follows:

open_basedir = “/var/www/vhosts/yourdomain.com/httpdocs:/tmp”

Due to this directive, files cannot be included (with the PHP include or require function) that are in other folders or subfolders that hang from those marked in open_basedir.

We have some folders that contain code outside of the publish directory and they were not being able to be included. That’s why we were getting a PHP error like this:

open_basedir restriction in effect. File(./../directory-outside-httpdocs/file.php) is not within the allowed path(s): (/var/www/vhosts/mydomain.com/httpdocs:/tmp)

See also  CSS Workshop

Then I have seen that this problem is also experienced by users who have codes included in PHP frameworks such as PEAR.

Solution to the problem: configure Plesk

The first approach to the solution was, of course, to modify the PHP.ini file. In fact, that’s what I thought would fix it. To change the open_basedir directive of the php.ini. But the changes did not take effect. I also tried changing the include_path directive, but that didn’t fix anything either.

After consulting with our provider’s technical support, they advised us to move all the folders to the publish directory, but that is not possible, for various reasons. But they gave us the hint that the problem was related to Plesk.

Finally, searching for Pear and Pesk on Google, a very interesting article appeared on a page in English:

In that article, what has to be done is expressed step by step, which I am going to summarize in Spanish, for the readers of to whom the same thing happens.

There is a file that Plesk uses to configure each domain, so you shouldn’t touch the php.ini, because that would affect the whole server (and not always, because some directives, like open_basedir, are then overridden by Plesk in separate files and no matter how much they are touched in the php.ini it will not have any effect).

There is a place where you must configure the php.ini changes, specific to each hosted domain. In my case, that configuration file was not created, so I had to create it. The specific configuration file for each domain is in the directory

See also  Javascript typeof operator for type checking

/var/www/vhosts/mydomain.com/conf

And the file that must be created there, or modified if it already exists, is:

vhost.conf

To make it work, the content of the file that I have placed is the following:


php_admin_value open_basedir “/var/www/vhosts/mydomain.com/httpdocs:/tmp:/var/www/vhosts/mydomain.com/directory_includes
php_admin_value display_errors On

It is simply a question of defining the open_basedir marking all the directories where there are files that are intended to be included from PHP. (Include a directory allows you to include files from all subdirectories inside)

In the above code you can see that we have modified another PHP parameter:

display_errors On (This is to be able to see the errors directly on the page, instead of the error log, which is more comfortable at least during tests and until the domain is finally migrated)

Now, we know where to go to configure PHP directives in the php.ini specific to a hosted domain. We can define all the directives that are needed. For example, another thing that may need to be changed is to override the safe_mode for a specific domain and that can be done from this same file with the line:

php_admin_value safe_mode Off

For the changes to take effect we still have to perform a couple of steps.

The first thing is to tell Plesk to update the configuration of a domain. This is done with the command:

/usr/local/psa/admin/sbin/websrvmng –reconfigure-vhost –vhost-name=mydomain.com

Now we will also have to restart apache, which can be done with the command:

/etc/init.d/httpd restart

Or with the command:

See also  Photoshop Gradient Tool

service httpd reset

This is it, now it should work. We hope .com readers have the same luck. It has gone well for us!

Loading Facebook Comments ...
Loading Disqus Comments ...