Skip to content

Fix "open_basedir restriction in effect" on cPanel

Fix the PHP warning "open_basedir restriction in effect" on a cPanel server by reading the two paths in the message. You will find where the allowed list is set, correct the path your site uses, and add a folder only when the site truly needs it.

Your PHP error log on a cPanel server shows “open_basedir restriction in effect. File(/some/path) is not within the allowed path(s)”, and an upload, an export or a login on the site fails. open_basedir is a PHP setting that limits scripts to a list of folders, and PHP has refused to touch a file outside that list. The message names both sides: the path PHP tried, and the list it may use. If the path holds an old account folder left by a migration, correct the path your site uses. If it is a temp or session folder the site needs, add that folder to the list. Switch the limit off only as a last choice, because every script on the site can then open any file its user can read.

What you’ll accomplish

  • Split the warning into the path PHP tried, the allowed list, and the file that asked.
  • See the open_basedir value your website really runs with.
  • Find which file sets the value on a cPanel server, and who can change it.
  • Match the blocked path to one of five causes and apply the fix for that cause.
  • Confirm the fix with a test request and a quiet error log.

Prerequisites

  • A cPanel account with Terminal (cPanel → Advanced → Terminal) or SSH. The steps marked “root” need WHM or root SSH; on shared hosting, send those to your host.
  • PHP 7 or 8. The warning text is the same in both.
  • WP-CLI, only for the two WordPress commands in cause A.
  • Example values used below: current account shopca, previous account shopold, domain example.com, document root /home/shopca/public_html, PHP 8.3 from EasyApache 4 (ea-php83). Replace them with yours.

How it works

Each time a script opens, includes or writes a file, PHP compares the file’s location with the folders listed in open_basedir. A file inside one of those folders, at any depth, passes. Anything else is refused with this warning, and a file open then fails with “Operation not permitted”. When the setting is empty, PHP checks nothing, and that is PHP’s default.

Three details of PHP’s behaviour explain the common surprises:

  • On Linux the folders are separated by colons. Each entry is a directory name, not a text prefix, so /home/shop does not also allow /home/shopca.
  • PHP resolves symbolic links (shortcuts that point to another folder) before it compares. A link inside your home folder that points outside the list is refused.
  • A script can make the list narrower while it runs, with ini_set(), but never wider. A .user.ini file follows the same one-way rule once a list is set higher up.

Annotated example output of the open_basedir warning. Part 1, the path PHP tried, sits under the old account shopold and is marked with a cross. Part 2 is the allowed list, /home/shopca and /tmp. Below, one question: should the site use path 1? No leads to fixing the path in the app; yes leads to adding the folder where the list is set.

The diagram shows where the two parts sit in the message, and the one question that picks your fix. Part 1, inside File(...), is the path the script asked for. Part 2, in the last brackets, is the list in force for that request.

On cPanel, the list usually comes from one of three places. The first is a php.ini, .user.ini or .htaccess file inside the account, which cPanel’s MultiPHP INI Editor writes. The second is the server-wide php.ini of one PHP version. The third is the domain’s PHP-FPM pool (PHP-FPM is the service that keeps PHP workers running per domain). Older tutorials send you to a WHM screen named PHP open_basedir Tweak. cPanel removed that screen in version 76 for servers on EasyApache 4, and its support articles now point to MultiPHP INI Editor.

Step-by-step

  1. Get the full message from the log. With PHP-FPM, cPanel’s default log is ~/logs/ plus the domain with dots turned into underscores, ending in .php.error.log. With other handlers the location depends on the error_log setting, and it is often a file named error_log beside the script.
grep -h "open_basedir restriction" ~/logs/*.php.error.log ~/public_html/error_log 2>/dev/null | tail -n 2

Example output:

[27-Nov-2026 09:41:26 UTC] PHP Warning:  file_put_contents(): open_basedir restriction in effect. File(/home/shopold/public_html/wp-content/uploads/a.pdf) is not within the allowed path(s): (/home/shopca:/tmp) in /home/shopca/public_html/wp-content/plugins/acme-export/export.php on line 88

If nothing prints, the log is somewhere else. Ask your host where PHP errors go for this domain, then run the same grep on that file.

  1. Compare the two paths. Copy the path from File(...) and the list from the last brackets. Then test whether the folder exists and where it really leads.
ls -ld /home/shopold/public_html/wp-content/uploads
readlink -f /home/shopca/public_html/wp-content/uploads

Example output:

ls: cannot access '/home/shopold/public_html/wp-content/uploads': No such file or directory
/home/shopca/public_html/wp-content/uploads

Here the old folder is gone, and readlink -f printed the same path back, so no link is involved. Use the first row that matches to pick your cause:

What the blocked path looks likeCause
It holds an old username or an old document rootA
It is under /tmp, /var/tmp or another temp folderB
It holds sessions, and the function is session_start()C
It looks inside the list, but readlink -f prints a folder outside itD
It is a real folder outside the home folder that the site must useE
  1. See the value the website really uses. Create a small check file in the document root and request it over the web.
cat > ~/public_html/obd-check.php <<'PHP'
<?php
header('Content-Type: text/plain');
foreach (['open_basedir', 'upload_tmp_dir', 'session.save_path'] as $k) {
    echo $k, ' = ', var_export(ini_get($k), true), "\n";
}
echo 'sys_get_temp_dir = ', sys_get_temp_dir(), "\n";
echo 'SAPI = ', PHP_SAPI, "\n";
PHP
curl -s https://example.com/obd-check.php

Example output:

open_basedir = '/home/shopca:/tmp'
upload_tmp_dir = ''
session.save_path = '/var/cpanel/php/sessions/ea-php83'
sys_get_temp_dir = /tmp
SAPI = fpm-fcgi

Every folder named on lines 2 to 4 must sit inside a folder from line 1. Here the session folder does not, so this site also has cause C waiting. An empty open_basedir line means no list is set for web requests. The log entry is then old, or the calling script sets its own list with ini_set(). The last line names the PHP handler, and fpm-fcgi means PHP-FPM.

Do not trust php -i | grep open_basedir or wp eval 'echo ini_get("open_basedir");' here. Both run PHP from the command line, outside the PHP-FPM pool, so they can print a different value. Our guide on checking the PHP version on the web and on the command line explains the split.

  1. Find where the value is set. Start inside the account:
grep -n "open_basedir" ~/.user.ini ~/php.ini ~/public_html/.user.ini ~/public_html/php.ini ~/public_html/.htaccess 2>/dev/null

Example output:

/home/shopca/public_html/.user.ini:6:open_basedir = /home/shopca:/tmp

A hit means the account sets the value, and you can change it yourself in step 5. No output means it is set at server level. As root, check the PHP version’s own file and the PHP-FPM settings:

grep -n "open_basedir" /opt/cpanel/ea-php83/root/etc/php.ini
grep -rn "open_basedir" /var/cpanel/userdata/shopca/ /var/cpanel/ApachePHPFPM/ 2>/dev/null

Example output:

310:;open_basedir =
/var/cpanel/userdata/shopca/example.com.php-fpm.yaml:3:php_admin_value_open_basedir: { name: 'php_admin_value[open_basedir]', value: "/home/shopca:/tmp" }

A line that starts with ; is switched off. In this example the pool file for example.com sets the list. cPanel’s documented default pool settings do not include open_basedir, so a line like this was added by whoever runs the server. A hit under /var/cpanel/ApachePHPFPM/ applies to every PHP-FPM domain. If all three commands print nothing but step 3 showed a list, ask your host where it is set.

Cause A: a path from the old account or old document root

A migration or an account rename moves the files, but stored paths keep the old location. In WordPress, one such place is the upload_path option, which can hold a full path.

cd ~/public_html
wp option get upload_path

Example output:

/home/shopold/public_html/wp-content/uploads

Empty it, and WordPress goes back to its own wp-content/uploads folder:

wp option update upload_path ''

Example output:

Success: Updated 'upload_path' option.

If wp option get printed an empty line, or the app is not WordPress, the old path is stored in a file. Cause A in our article on the “Failed to open stream” error gives the search commands for that case.

Cause B: a temp folder outside the list

The blocked path is under /tmp or the folder printed as sys_get_temp_dir, and the list does not include it. For WordPress’s own temp files, such as update downloads, point WordPress at a folder inside the account. Create it, which prints nothing, then add one line to wp-config.php above the “That’s all, stop editing” comment:

mkdir -p ~/tmp
define( 'WP_TEMP_DIR', '/home/shopca/tmp' );

Browser uploads are different, because PHP stores them itself before WordPress starts. The PHP manual states the rule: when open_basedir is on, the system temp folder must be in the list for uploads to work. upload_tmp_dir can only be set at server level, so an account’s .user.ini cannot change it. Either root sets it to a folder in the list, or the temp folder is added as in step 5. Our guide to the “Missing a temporary folder” error covers PHP’s temp folder in full.

Cause C: the session folder is outside the list

The warning comes from session_start() and names the folder from session.save_path. By default, cPanel keeps PHP sessions under /var/cpanel/php/sessions, with a subfolder for each PHP version, and removes old ones with its own scheduled script. A list that holds only the home folder shuts PHP out of it. The clean fix is to add the session folder from step 3 to the list (step 5). Moving sessions into the home folder also works. cPanel’s cleanup script reads the session folder from the server-wide php.ini, so ask your host how old files will be removed from yours.

The path in the message looks fine, yet readlink -f in step 2 printed a different folder, for example /mnt/media/uploads. PHP compares the real location, not the link. Move the data back inside the home folder, or add the folder that readlink -f printed to the list.

Cause E: a real folder the site needs

Some sites read a shared library folder or a storage mount on purpose. Confirm the path with whoever built the site, then go to step 5.

  1. Add a folder to the list, in the place that sets it. Write the complete list, colon-separated, with no spaces. Keep every existing entry and add only the folder your site needs, never /.
  • Set in the account (step 4, first command). Open cPanel → Software → MultiPHP INI Editor → Editor Mode, then choose the domain or Home Directory. Edit the open_basedir line and click Save. Leave out quotation marks, which cPanel’s page for this editor lists among the characters it does not accept. PHP re-reads .user.ini files every 300 seconds by default, so wait five minutes before you test.
  • Set in the PHP version’s php.ini (root). Open WHM → Software → MultiPHP INI Editor → Editor Mode, select the PHP version, edit the open_basedir line and save. This value applies to every site on that PHP version.
  • Set in the PHP-FPM pool (root). Edit the existing open_basedir line in the .yaml file that step 4 printed. cPanel warns that a syntax error in these files can stop the service, so copy the file first. Change only the text inside value: "...", then rebuild and restart with cPanel’s scripts:
cp -a /var/cpanel/userdata/shopca/example.com.php-fpm.yaml /root/
/usr/local/cpanel/scripts/php_fpm_config --rebuild
/usr/local/cpanel/scripts/restartsrv_apache_php_fpm
/usr/local/cpanel/scripts/restartsrv_httpd

Each command should end without an error. If one reports an error, put the copy back and run the three scripts again. Leave the generated .conf files under /opt/cpanel/ea-php83/root/etc/php-fpm.d/ alone, because cPanel builds them from the .yaml files.

Validate it works

  1. Request the check file again and confirm the first line holds the list you expect:
curl -s https://example.com/obd-check.php

Example output:

open_basedir = '/home/shopca:/tmp:/var/cpanel/php/sessions/ea-php83'
upload_tmp_dir = ''
session.save_path = '/var/cpanel/php/sessions/ea-php83'
sys_get_temp_dir = /tmp
SAPI = fpm-fcgi

If the first line has not changed, you edited a file that this domain does not read. Go back to step 4.

  1. Repeat the action that failed. Upload the file, run the export or log in again. It should finish with no error on screen.

  2. Confirm the log stays quiet. Count the warnings, use the site for a few minutes, and count again. The command prints one number per log file, and none of them should grow.

grep -hc "open_basedir restriction" ~/logs/*.php.error.log ~/public_html/error_log 2>/dev/null
  1. Delete the check file. It shows server paths to anyone who guesses its name.
rm ~/public_html/obd-check.php

Troubleshooting

  • The value does not change after you save. Under PHP-FPM, a pool value written as php_admin_value is fixed for the request; the PHP manual says code cannot override it with ini_set(). Change it in the pool .yaml file and rebuild, as in step 5.
  • You widened the list in .user.ini, but the old list still applies. A lower level can only narrow a list set higher up. Find that level with the root commands in step 4 and change it there.
  • The warning names a path that is in the list. Check for a symbolic link with readlink -f (cause D). Also search the code for ini_set('open_basedir', because a plugin can narrow the list while it runs.
  • Warnings appear only for cron jobs or WP-CLI. Those run PHP from the command line, outside the PHP-FPM pool. Run php -i | grep open_basedir as the account user to see that value.

When this is the wrong approach

If the blocked path is one you do not recognise, such as /etc/passwd, another account’s home folder or /proc, do not add it. The limit may have stopped injected code, so check the calling file named in the message before you change anything. Removing open_basedir completely is reasonable only when another layer already separates the accounts, for example each site running as its own user with tight file permissions. The PHP manual calls open_basedir an extra safety net that cannot be relied on when security is needed. On a server that hosts many sites, keep it, and keep the list short.

The PHP manual entry for open_basedir and cPanel’s page on managing php.ini directives with PHP-FPM are the references behind these steps.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.