Fehlermeldung "PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect()" lösen

Auf einem Windows-Server mit Apache und PHP 8 erhalte ich beim Aufruf von WordPress die Fehlermeldung:

PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect()

Ausschnitt aus Fehlerprotokoll:

[php:error] [pid 4092:tid 1356] [client ::1:52680] PHP Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\Websites\Intranet\wp-includes\wp-db.php:1685\nStack trace:\n#0 C:\Websites\Intranet\wp-includes\wp-db.php(632): wpdb->db_connect()\n#1 C:\Websites\Intranet\wp-includes\load.php(558): wpdb->__construct()\n#2 C:\Websites\Intranet\wp-settings.php(124): require_wp_db()\n#3 C:\Websites\Intranet\wp-config.php(116): require_once(‚…‘)\n#4 C:\Websites\Intranet\wp-load.php(50): require_once(‚…‘)\n#5 C:\Websites\Intranet\wp-blog-header.php(13): require_once(‚…‘)\n#6 C:\Websites\Intranet\index.php(17): require(‚…‘)\n#7 {main}\n thrown in C:\Websites\Intranet\wp-includes\wp-db.php on line 1685

Ich habe gegoogelt wie doof, z. B. habe ich auch das hier gefunden:

Auch die Anpassung von extension_dir auf einen absoluten Pfad in der PHP.INI hat leider nicht geholfen.

Lösung

Lösung war dann, dass der Apache-Prozess keinen ACL-Zugriff auf den Extensions-Ordner im Dateisystem hatte.

Ich habe dann entsprechenden Zugriff auf „C:\Program Files\PHP“ gegeben, anschließend lief WordPress korrekt durch.

Ich hatte ähnliche Fehlermeldungen im Ereignisprotokoll:

PHP Warning: PHP Startup: Unable to load dynamic library ‚php_pdo_sqlite.dll‘ (tried: c:\Program Files\Php\ext\php_pdo_sqlite.dll (The specified module could not be found), c:\Program Files\Php\ext\php_php_pdo_sqlite.dll.dll (The specified module could not be found)) („C:\Program Files\Apache24\bin\httpd.exe“ -d „C:/Program Files/Apache24“)

PHP Warning: PHP Startup: Unable to load dynamic library ‚php_curl.dll‘ (tried: c:\Program Files\Php\ext\php_curl.dll (The specified module could not be found), c:\Program Files\Php\ext\php_php_curl.dll.dll (The specified module could not be found)) („C:\Program Files\Apache24\bin\httpd.exe“ -d „C:/Program Files/Apache24“)

PHP Warning: PHP Startup: Unable to load dynamic library ‚php_pdo_sqlite.dll‘ (tried: c:\Program Files\Php\ext\php_pdo_sqlite.dll (The specified module could not be found), c:\Program Files\Php\ext\php_php_pdo_sqlite.dll.dll (The specified module could not be found)) („C:\Program Files\Apache24\bin\httpd.exe“ -k runservice)

PHP Warning: PHP Startup: Unable to load dynamic library ‚php_curl.dll‘ (tried: c:\Program Files\Php\ext\php_curl.dll (The specified module could not be found), c:\Program Files\Php\ext\php_php_curl.dll.dll (The specified module could not be found)) („C:\Program Files\Apache24\bin\httpd.exe“ -k runservice)

Und konnte mithilfe dieser Antwort eine Lösung realisieren:

windows 7 - Curl extension not working - PHP Warning: PHP Startup: Unable to load dynamic library php_curl.dll - Server Fault

Lösung

Die Lösung war dann:

  1. Pfad zu PHP (und somit den Hilfs-DLLs, die er nicht laden konnte) ermitteln. Z. B. „C:\Program Files\PHP“.
  2. Diesen Pfad in der systemweiten Umgebungsvariable PATH ergänzen.
  3. Den Server neu booten.

Anschließend wurden die DLLs wie z. B. „libsqlite3.dll“ korrekt gefunden vom Apache-Prozess.

Ein anderer, ähnlicher Fall bei einem Kunden war verursacht durch falsche Groß-/Kleinschreibung im Pfad zum Modul in der Apache-Konfigurationsdatei.

Schlecht:

LoadModule php_module "C:/program files/php/php8apache2_4.dll"

Gut:

LoadModule php_module "C:/Program Files/php/php8apache2_4.dll"