Jump to content

Recommended Posts

Hello all, this is my first post here and I just first want to say thanks for having such a wonderful site with lots of information.  Now to the point:

 

On our server at work we are running the following:

-Apache 2.2.3-11 (httpd-2.2.3-11.el5_1.centos.3)

-PHP 4.4.9 (built on the machine --with-mysql --with-apxs)

-MySQL 4.1.22 (MySQL-client-standard-4.1.22-0.rhel3.x86_64.rpm & MySQL-server-standard-4.1.22-0.rhel3.x86_64.rpm)

 

The older version of mysql is needed to support some older software we have.

 

The Problem:

Now the delima is as follows.  I can connect to mysql when I run my php scripts from the command line, but when I access the php script using a web browser the script reports "Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)".

 

Now this mysql.sock file does exist, and is connected to when the script is run from the command line.  Does this mean some user/group permissions need to be changed? And if so where?  I have been tackling this problem for days and am getting very frustrated lol.

 

The php script

--------------------------------------------------

<?php

echo "This is a test php script:<br>\n";

 

if(!($conn = mysql_connect("localhost","*****","*****")))

{

        echo "Did not connect!<br>\n";

}

 

echo "Done Script!\n";

?>

----------------------------------------------

 

Output when run from command line:

----------------------------------------------

[root@m0bugz2 php-4.4.9]# php -f /var/www/html/dm/testsimple.php

This is a test php script:<br>

Done Script!

----------------------------------------------

 

Output when run from webbrowser: http://dhcp-199.********.ca/dm/testsimple.php

----------------------------------------------

This is a test php script:

Did not connect!

Done Script!

----------------------------------------------

 

 

Thanks in advance to all who reply!

 

The output from the command line is indicating that php is connecting to mysql.  So the php-mysql shouldn't be related to the Apache problem should it?

 

The reason I am not doing a "yum install php-mysql" is because it then wants to upgrade my mysql to a 5.x version which I can't do due to legacy software which can't have a mysql > 4.1.

 

Modules Installed by php:

ctype

ionCube Loader

mysql

overload

pcre

posix

session

standard

tokenizer

xml

 

Since mysql appears to be a php module it shouldn't need a php-mysql install anyways.  Correct me if I am wrong.

http://isoredirect.centos.org/centos/3/updates/i386/RPMS/

 

You can use "Parent Directory" to go back and get your correct version of CentOS 3.x and then go to updates/arch/RPMS/ and get php-mysql

 

Then use yum localinstall php-mysql-ver.ent.arch.rpm

Awesome.  It would be still nice to understand why the localhost didn't work.  I think it has to do with permissions, as when I set Apache to use user:mysql group:mysql then it worked using localhost (I just tested this).  But I will forget about persueing that fix and use this new approach. 

 

Thank you to everyone who replied, and those tips will come in handy for searching for other rpm's.

 

~Randy (Shadarap)

I think it has to do with permissions, as when I set Apache to use user:mysql group:mysql then it worked using localhost (I just tested this).  But I will forget about persueing that fix and use this new approach.

 

Yeah, I should have mentioned that my suggestion is just a quick hack, not a solution to the issue. Connecting to mysql via the local socket is apparently quicker than using tcp/ip, though I'm sure in most cases the difference would be negligible.

  • 3 years later...

Hello,

I know this is an old topic, but I just had the same issue.

 

Fortunaltely, it was solved by using 127.0.0.1 instead of localhost.

 

But have you found a better solution since?  Using the socket is certainly abetter way to do this...

 

By the way, my socket is there and functions, and I can connect to mysql without any problem from the command line (with mysqladmin for example).

 

Could the problem bue aproblem of permissions on the socket itself?  When I am at command line, I am root, but PHP/Apache uses www-data I assume...

 

Thanks

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.