LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-25-2012, 05:26 PM   #1
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Rep: Reputation: 5
Linux -> MySQL / PHP / Apache


Hi,

I'm using a Fedora 15, 64-bit machine, and trying to get MySQL to work with PHP and Apache.

Firstly, Apache works fine; PHP also works fine, and MySQL also works fine. PHP also works fine under Apache. However, I cannot seem to get PHP to recognize MySQL under Apache 2.

I've installed php-mysql (i.e. yum install php-mysql), and restarted Apache, but phpinfo (when run via the webserver) displays no MySQL info at all. My Apache error log also indicates errors when my PHP scripts attempt to use mysql stuff.

If I run "php -i | grep -i mysql" from a command line then I see everything I would expect to see, including all of the MySQL bits.

Thus, I don't understand why PHP doesn't recognize MySQL when it's run under Apache. I'm sure it must be something really simple, but any help would be much appreciated.

Thanks!
 
Old 11-25-2012, 06:19 PM   #2
deswarf
LQ Newbie
 
Registered: Jan 2012
Posts: 26

Rep: Reputation: Disabled
Did you started mysql daemon?
What nmap localhost says?
 
Old 11-25-2012, 06:41 PM   #3
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
a) MySQL was restarted.

Not sure about nmap. I don't have it installed, but I'm not sure what it is I'd be looking for anyway, or what it would show relating to PHP/MySQL not playing together under Apache.
 
Old 11-25-2012, 06:56 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
Quote:
My Apache error log also indicates errors when my PHP scripts attempt to use mysql stuff.
Show exact php cmds and error msgs; we can't guess from that...

Also, check users/grants inside MySQL
Code:
mysql -u root -p${1} --batch --skip-column-names -e "SELECT user, host FROM user" mysql | sed 's,\t,"@",g;s,^,show grants for ",g;s,$,";,g;' | mysql -u root -p${1} --batch --skip-column-names | sed 's,$,;,g'
Put that in a shell script, call it and pass mysql root passwd as a param

To see if mysql is listening (usually on port 3306)
Code:
netstat -tanp

#OR
netstat -tap

Last edited by chrism01; 11-25-2012 at 06:59 PM.
 
Old 11-25-2012, 07:07 PM   #5
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
Well, like I said, it won't do anything with MySQL, so trying to connect via a PHP script will produce an Apache error as below:

Quote:
[Sun Nov 25 16:25:22 2012] [error] [client 172.10.1.5] PHP Fatal error: Call to undefined function mysql_connect() in /var/www/sites/... ... ...
The output from the command you gave is provided below:

Code:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'cheddar'@'172.10.1.3' IDENTIFIED BY PASSWORD '*72AA0B7...' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'cheddar'@'172.10.1.5' IDENTIFIED BY PASSWORD '*72AA0B7...' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'::1' WITH GRANT OPTION;
GRANT USAGE ON *.* TO ''@'dbserver';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'dbserver' WITH GRANT OPTION;
GRANT PROXY ON ''@'' TO 'root'@'dbserver' WITH GRANT OPTION;
GRANT USAGE ON *.* TO ''@'localhost';
GRANT ALL PRIVILEGES ON *.* TO 'cheddar'@'localhost' IDENTIFIED BY PASSWORD '*72AA0B7...' WITH GRANT OPTION;
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;
GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION;
I know the PHP code works, because I'm simply moving an existing working site to another machine.

Yes, mysql is listening (it works fine for Perl/Apache, and everything else I do with MySQL ... just not with PHP/Apache). Here's the output from the last command you supplied:

Code:
# netstat -tanp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      12866/mysqld
tcp        0      0 0.0.0.0:5900                0.0.0.0:*                   LISTEN      2515/vino-server
tcp        0      0 127.0.0.1:5902              0.0.0.0:*                   LISTEN      2307/Xvnc
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1122/rpcbind
tcp        0      0 0.0.0.0:6000                0.0.0.0:*                   LISTEN      2063/Xorg
tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      1349/vsftpd
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1207/sshd
tcp        0      0 127.0.0.1:631               0.0.0.0:*                   LISTEN      1245/cupsd
tcp        0      0 0.0.0.0:44087               0.0.0.0:*                   LISTEN      1186/rpc.statd
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      2621/sendmail: acce
tcp        0      0 172.10.1.2:22               172.10.1.5:3398             ESTABLISHED 21420/sshd: cheddar [pr
tcp        0     52 172.10.1.2:22               172.10.1.5:2053             ESTABLISHED 13009/sshd: cheddar [pr
tcp        0      0 172.10.1.2:3306             172.10.1.3:4477             ESTABLISHED 12866/mysqld
tcp        0      0 172.10.1.2:22               172.10.1.5:3732             ESTABLISHED 21476/sshd: cheddar [pr
tcp        0      0 172.10.1.2:22               172.10.1.5:4533             ESTABLISHED 6557/sshd: cheddar [pri
tcp        0      0 :::39296                    :::*                        LISTEN      1186/rpc.statd
tcp        0      0 :::5900                     :::*                        LISTEN      2515/vino-server
tcp        0      0 :::111                      :::*                        LISTEN      1122/rpcbind
tcp        0      0 :::80                       :::*                        LISTEN      12222/httpd.worker
tcp        0      0 :::6000                     :::*                        LISTEN      2063/Xorg
tcp        0      0 ::1:631                     :::*                        LISTEN      1245/cupsd
Thanks.

Last edited by cheddarcheese; 11-25-2012 at 07:15 PM.
 
Old 11-26-2012, 01:17 AM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
This msg
Code:
[Sun Nov 25 16:25:22 2012] [error] [client 172.10.1.5] PHP Fatal error: Call to undefined function mysql_connect() in /var/www/sites/... ... ...
http://stackoverflow.com/questions/9...-error-message
In other words, you need the php-mysql pkg.
 
Old 11-26-2012, 05:35 AM   #7
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Quote:
Originally Posted by chrism01 View Post
In other words, you need the php-mysql pkg.
But it is supposed to be installed. Am I missing something?

From the opening post:
Quote:
Originally Posted by cheddarcheese View Post
I've installed php-mysql (i.e. yum install php-mysql), and restarted Apache, but phpinfo (when run via the webserver) displays no MySQL info at all. My Apache error log also indicates errors when my PHP scripts attempt to use mysql stuff.
 
Old 11-26-2012, 05:59 AM   #8
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
Hi Wim,

No, you're not missing anything. php-mysql is installed. Originally, before I posted the original question on here, I'd figured that was the issue, so that's what I did, and it installed without any problem. But I simply cannot get PHP to recognize MySQL under Apache.

On finding that it didn't work I figured it was just an Apache module or two that I needed installing as well, but I've really no idea ... hence why I've arrived here :-)

I've installed php-mysql on other machines before now, and I don't recall any big problems ... it always seemed just to work, from my recollection at least.

Any assistance much appreciated!
 
Old 11-26-2012, 11:07 AM   #9
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
FYI. I also temporarily disabled SELinux in case there was some issue relating to that, but it made no difference.

Also checked that php-mysql was installed properly:
Quote:
Package php-mysql-5.3.13-1.fc15.x86_64 already installed and latest version
Nothing to do
All very frustrating ... I've looked in dozens of places for a solution, but nothing doing.

Is there anything that I should be doing in the PHP ini file, or the Apache config to get PHP and MySQL talking to each other under Apache? (bearing in mind that from a command line PHP already does recognize MySQL).

Last edited by cheddarcheese; 11-26-2012 at 11:09 AM.
 
Old 11-27-2012, 08:08 AM   #10
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
Anyone?
 
Old 11-27-2012, 09:20 AM   #11
deswarf
LQ Newbie
 
Registered: Jan 2012
Posts: 26

Rep: Reputation: Disabled
Quote:
Originally Posted by cheddarcheese View Post
a) MySQL was restarted.

Not sure about nmap. I don't have it installed, but I'm not sure what it is I'd be looking for anyway, or what it would show relating to PHP/MySQL not playing together under Apache.
It can tell on which ports are those services and whether those ports are opened.
Is there anything useful in log files?
 
Old 11-27-2012, 09:40 AM   #12
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
Okay, but, for my purposes, isn't that going to be something similar to what I've already ascertained from the previous post, where I ran "netstat -tanp" and was able to see MySQL listening on the given ports?

I still can't help thinking it's just some config issue with either PHP or Apache, but I'm not familiar enough with getting PHP and MySQL working together under Apache to know what that might be.
 
Old 11-27-2012, 10:12 AM   #13
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: PCLinux, Slackware
Posts: 6,870

Rep: Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249Reputation: 1249
Have you checked the php.ini file to see that the line below is not commented out?

Quote:
extension=mysql.so
 
Old 11-27-2012, 10:53 AM   #14
deswarf
LQ Newbie
 
Registered: Jan 2012
Posts: 26

Rep: Reputation: Disabled
Quote:
Originally Posted by cheddarcheese View Post
Not sure about nmap. I don't have it installed, but I'm not sure what it is I'd be looking for anyway, or what it would show relating to PHP/MySQL not playing together under Apache.
Yep, that's an alternative.
Quote:
Originally Posted by cheddarcheese View Post
I've installed php-mysql
Are you using php5 with apache2? Check all versions matching.
Don't forget to restart the services after changing something.

Last edited by deswarf; 11-27-2012 at 10:56 AM.
 
Old 11-27-2012, 10:58 AM   #15
cheddarcheese
Member
 
Registered: Aug 2011
Location: Massachusetts, USA
Distribution: Fedora; Centos; Puppy
Posts: 82

Original Poster
Rep: Reputation: 5
Hi Yancek / deswarf,

Yancek::
That line is commented out, but it's also commented out on another machine I have where it's working okay.

However, for purposes of elimination, I did un-comment the line and try again (also re-started Apache, just in case), but it makes no difference.

Thanks for the thoughts though.

deswarf::
Yes, PHP 5.3.13 and Apache 2.2.17.
Yes, I've been restarting MySQL and Apache, just to be on the safe side. I just can't get my head around what could be wrong. I even disabled (and now re-enabled) SELinux just in case, but no dice.

Thanks too for your suggestions to date.

Last edited by cheddarcheese; 11-27-2012 at 11:04 AM.
 
  


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
apache, php, mysql on linux MrSako Linux - Newbie 62 08-02-2006 03:46 AM
Linux + Apache + PHP + ??MySQL/PostgreSQL?? Thakowbbery Linux - Enterprise 4 10-28-2005 04:18 PM
Linux, Apache, PHP, MySQL akilles Linux - Newbie 4 03-02-2005 03:43 AM
Apache Mysql Php: mysql with php doesn't work breakerfall Linux - Networking 6 12-27-2003 09:59 PM
VMWare, RH Linux 7.3, Apache, MySQL and PHP xibernex Linux - Software 2 06-17-2002 10:57 AM


All times are GMT -5. The time now is 08:47 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration