Page 1 of 1
[SOLVED] Connection Problem in linux
Posted: Mon Dec 01, 2003 4:02 pm
by dbudde
Ok, I have not been able to figure out why my php/apache server is not able to connect to my mysql server and they are all on the same linux box. I checked /etc/services and the mysql server is on port 3306 and I set that to the default port in php.ini, and "YES" both apache and mysql are up and running. Below is the code that I use straight from php.net.
<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
or die("Could not connect: " . mysql_error());
print ("Connected successfully");
mysql_close($link);
?>
The error im getting on the page is,
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111) in /srv/www/htdocs/login.php on line 68
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)
Please give me a hand. This is only my 2nd or 3rd venture into setting up these 2 servers to play together and I could really use some help.
Thanks, Daniel
Posted: Mon Dec 01, 2003 4:16 pm
by Pyrite
Can you connect to MySQL on the command line?
Are you positive MySQL is running?
I would say your user/pass might be wrong, but that would give you a different warning/error.
What distro are you running? Did you install binaries of MySQL, php and Apache or did you compile them from source?
Posted: Mon Dec 01, 2003 4:31 pm
by Pyrite
The port etc doesn't matter since you're setup is trying to connect to MySQL through sockets. A connection warning like that means that either the mysql server isn't up and running or the mysqld doens't have the right permission to the socket file or is connecting to the wrong one.
Have a look at:
http://www.mysql.com/doc/en/Can_not_con ... erver.html
Might make a symlink to your socket file.
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
Also might want to give your socket some permissions like:
chmod 755 /var/lib/mysql/mysql.sock
Thanks for the speedy replies
Posted: Mon Dec 01, 2003 4:42 pm
by dbudde
Yes, I can attach to MySql from the command prompt and yes it is on. Yes, my php/apache server is up and running or I would not reach my php pages.
I will try your answers about the sockets, but that sounds to be it. Thank you, I will drop a line later as to if it helped or did not help.
Posted: Mon Dec 01, 2003 4:54 pm
by Pyrite
ps aux | grep mysql
And if you see mysqld in the process list, then its running. Otherwise. Sometimes safe_mysqld won't tell you it can't start MySQL. But then you'll need to find out how you're starting it and what youre doing wrong. Either mysqld is a daemon or is handled by inetd. So if you were starting the mysql as a daemon in an init script suppose and you were passing it the wrong socket option or something...
Posted: Mon Dec 01, 2003 5:46 pm
by mrvanjohnson
Run this script real fast
Then search on that page for the MySQL section and make sure it says "Enabled" next to it. Just to make sure you have PHP compiled with MySQL support
Posted: Tue Dec 02, 2003 2:42 am
by Pyrite
He would of had to compile from source and old version of php4 for MySQL not be enabled.
I got it working
Posted: Wed Dec 03, 2003 12:41 am
by dbudde
Pyrite, thanks for your help. There were two copies of mysql.sock for some reason in two different directories. The php server was looking at the wrong one. I changed it in my php.ini file and now it seems to running with no problems, thanks for you help.
Posted: Wed Dec 03, 2003 4:18 am
by Pyrite
NP
