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! |
Did you started mysql daemon?
What nmap localhost says? |
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. |
Quote:
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' To see if mysql is listening (usually on port 3306) Code:
netstat -tanp |
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:
Code:
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION; 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 |
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/... ... ... In other words, you need the php-mysql pkg. |
Quote:
From the opening post: Quote:
|
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! |
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:
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). |
Anyone?
|
Quote:
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. |
Have you checked the php.ini file to see that the line below is not commented out?
Quote:
|
Quote:
Quote:
Don't forget to restart the services after changing something. |
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. |
All times are GMT -5. The time now is 12:17 AM. |