PHP doesn't know the correct path to mysql.sock

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
shemond
Forum Newbie
Posts: 6
Joined: Wed Dec 03, 2003 8:45 am

PHP doesn't know the correct path to mysql.sock

Post by shemond »

Hi folks,

I have installed mysql but I had to change the default datadir to /mysqldb. I also had to change the default socket path to /mysqldb/mysql.sock.

Everything works fine with the clients, I can use mysql and other win32 clients to connect to mysql server and everything is working smoothly.

However, when running a php page which connect to my mysql database, it returns me an error looking for mysql.sock in /var/lib/mysql. It obviously won't work because I have changed the default socket path to /mysqldb!

How could I tell php to look in /mysqldb.

I'm not sure to have used to correct method to move the datadir to another place on the system... there must be a 'standard' procedure to do so?

Two solutions required :

1. Changing the Mysql datadir correctly
2. Tell php to look in /mysqldb for mysql.sock

Any ideas?

Thanks in advance,

Best regards,

Steve
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

php.ini:

Code: Select all

//...skipped
mysql.default_socket "/mysqldb/mysql.sock"
//...skipped
shemond
Forum Newbie
Posts: 6
Joined: Wed Dec 03, 2003 8:45 am

Post by shemond »

I don't have any php.ini file in /etc

My only main mysql config file is /etc/my.cnf

Where is your php.ini file located?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

PHP manual wrote: The default location of php.ini is a compile time option (see the FAQ entry), but can be changed for the CGI and CLI version with the -c command line switch, see the chapter about using PHP from the command line. You can also use the environment variable PHPRC for an additional path to search for a php.ini file.

Code: Select all

$ locate php.ini
/usr/local/Zend/etc/php.ini
/usr/local/lib/php.ini
/usr/local/lib/php.ini.bak
/usr/local/src/php-4.3.3/pear/tests/php.ini
/usr/local/src/php-4.3.3/php.ini-dist
/usr/local/src/php-4.3.3/php.ini-recommended
User avatar
mrvanjohnson
Forum Contributor
Posts: 137
Joined: Wed May 28, 2003 11:38 am
Location: San Diego, CA

Post by mrvanjohnson »

Or if you have a phpinfo page i.e.

Code: Select all

<?php
phpinfo () ;
?>
You can look at the first section where it says
Configuration File (php.ini) Path
This is tell you which php.ini file your webserver is using in case you find mulitple copies.
Chambrln
Forum Commoner
Posts: 43
Joined: Tue Dec 02, 2003 10:45 am
Location: Oregon

Post by Chambrln »

Depending on your system and how you installed php it doesn't always automatically create a php.ini file. You might need to copy the php-dist.ini to the correct file and rename it to php.ini as well as make any necessary changes. I had this problem on a redhat box I installed php on.
shemond
Forum Newbie
Posts: 6
Joined: Wed Dec 03, 2003 8:45 am

Post by shemond »

Thanks for the help to you guys,

In fact, I've installed mysql and php on a Redhat9 box.

I'll try this when at home, thanks! :-)
shemond
Forum Newbie
Posts: 6
Joined: Wed Dec 03, 2003 8:45 am

Post by shemond »

I edited /etc/php.ini

; Default socket name for local MySQL connects. If empty, uses the built-in
; MySQL defaults.
mysql.default_socket = /mysqldb/mysql.sock

But that didn't change anything, php is still looking for the mysql socket in /var/lib/mysql/ ... that's wierd!

I keep searching ...

Thanks

Steve
shemond
Forum Newbie
Posts: 6
Joined: Wed Dec 03, 2003 8:45 am

Post by shemond »

Okay, I'm on a good track...

Take a look at my phpinfos : http://badside.homeunix.org/grip/info.php

The socket is /var/lib/mysql/mysql.sock, even if I specified /mysqldb/mysql.sock in the php.ini file.

How could I change this system-wide?

Thanks again!

Steve
shemond
Forum Newbie
Posts: 6
Joined: Wed Dec 03, 2003 8:45 am

Post by shemond »

OK, DONE!

I made that issue more complex than it actually is.

I only pointed datadir to /mysqldb

The socket is now back in /var/lib/mysql/ so EVERYTHING linked to mysql will be working smoothly.

Thanks to all again for your help!

Steve
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

Code: Select all

Name                            local           master
mysql.default_socket	no value	no value
did you restart apache?
Post Reply