Forum Moderators: coopster

Message Too Old, No Replies

mysql connect() problems

over SSL

         

omoutop

1:05 pm on Dec 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi all and thanks for any advice/info you may offer.

Some time ago, we activated a subdomain in our main domain
www.maindomain.com and subdomain.mydomain.com

All php scripts worked as expected on the new subdomain.
Yesterday we install SSL on the subdomain, and nothing works.
[subdomain.mydomain.com...] works fine
[subdomain.mydomain.com...] throws the following error:
mysql_connect(): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

I know this kind of error occurs while you try to connect to a db in a diferent domain.
Is this correct? And if yes, what can i do?

we are running PHP 4.4.2, Apache 1.3.37 , Mysql 4.1.14

and we connect to our main db with :
$server_connect = mysql_connect("localhost", "user", "pass");
$db_connect = mysql_select_db("databasename", $server_connect) or die("Cannot Connect to Database");

mattcg

1:46 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



Try using the MYSQL_CLIENT_SSL flag for mysql_connect(). But to be honest I don't think that this will work because you don't get the opportunity to specify a certificate. SSL support isn't PHP4's forte.

omoutop

2:20 pm on Dec 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for your responce mattcg, but it didn't help.

When i connect through "localhost", i got the Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) error.
When i connect with domain.com:port or ip:port methods I got Lost Connection error (although for the port part, i relly on phpinfo() - i am not sure if the port i use is the correct one)

FalseDawn

3:52 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



You could try adding localhost.subdomain to your hosts file (mapped to 127.0.0.1)

Edit: Or maybe that's subdomain.localhost?

Or even subdomain.localhost.mydomain
or subdomain.localhost.mydomain.com

I'd try a few combinations to see if any help - sorry, I'm not that familiar with how PHP maps localhost when subdomains are involved.

[edited by: FalseDawn at 3:57 pm (utc) on Dec. 14, 2006]

mattcg

4:19 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



Try this, from [databasejournal.com...]

Here are some examples, in both a procedural and object-oriented style. First procedurally:

$dbh = mysqli_init( );
// Set a new config file, disallow LOAD LOCAL INFILE and set the timeout to 600 seconds
mysqli_options($dbh, MYSQLI_READ_DEFAULT_FILE, '/home/phpb/mynew.cnf');
mysqli_options($dbh, MYSQLI_OPT_LOCAL_INFILE, false);
mysqli_options($dbh, MYSQLI_OPT_CONNECT_TIMEOUT, 600);
// Connect with the above options, as well as SSL
mysqli_real_connect($dbh,$host,$username,$password,$dbname,$port,$socket, MYSQLI_CLIENT_SSL);

And then in an object-oriented style:

// Instantiate object
$mysqli = new mysqli( );
//Call the init method to allow setting of options
$mysqli->init( );
// Set a new config file, disallow LOAD LOCAL INFILE and set the timeout to 600 seconds
$mysqli->options(MYSQLI_READ_DEFAULT_FILE, '/home/phpb/mynew.cnf');
$mysqli->options(MYSQLI_OPT_LOCAL_INFILE, false);
$mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 600);
// Connect with the above options, as well as SSL
$mysqli->real_connect($host,$username,$password,$dbname,$port,$socket,MYSQLI_CLIENT_SSL);

FalseDawn

4:29 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



mattcg - I don't think the MYSQL_CLIENT_SSL is relevant here - as I understand it, that is used to connect to a remote MySQL instance over SSL.
I believe in this case, the MySQL server is on the same box, so the use of SSL communication is unnecessary.

I use https and have no problem using just localhost to connect, but then again I am not using a subdomain...

mattcg

4:52 pm on Dec 14, 2006 (gmt 0)

10+ Year Member



I think you're right falsedawn. Time for me to back out gracefully..

omoutop

6:42 am on Dec 15, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



FalseDawn you got it right...
I connect without problems over http in both domain and subdomain (both on same box/server).
The proble is I cannot connect through https in subdomain.
I have contacted my hosting company and wait for their reply.

Meanwhile I thank you all for your efford and time..
I will post any usefull findings here, just in case someone else comes to the same problem with me.