Fixing 404 Error Loading Scripts in IIS 10 (Windows 10)
If you are running IIS 10 on Windows 10 and have PHP installed, you may encounter a 404 error when trying to load scripts through your web server. This issue can be frustrating, but it can be fixed with some simple configurations in your IIS server.
Understanding the Error
A 404 error typically means that the file or resource you are trying to access is not found. In this case, the web server is not able to locate the PHP scripts you are trying to load.
Checking File Permissions
The first thing you should check is the file permissions. Make sure that the PHP scripts have the correct permissions for the web server to access them. You can do this by right-clicking on the script file and selecting Properties. Go to the Security tab and check that the IIS AppPool\ <your app pool name> has read access.
IIS AppPool\ <your app pool name>
READ
Configuring Handler Mappings in IIS
If the file permissions are correct, the next thing to check is the handler mappings in IIS. Handler mappings tell IIS which ISAPI extension to use to handle a specific file type. In this case, we need to make sure that the PHP ISAPI extension is mapped to the .php file extension.
To do this, open IIS Manager and navigate to the site where the PHP scripts are located. Right-click on the site and select Handler Mappings. Check if the PHP_via_FastCGI handler is mapped to the .php file extension.
Function Name: PHP_via_FastCGI
Request Path: *.php
Type: Application
Checking FastCGI Settings
After configuring the handler mappings, we need to check the FastCGI settings in IIS. FastCGI is a protocol used by IIS to communicate with the PHP executable.
To check the FastCGI settings, open IIS Manager and navigate to the site where the PHP scripts are located. Right-click on the site and select FastCGI Settings. Make sure that the PHP executable is listed and that the Monitor Changes option is checked.
Full Path: <path to php exe>
Monitor Changes: Checked
Testing the PHP Scripts
After configuring the handler mappings and FastCGI settings, it's time to test the PHP scripts. Create a simple PHP script in the site's root directory and try to access it through your web browser. If the PHP script loads correctly, then the 404 error is fixed.
-
Check the file permissions of the PHP scripts to make sure that the web server has read access.
-
Configure the handler mappings in IIS to tell the web server to use the PHP ISAPI extension for .php files.
-
Check the FastCGI settings in IIS to make sure that the PHP executable is listed and that monitor changes is checked.
-
Test the PHP scripts by accessing them through your web browser.
References
-
Microsoft Documentation: Troubleshooting PHP on IIS
-
PHP Documentation: Installing PHP on IIS 7