Fix the PHP "open_basedir restriction in effect" error on LWS Panel

Procédure

  

Service concerned : shared web hosting LWS Panel
Panel concerned : LWS Panel
Level : intermediate

The error open_basedir restriction in effect appears when a PHP script tries to access a file or folder located outside the authorized space on your hosting.

It can occur in particular after migrating a website, because of an old path saved in the configuration, a misconfigured extension, or a custom script.

Before you begin

Keep a copy of the file before modifying it. You should also have the full error message in order to identify the refused path and the PHP file causing the problem.

Understanding the error message

The message may look like this example:

Warning: include(): open_basedir restriction in effect.
File(/home/ancien-hebergeur/public_html/config.php)
is not within the allowed path(s):
(/var/www/exemple.com/htdocs/:/tmp/)
in /var/www/exemple.com/htdocs/index.php on line 24

It contains several useful pieces of information:

  • /home/ancien-hebergeur/public_html/config.php is the file the script [ADDRESS] ;
  • /var/www/exemple.com/htdocs/ corresponds to the space in which your site's files can be used ;
  • /var/www/exemple.com/htdocs/index.php is the script [PERSON_NAME] to open the file ;
  • line 24 indicates the line concerned in this script.

In this example, the site is still using a path from an old hosting account. PHP therefore blocks access to the file.

Find the error in the PHP logs

If your site displays only a blank page or a 500 error, check the hosting logs:

  1. Open the Logs Apache / PHP tool.
  2. Reproduce the action that causes the problem on your site.
  3. Refresh the logs and look for the line containing open_basedir restriction in effect.
  4. Note the refused path and the PHP file indicated at the end of the message.

The most recent lines are generally found at the end of the log.

Fix the path used by the site

1. Check the file's real location

On LWS Panel, a site's public files are generally placed in a directory like this:

/var/www/votre-domaine.fr/htdocs/

Replace votre-domaine.fr with the domain name concerned.

Then check, from the file manager or by FTP, that the searched file is [PERSON_NAME] one of its subfolders.

2. Find the old path

The incorrect path may be stored:

  • in a configuration file ;
  • in a custom PHP script ;
  • in the settings of an extension or a theme ;
  • in the configuration of a cache, import, backup, or temporary files folder ;
  • in data kept after a migration.

First look for the distinctive part of the old path, for example:

/home/ancien-hebergeur/

Do not randomly modify the internal files of WordPress, PrestaShop, or another application. Start by checking the configuration of the extension or module indicated in the error message.

3. Replace the incorrect path

Replace the old path with the real path to the file on your LWS hosting.

For example:

Ancien chemin :
/home/ancien-hebergeur/public_html/cache/

Nouveau chemin :
/var/www/votre-domaine.fr/htdocs/cache/

In a custom PHP script, it is often better to build the path from the script's folder rather than storing the server's full path.

For example:

require __DIR__ . '/config.php';

This writing allows the script to look for config.php in its own folder.

The open_basedir directive cannot be modified or disabled from a .user.ini file on LWS Panel.

This protection must not be bypassed. You must correct the path used by the site, script, or extension.

4. Clear the application cache

After correcting the path, clear the cache from your CMS or application interface.

An old path may remain stored in a cache file, even after the configuration has been modified.

Check that everything works

Reproduce exactly the action that caused the error: open the relevant page, submit the form, or restart the interrupted operation.

Then check the PHP logs again. No new open_basedir restriction in effect line should appear.

The fix is complete when the relevant page or feature works again and no new open_basedir error appears in the PHP logs.

Common issues

I only see a 500 error or a blank page

The full message is probably recorded in the PHP logs. Open the Logs Apache / PHP tool from the LWS Panel, then reproduce the error before refreshing the log.

The indicated path corresponds to my old host

An absolute path was not updated during the migration. Search for this path in configuration files, extension settings, and custom scripts.

Replace it with the current path of your site [ADDRESS] Panel.

I can't find where the path is stored

Look at the name of the PHP file displayed at the end of the error message. It often helps identify the application, theme, extension, or script concerned.

For an extension, first check its cache, import, backup, or temporary files settings.

The file is located in the htdocs folder, [PERSON_NAME] continues

Check that the path used by the script exactly matches the file's real location.

A symbolic link can also appear to point to a file on the site while directing PHP to a location outside the allowed space. In this case, replace the link with direct access to a file located in the site's folder.

The error returns after the modification

Clear your application's cache, then reproduce the problem. Also check that the path is not stored in multiple places.

Rate this article :

This article was useful to you ?

Article utileYes

Article non utileNo

MerciMerci ! N'hésitez pas à poser des questions sur nos documentations si vous souhaitez plus d'informations et nous aider à les améliorer.


Vous avez noté 0 étoile(s)

Similar articles

0mn reading

Cloudflare Error 524 : A timeout occured

3mn reading

How to correct a 500 error on your site with LWS Panel

9mn reading

How do I correct HTTP error codes?

0mn reading

404 error, what it is and how to correct it


Questions sur cet article

Ask the LWS team and its community a question

RGPD : Responsable LWS-Ligne Web Services. Finalité : modération et publication publique de votre question, notification éventuelle d'une réponse. Base légale : consentement (art. 6.1.a RGPD). Conservation des emails : 90 jours après notification, 12 mois maximum sans réponse. Vous pouvez exercer vos droits via notre nos CGV - section RGPD.