php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71874 PHP cannot find mysql.sock file via web
Submitted: 2016-03-21 18:15 UTC Modified: 2016-03-28 06:25 UTC
From: jfha73 at gmail dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 7.0.4 OS: Fedora 23
Private report: No CVE-ID: None
 [2016-03-21 18:15 UTC] jfha73 at gmail dot com
Description:
------------
Hey guys,

I have a script trying to connect to a localhost database on mysql/mariadb but it gives me the error that cannot file mysql.sock message via web, when I run it via console it runs just fine, when I do a fsockopen("/tmp/mysql.sock", 3306); it opens it, but for some reason mysqli_connect cannot open that file to connect to MySQL, please check why PHP is doing this.

NOTE: it does work when run via console, just not the web, my firewall and selinux are both disabled.

Test script:
---------------
<?php
$link = mysqli_connect("localhost", "root", "password", "mysql");

if (!$link) {
    echo "Error: Unable to connect to MySQL." . PHP_EOL;
    echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
    echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
    exit;
}

echo "Success: A proper connection to MySQL was made! The mysql database is gre$
echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

mysqli_close($link);
?>


Expected result:
----------------
Show Success message.

Actual result:
--------------
Warning: mysqli_connect(): (HY000/2002): No such file or directory in /var/www/html/tests/mysql.php on line 3
Error: Unable to connect to MySQL. Debugging errno: 2002 Debugging error: No such file or directory

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-03-28 06:25 UTC] krakjoe@php.net
-Status: Open +Status: Not a bug
 [2016-03-28 06:25 UTC] krakjoe@php.net
I am 99.99999998% sure that this is not a bug. 

The CLI binary, and your web server binary (apache, fpm, or whatever) do not necessarily use the same configuration file (php.ini), or settings as both can be configured independently of php.ini, with SAPI specific (php-fpm.ini, php-apache.ini, etc), and server specific configuration methods.

If you can negotiate a connection in CLI, then there is no problem connecting to the server and you are looking at a misconfiguration issue.

If I'm wrong, please do re-open the bug. 

If you do reopen the bug, please include information about your web server, and maybe a screenshot of the relevant parts of phpinfo output (as executed by the web server), showing your mysqli configuration section.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Oct 27 07:03:33 2021 UTC