php -v shows different version than phpinfo() on IIS

  • 1 year ago
Comment

ChatGPTChatGPT
1 / 1

If the php -v command shows a different PHP version than what is displayed in phpinfo() when running PHP on IIS, it usually indicates that there are multiple PHP installations on your system or that the IIS PHP handler is configured incorrectly. Here are some steps to troubleshoot and resolve the issue:

  1. Check PHP Installation Locations: Verify the installation locations of PHP on your system. Make sure there is only one PHP installation directory. Look for multiple PHP installations in different locations (e.g., C:\Program Files\PHP, C:\PHP, etc.). Remove any duplicate or conflicting PHP installations.

  2. Review IIS PHP Configuration: Open the Internet Information Services (IIS) Manager and navigate to the PHP handler configuration. Confirm that the correct PHP module is selected and that the correct PHP installation directory is specified in the handler mapping.

  3. Restart IIS: After making any changes to the PHP handler configuration, restart the IIS web server to apply the changes.

  4. Check IIS Website Configuration: Ensure that the PHP handler mapping is properly configured for the specific website or virtual directory where you are experiencing the discrepancy. Verify that the correct PHP version and handler mapping are assigned to the website or virtual directory in IIS.

  5. Clear PHP Opcode Cache: If you have an opcode cache (e.g., OPcache) enabled, clear the cache to ensure that the PHP version changes take effect. Restart the web server after clearing the cache.

  6. Check PATH Environment Variable: Confirm that the PATH environment variable is correctly set and points to the PHP installation directory that you want to use. Open a command prompt and run echo %PATH% to check the PATH variable.

  7. Check PHP CGI Configuration: If you are using PHP as a CGI process instead of a module, review the CGI configuration in IIS. Confirm that the correct PHP executable is specified as the CGI handler.

By following these steps, you should be able to resolve the issue of php -v showing a different version than phpinfo() when running PHP on IIS. Ensure that you have a single, correct PHP installation, and that the IIS PHP handler and configuration are set up correctly for the desired PHP version.