LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-05-2006, 05:50 AM   #1
binnyva
LQ Newbie
 
Registered: Jan 2006
Location: Cochin, India
Distribution: Fedora Core 3
Posts: 8

Rep: Reputation: 0
Can't connect to MySQL using PHP


Hi,

I have Fedora Core 3 with Apache, PHP and MySQL installed by default. I am tring to connect PHP with MySQL. But phpMyAdmin gives the error "#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)".

When I tried to connect using my own PHP codes, I got the error

Quote:
Unable to connect to MySQL : Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (13)
The code I used is

Quote:
//Connect to the database
mysql_connect("localhost","root",'') or die("Unable to connect to MySQL : " . mysql_error());

//Select the necessary Database
mysql_select_db('test') or die("Unable to select the database 'test' : " . mysql_error());

There is no problem with mysql. I can run the program using the 'mysql -u root -p <password>' command. In this shell I can access the databases and tables without any problem. But I cannot access the MySQL server from PHP.

Any help is greatly appriciated.

Binny V A
 
Old 02-05-2006, 08:46 AM   #2
thermite_1033
Member
 
Registered: May 2004
Location: Antwerp, Belgium
Distribution: slackware
Posts: 112

Rep: Reputation: 18
make sure apache can read the socket and the whole path to the socket
check your permisions
 
Old 02-05-2006, 10:59 AM   #3
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Can you connect via localhost?
 
Old 02-05-2006, 11:54 AM   #4
dudulz
Member
 
Registered: Feb 2005
Location: Australia
Distribution: [Redhat] [Slackware] [SuSe] [FreeBSD]
Posts: 81

Rep: Reputation: 15
-- check php.ini /usr/local/lib/php.ini , after that check the compiling command. Make sure that compile command have option --with-mysql=$path.
-- if still still error check in local db store, check ownship (it must mysql). after that "./mysqld_safe --user=mysql &" (configuration in /etc/my.cnf)

-- try again "mysql -u root -p "
 
Old 02-05-2006, 03:06 PM   #5
MicahCarrick
Member
 
Registered: Jul 2004
Distribution: Fedora
Posts: 241

Rep: Reputation: 31
I get this error every time I reinstall my linux distro... and now I can't recall the solution. There are permissions and selinux issues if I recall, but I think for me I simply didn't have all the required packages. Make sure you have mysql, mysql-server, and php-mysql. I think my problem was that I had mysql and php-mysql but not mysql-server.

yum install php-mysql mysql mysql-server
 
Old 02-08-2006, 12:11 PM   #6
binnyva
LQ Newbie
 
Registered: Jan 2006
Location: Cochin, India
Distribution: Fedora Core 3
Posts: 8

Original Poster
Rep: Reputation: 0
I have solved the problem - I disabled selinux.

Open /etc/selinux/config
Change the line
SELINUX=enforcing
TO
SELINUX=disabled
Then restart the system.

One doubt - how will this affect me? I know that selinux has something to with security - but not more than that. What is the the function of selinux? Will I run into any trouble by disabling it?

Security is not much of an issue for me - the system I am working on is connected to just another computer inside my home - no other network has access to it. Also the system will NOT be a internet web server. I need PHP/MySQL to test my programs at home - not for serving files over the net. So will there be a problem if I disable selinux?

Anyway, thanks for all your suggestions.
 
Old 02-08-2006, 12:15 PM   #7
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Quote:
Originally Posted by binnyva
One doubt - how will this affect me? I know that selinux has something to with security - but not more than that. What is the the function of selinux? Will I run into any trouble by disabling it?
here's some info about it:

http://en.wikipedia.org/wiki/Selinux

http://fedora.redhat.com/docs/selinux-faq/

no, you won't run into trouble by not using it... it's just an aditional security option you can add to your linux systems to make them harder to crack...

Quote:
Security is not much of an issue for me - the system I am working on is connected to just another computer inside my home - no other network has access to it. Also the system will NOT be a internet web server. I need PHP/MySQL to test my programs at home - not for serving files over the net.
yeah, IMHO it sounds like you don't really have much use for selinux...

of course, when you finally do set the box up as an internet server then selinux is something you should at least consider learning to use, as it's a valuable tool when it comes to mission-critical linux installations...

just my ...

Last edited by win32sux; 02-08-2006 at 12:25 PM.
 
Old 02-08-2006, 10:08 PM   #8
BongHongXanh
LQ Newbie
 
Registered: Jan 2005
Posts: 14

Rep: Reputation: 0
Quote:
Originally Posted by binnyva
Hi,

I have Fedora Core 3 with Apache, PHP and MySQL installed by default. I am tring to connect PHP with MySQL. But phpMyAdmin gives the error "#2002 - The server is not responding (or the local MySQL server's socket is not correctly configured)".

Binny V A
MySQl is not running
you must statup MySQL !

Command:
$chkconfig --add mysqld --level 345
 
Old 02-09-2006, 06:37 AM   #9
win32sux
Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 371Reputation: 371Reputation: 371Reputation: 371
Quote:
Originally Posted by BongHongXanh
MySQl is not running
you must statup MySQL !

Command:
$chkconfig --add mysqld --level 345
he said he already fixed it by disabling selinux...
 
Old 05-12-2006, 10:11 PM   #10
nonfatalexec
Member
 
Registered: May 2006
Location: Toronto, Canada
Distribution: Fedora 17
Posts: 36

Rep: Reputation: 15
You can use SELinux properly by running
Code:
setsebool -P httpd_can_network_connect_db=1
The "P" will make this SELinux change persistent through your next reboot.

You can get the list of all SELinux booleans by running this command
Code:
getsebool -a
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot connect to mysql database from php rocordial Linux - Software 2 08-21-2005 02:05 PM
PHP can't connect to MySQL westchester Linux - Software 13 07-02-2005 10:45 PM
PHP Can Not Connect To MYSQL ombill Fedora 4 09-06-2004 01:24 PM
php can connect mysql, but can't do anything else? towlie Programming 2 04-26-2004 04:17 PM
Can't connect MySQL through PHP mac Programming 1 02-18-2002 09:23 AM


All times are GMT -5. The time now is 10:20 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration