LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora
User Name
Password
Fedora This forum is for the discussion of the Fedora Project.

Notices


Reply
  Search this Thread
Old 02-23-2008, 05:35 PM   #1
hil4d
LQ Newbie
 
Registered: Feb 2008
Posts: 7

Rep: Reputation: Disabled
Question Can't connect to mysql from php script


I am trying to setup a LAMP server to practice database driven web development.

System Confiruration:
Apache 2.2.6
php 5.2.4
mysql 5.0.45

The mysql command line interface works fine.

Isses:
Apache and php works but when i try to connect to a mysql database the html and php works but the mysql does not work - no error message displayed.

html files with embedded php scrips processes only the html code - no php processing. php scripts process both html and php.
 
Old 02-24-2008, 02:08 AM   #2
dla-nor
LQ Newbie
 
Registered: Jan 2007
Distribution: FC9, eee-xubuntu r3, RHEL 4, RHEL 5
Posts: 17

Rep: Reputation: 0
Do you have the php-mysql package installed? That's the first thing I would check. What's the complete listing of php and mysql related packages you have installed?
 
Old 02-24-2008, 07:56 PM   #3
hil4d
LQ Newbie
 
Registered: Feb 2008
Posts: 7

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dla-nor View Post
Do you have the php-mysql package installed? That's the first thing I would check. What's the complete listing of php and mysql related packages you have installed?
Thanks for your response. I am a newbie and I don't know where to find the php-mysql package.

Additional info
---------------
<?php
$mysqli = mysqli_connect('localhost', 'mysql', 'password', 'testDB');

/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}

?>

Error Message:

Connect failed: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

---------------

I ran the phpinfo() function from a script and found the following listed under the mysql section

MYSQL_SOCKET /var/lib/mysql/mysql.sock

but there is no /var/lib/mysql directory on the system



when I typed:
ps xa | grep mysqld

I get:

---------------------------------------------------
1900 ? S 0:00 /bin/sh ./bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
2005 ? Sl 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --log-error=/usr/local/mysql/data/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid --socket=/tmp/mysql.sock --port=3306
3450 pts/0 S+ 0:00 grep mysqld
-----------------------------------------------------

I found:
--socket=/tmp/mysql.sock in the output

ls -l /tmp/mysql.sock
srwxrwxrwx 1 mysql mysql 0 2008-02-22 22:23 /tmp/mysql.sock

I also found this line in /etc/my.cnf
socket = /tmp/mysql.sock

I don't know why the phpinfo() function show

MYSQL_SOCKET /var/lib/mysql/mysql.sock


I don't know where to go from here
Thanks
 
Old 02-24-2008, 08:46 PM   #4
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
Assuming you're on Fedora (since this is a Fedora sub-forum), use

yum install php-mysql

as root from the command line. If you use a GUI, there is an add/remove front-end available too somewhere.

Edit

Note you can list php packages with

yum list installed php*

and sim. for mysql

Last edited by billymayday; 02-24-2008 at 08:47 PM.
 
Old 02-26-2008, 09:24 AM   #5
shafty023
Member
 
Registered: Oct 2007
Distribution: OSX
Posts: 248

Rep: Reputation: 31
or you could type "rpm -q --all | grep php" without the double quotes
 
Old 02-26-2008, 07:17 PM   #6
hil4d
LQ Newbie
 
Registered: Feb 2008
Posts: 7

Original Poster
Rep: Reputation: Disabled
rpm q all - response

Quote:
Originally Posted by shafty023 View Post
or you could type "rpm -q --all | grep php" without the double quotes
Here is the response I got from rpm
What does this say about my php/mysql configuration?

# rpm -q --all | grep php

php-mysql-5.2.4-3
php-ldap-5.2.4-3
php-common-5.2.4-3
php-5.2.4-3
php-pdo-5.2.4-3
php-cli-5.2.4-3

Thanks
 
Old 02-27-2008, 02:30 AM   #7
dla-nor
LQ Newbie
 
Registered: Jan 2007
Distribution: FC9, eee-xubuntu r3, RHEL 4, RHEL 5
Posts: 17

Rep: Reputation: 0
Ok, that means that you have the right packages installed. In your other post about mysql.sock, you mention that your my.conf has the right location for the mysql.sock but running phpinfo() gives the wrong location. I'm no expert, but I'm suspecting now that there might be a wrong line in your php.ini file (/etc/php.ini) There's a line that starts with "mysql.default_socket="

Maybe you can check that line to see if it doesn't say the wrong thing there?
 
Old 03-15-2008, 06:06 AM   #8
simplicissimus
Registered User
 
Registered: Mar 2008
Posts: 104

Rep: Reputation: 15
chmod user.group

I had a case with a Fedora 6 installation upgraded to Fedora 8, leading to a similar problem with a MySQL socket. I have tried to reinstall MySQL but that didn't correct the problem.

In the end it turned out that the current MySQL installation is using the 'root.mysql' combination of user.group, but the /var/lib/mysql directory and it's contents where set to belong to 'mysql.root'. Just the other way around.

That's a subtle difference, but enough to not allow MySQL to create a socket file in that location.

Using chmod to set proper user.group values did solve the problem in my case.

Hope this helps,
Regards,
SIMP

Linux Archive

Last edited by simplicissimus; 04-02-2008 at 04:33 AM.
 
  


Reply

Tags
lamp, mysql5


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
php/shell script to install mysql,apache and php automatically stranger_6_7 Linux - General 2 08-11-2009 02:07 AM
is there a client install for MySql so PHP can connect to MySQL Server? alar Linux - Software 8 07-03-2007 07:42 PM
LXer: Title: PHP/MySQL Classifieds Script AddAsset1.php Script Insertion LXer Syndicated Linux News 0 07-02-2006 06:21 PM
Can't connect to MySQL using PHP binnyva Programming 9 05-12-2006 10:11 PM
Can't connect MySQL through PHP mac Programming 1 02-18-2002 09:23 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Fedora

All times are GMT -5. The time now is 08:05 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration