IIS (Internet Information Services) is a powerful web server developed by Microsoft, providing a stable and reliable environment to host websites and various applications. With proper configuration, IIS can seamlessly integrate with scripting languages such as PHP, expanding development flexibility and capabilities.
Before configuring IIS to support PHP, you need to properly install PHP. Here is the detailed installation process:
Visit the official PHP website and download the PHP package suitable for your server version.
Extract the downloaded PHP archive to a directory such as C:\PHP, and add this directory to your system environment variables so the system can recognize PHP commands.
setx PATH "%PATH%;C:\PHP"
After PHP is installed, configure IIS accordingly to enable PHP support.
Open IIS Manager, select your target site, go to “Handler Mappings,” and make sure the CGI feature is enabled. This step is critical for the server to process PHP requests.
Click “Add Module Mapping” in “Handler Mappings” and fill in the following:
Use the site’s “Configuration Editor” to adjust PHP-related settings such as maximum upload file size and default timezone. Here are some common php.ini configuration examples:
upload_max_filesize = 10M post_max_size = 10M date.timezone = "Asia/Shanghai"
Once configured, create a test PHP file to verify if the environment works properly. Create info.php in your website root directory with the following content:
<?php phpinfo(); ?>
Visit this file (e.g., http://yourdomain.com/info.php). If you see the PHP info page, the IIS and PHP configuration was successful.
By following these steps, you can set up a fully functional PHP environment on an IIS server. Regular maintenance and updates of the configuration will help ensure your website’s security and stability. Hopefully, this article helps you complete the IIS and PHP integration smoothly.