views:

365

answers:

1

Ok, this will be a long question.

I'm trying to get something up and running on my university account. We have a public_html folder that we can use as web space to host anything we want there.

I've installed Bitnami lamp stack in the public_html folder (probably not the best idea, security-wise, but I'm only going to test this application for a couple of days and pull it down so I really don't care so long I can get this up and running fast) and the site I want to host is working fine and accessible via (http:// (uni address)/(my account name)/public_html/lamp/apache2/htdocs/(etc..). However, certain parts of the code that connects to the databse gives me the following warning:

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I'm connecting to the database using the following code:

mysql_connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass);

Where dbhost is 'localhost'.

Since it's referencing /var/run/mysqld/mysqld.sock - it obviously means it's trying to connect to the wrong thing as the mysql in the lamp stack I've installed have the following in its my.cnf:

[mysqladmin]
user=root

[mysqld]
basedir=(my account folder)/public_html/lamp/mysql
datadir=(my account folder)/public_html/lamp/mysql/data
port=3306
socket=(my account folder)/public_html/lamp/mysql/tmp/mysql.sock
tmpdir=(my account folder)/public_html/lamp/mysql/tmp

[mysqld_safe]
mysqld=mysqld.bin

[client]
port=3306
socket=(my account folder)/public_html/lamp/mysql/tmp/mysql.sock

[manager]
port=3306
socket=(my account folder)/public_html/lamp/mysql/tmp/mysql.sock
pid-file=(my account folder)/public_html/lamp/mysql/tmp/manager.pid
default-mysqld-path=(my account folder)/public_html/lamp/mysql/bin/mysqld.bin

So my question is, anyone know how to get it to connect to the correct socket? Also, var/run/mysqld/mysqld.sock doesn't exist at all and I obviously don't have the permission to create it (not that I see how it serves my purpose at all).

This had been plaguing me since yesterday. Any help would be greatly appreciated.

Cheers!

+1  A: 

You might have to specify the socket defined in my.cnf using mysql_connect (you should be able to see the functional expample in example #3) instead of localhost by making $CFG->dbhost point to the socket file

$CFG->dbhost = ':(my account folder)/public_html/lamp/mysql/tmp/mysql.sock';
$link = mysql_connect($CFG->dbhost,$CFG->dbuser,$CFG->dbpass);

See if that works!

Another word of advice you should also make sure that the socket file is actually being created by your mysql service in that location "(my account folder)/public_html/lamp/mysql/tmp/mysql.sock"


Edit:

We just needed to confirm that the path to your mysql sock file was valid and the file has been created which it appears to have been.

Can you also confirm that you can manually connect to the mysql server from the command line that would be another good step to help with the diagnosis.

mysql --socket=<my account folder>/public_html/lamp/mysql/tmp/mysql.sock -u <username> -p


Edit 2:

Just a quick confirmation that you are using the full path to your the file when you are substituting you account folder in the examples above.

e.g.

/home/<username>/public_html/lamp/mysql/tmp/mysql.sock
houmam
How do I check if the file is created by my mysql service? I'm presuming it is since it was created after installing the bitnami lamp stack. Also, I tried example#3. It's giving me the same warning and I double checked the location of mysql.sock and it's definitely there and I've allowed full access to it.Thanks again
MikiRei
Yes. I've tried both "/home/<username>" and the full path file in case it doesn't redirect properly if I used "/home/<username>".
MikiRei
Did you manage to connect to the mysql server via the command line?
houmam
Yeah I can connect via command line
MikiRei
Hmmm if you can connect to the mysql server via the socket then you "should" be able to via PHP when you specify the appropriate socket.Can you confirm that you are using the exact notation required like ':/tmp/mysql' or alternatively you could try 'localhost:/tmp/mysql' notation, you have to make sure you are not missing the ':' in your stringIf this still does not work could you provide the error message and the output of mysql_error() with the new socket file.
houmam
Yeah, I've tried several combinationa, all with the ":" but it's still the same warning. Maybe it's my uni's firewall that's preventing it from connecting properly? Possibly. I've managed to get it working on a different server so it doesn't matter anymore. Thank you very much for your help though! Much appreciated!
MikiRei