0

The PHP version is "PHP 7.4.30", MariaDB version (mysql Ver 15.1 Distrib 10.6.8-MariaDB, for Linux (x86_64) using readline 5.1). and I am using Centos 7.

When I run the file locally it works but when I run the same file on the browser it shows the 500 error https://passimage.in/i/9fd1937c0a5d389b447e.png and in error_log I see "PHP Fatal error" Here is the example code

$mysqli = mysqli_connect('localhost','my_user','my_password','my_db', 'port', '/path/mysql/mysql.sock');
if ($mysqli->connect_error) {
  echo "Failed to connect to MySQL: (".$mysqli->connect_errno.")". $mysqli->connect_error;
  exit();
}
else {
  echo "connected";
}

The error i see is


[Mon Aug 08 08:07:54.188110 2022] [proxy_fcgi:error] [pid 21030] [client 59.92.251.25:56390] AH01071: Got error 'PHP message: PHP Fatal error:  Uncaught Error: Call to undefined function mysqli_connect() in /home/deep/public_html/wpinfo.php:15\nStack trace:\n#0 {main}\n  thrown in /home/deep/public_html/wpinfo.php on line 15\n'

In /etc/php.ini i have uncommented extension=mysqli

the mysqli is installed https://passimage.in/i/c9a19a98cdc1627f2420.png, but the default port and path are different. but in my /etc/my.cnf file the port and socket path is set. In the Database, I can see the port is set https://passimage.in/i/c994d99f4fc812c6a0ca.png. Is it causing the issue? if yes how to change it?

any help would be appreciated thank you!

  • Change the first parameter to add the port: `mysqli_connect('localhost:3307',...` – Paul T. Aug 07 '22 at 21:16
  • Display All PHP Errors then tail the server using this command as you open the page *tail -f /var/log/apache2/error.log* . A more verbose error message could be displayed and possibly give direction – Osoro Aug 07 '22 at 21:21
  • Make sure you edit the correct `php.ini` for your webserver (run a file with `` to get the path). Restart your webserver after enabling PHP extensions – brombeer Aug 07 '22 at 21:25
  • @PaulT. How will that help if the function isn't even defined? – Barmar Aug 07 '22 at 21:40
  • Please edit your question and show [**the error logs you have read**](https://stackoverflow.com/questions/5127838/where-does-php-store-the-error-log-php-5-apache-fastcgi-and-cpanel) – Martin Aug 07 '22 at 21:42
  • @Barmar ... well, I guess I only covered 1/2 the picture. I should have asked about restarting the webserver too, at least. – Paul T. Aug 07 '22 at 21:43
  • @PaulT. wouldn't it be better to update the `php.ini` settings with the correct port? 3306 is the default, 3307 is not. – Martin Aug 07 '22 at 21:46
  • @Martin ... sure, but I don't know what install set 3307. – Paul T. Aug 07 '22 at 22:22
  • @Martin: i have updated the error logs – chandana Gowda Aug 08 '22 at 15:15
  • @PaulT. i have added the port `mysqli_connect('localhost:3307',...` but i still face the same error on browser – chandana Gowda Aug 08 '22 at 15:18

0 Answers0