MySQL extension not loading in PHP web pages on IIS server

I’ve configured IIS 6.0 with PHP 5.2.8 and MySQL 5.1.30 on Windows Server 2003. PHP scripts run fine through the web server, but I’m getting errors when trying to use MySQL functions.

The errors I see are:
Fatal error: Class ‘mysqli’ not found
Fatal error: Call to undefined function mysql_connect()

When I check phpinfo() from a web page, there’s no MySQL or MySQLi information shown. But here’s the weird part - if I run PHP from command line like this:

> php -r phpinfo()

The MySQL and MySQLi sections show up perfectly in the output.

I’ve tried restarting IIS and the server but nothing changes. There’s only one php.ini file in my PHP installation folder. Is there something special I need to configure to make MySQL work with IIS, or what could be causing this difference between command line and web server behavior?

Had this exact issue moving from Apache to IIS. The problem? IIS doesn’t inherit environment variables that command line PHP uses. Here’s what fixed it for me: add the MySQL bin directory to your system PATH (not user PATH). IIS runs under different security contexts and needs explicit access to MySQL client libraries. You’ll need to restart the whole server after updating PATH - just restarting IIS won’t cut it. Also, use the full absolute path for extension_dir in your php.ini instead of relative paths. IIS handles relative paths differently than CLI does.

classic iis issues, huh? probably a misconfiguration on which php.ini it’s using for the web. also check permissions, sometimes the IIS process can’t read the .dll files even if they’re there. had luck once by copying php_mysql.dll to system32. worth a shot!

Check the php.ini file used by IIS, as discrepancies can arise between CLI and web configurations. Ensure that the MySQL extension lines are uncommented:

extension=php_mysql.dll
extension=php_mysqli.dll

Also, verify that the extension_dir path is correctly set with forward slashes or double backslashes, as Windows path issues can prevent extensions from loading. When I faced a similar transition from Apache to IIS, granting the IUSR account explicit read permissions to the entire PHP directory resolved the loading issue. After adjusting settings, perform an iisreset to clear cached configurations.

It appears that IIS might be using a different php.ini file compared to your command line version. Even if you indicated there’s only one php.ini in your PHP folder, IIS could be accessing another location or applying default settings.

I experienced the same issue years ago. To solve it, I directly set the PHPIniDir directive in IIS to ensure it points to the php.ini that includes MySQL extensions.

Also, double-check that the MySQL extension files (php_mysql.dll and php_mysqli.dll) are present in your PHP extensions directory. It’s essential that the extension_dir in php.ini is correctly configured as well, as Windows Server setups sometimes misconfigure these paths.

Lastly, ensure that IIS has the necessary permissions to access both the php.ini file and the extension directory, as the IIS process requires read access for both.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.