Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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)
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:
But it is supposed to be installed. Am I missing something?
From the opening post:
Quote:
Originally Posted by cheddarcheese
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.
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.
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 10:09 AM.
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?
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.
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
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.
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 10:04 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.