Causes
This error typically occurs when the web server cannot find the specified PHP file or script. Possible causes include:
-
open_basedirrestriction : Check the.user.inifile in the website's root directory. Theopen_basedirvalue might not include the directory paths your website requires. -
Incorrect rewrite rule configuration : Check the rewrite rules in the website's configuration file. The rules might be incorrectly redirecting requests to a non-existent PHP file.
-
Incorrect PHP handler configuration : Check the settings related to the PHP runtime mode in the website's configuration file. The web server might fail to pass requests to the PHP handler correctly.
Solutions
Linux
This procedure uses Alibaba Cloud Linux 3 as an example.
Log on to an ECS instance.
Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target instance.
Navigate to the details page of the target instance. Click Connect and select Workbench. Follow the on-screen prompts to access the terminal.
-
Check for
open_basedirrestrictions.-
Check whether the hidden configuration file
.user.iniexists in the website's root directory.sudo ls -la <website_directory>For example, if the website's root directory is
/www/wwwroot/www.abc.com/, runsudo ls -la /www/wwwroot/www.abc.com/.-
If the file exists, continue to the next step to check for
open_basedirrestrictions. -
If the file does not exist, the website is not affected by
open_basedirrestrictions. Proceed to modify the configuration file.
-
-
Check the
open_basedirsettings.In the
.user.inifile, find the line that starts withopen_basedirand check whether the directory list on the right of the equals sign includes your website's full root directory path.For example, if your website's root directory is
/www/wwwroot/www.abc.combut the.user.inifile containsopen_basedir=/www/wwwroot/www.test.com/:/tmp/, it means the path to the website's root directory is missing and you must add it.
-
-
Modify the configuration file.
Apache
-
Check and correct the
.htaccessfile.Go to the website's root directory and check if a
.htaccessfile exists. If it does, ensure theRewriteRuleline is configured as follows.This ensures that requests are correctly redirected to
index.php.RewriteRule ^(.*)$ /index.php?/$1 [L] -
Restart the Apache service.
sudo systemctl restart httpd
Nginx
-
Check and correct the php.ini configuration.
Edit the
/etc/php.inifile and ensure that thecgi.fix_pathinfoparameter is set to1.The default value is 1. With this setting, PHP attempts to load an existing file that matches the URL, which improves compatibility.
-
Check and correct the
fastcgi.confconfiguration.Edit the
/etc/nginx/fastcgi.conffile and ensure it contains the following configuration. This ensures that the web server can correctly pass requests to the PHP handler.fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param DOCUMENT_ROOT $document_root; -
Restart the Nginx service.
sudo systemctl restart nginx
-
-
Verify that the website is accessible.
After applying the fixes, revisit your website to confirm it is accessible.
Windows
This procedure uses Windows Server 2022 with Internet Information Services (IIS) as an example.
Log on to an ECS instance.
Go to ECS console - Instances. In the top-left corner, select the region and resource group for the target instance.
Navigate to the details page of the target instance. Click Connect and select Workbench. Set the connection method to Terminal Connection, enter your username and password, and log on to the graphical terminal.
-
Check for
open_basedirrestrictions.-
Check whether the hidden configuration file
.user.iniexists in the website's root directory.In File Explorer, click the View tab and select the hidden items checkbox.
-
If the file exists, continue to the next step to check for
open_basedirrestrictions. -
If the file does not exist, the website is not affected by
open_basedirrestrictions. Proceed to troubleshoot the PHP handler configuration for IIS.
-
-
Check the
open_basedirsettings.In the
.user.inifile, find the line that starts withopen_basedirand check whether the directory list on the right of the equals sign includes your website's full root directory path.For example, if your website's root directory is
C:/inetpub/wwwroot/mywebsitebut the.user.inifile containsopen_basedir = "C:/inetpub/wwwroot/abc", it means the path is incorrect and you must correct it.
-
-
Troubleshoot the PHP handler configuration for IIS.
-
Edit the
php.inifile.-
Comment out the
doc_rootdirective.Add a semicolon (
;) to the beginning of thedoc_rootdirective line to comment it out.; if PHP was not compiled with FORCE_REDIRECT, you SHOULD set doc_root ; if you are running php as a CGI under any web server (other than IIS) ; see documentation for security issues. The alternate is to use the ; cgi.force_redirect configuration below ; http://php.net/doc-root ; doc_root = ; The directory under which PHP opens the script using /~username used only ; if nonempty. ; http://php.net/user-dir user_dir = -
Modify the
cgi.force_redirectdirective.Remove the semicolon (
;) from the beginning of thecgi.force_redirect = 1line, and change the value from1to0. This security measure for CGI setups must be disabled for IIS.; cgi.force_redirect is necessary to provide security running PHP as a CGI ; most web servers. Left undefined, PHP turns this on by default. You can ; turn it off here AT YOUR OWN RISK ; **You CAN safely turn this off for IIS, in fact, you MUST.** ; http://php.net/cgi.force-redirect cgi.force_redirect = 0 ; if cgi.nph is enabled it will force cgi to always sent Status: 200 with ; every request. PHP's default behavior is to disable this feature. ;cgi.nph = 1
-
-
Restart the IIS service.
Press
Win+R, enterPowerShell, and then pressEnter. In the PowerShell window, run the following command to restart the IIS service.iisreset /noforce
-
-
Verify that the website is accessible.
After applying the fixes, revisit your website to confirm that the issue is resolved.