LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linux -> MySQL / PHP / Apache (https://www.linuxquestions.org/questions/linux-newbie-8/linux-mysql-php-apache-4175438686/)

cheddarcheese 11-25-2012 04:26 PM

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!

deswarf 11-25-2012 05:19 PM

Did you started mysql daemon?
What nmap localhost says?

cheddarcheese 11-25-2012 05:41 PM

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.

chrism01 11-25-2012 05:56 PM

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


cheddarcheese 11-25-2012 06:07 PM

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.

chrism01 11-26-2012 12:17 AM

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.

Wim Sturkenboom 11-26-2012 04:35 AM

Quote:

Originally Posted by chrism01 (Post 4836984)
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 (Post 4836831)
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.


cheddarcheese 11-26-2012 04:59 AM

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!

cheddarcheese 11-26-2012 10:07 AM

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).

cheddarcheese 11-27-2012 07:08 AM

Anyone?

deswarf 11-27-2012 08:20 AM

Quote:

Originally Posted by cheddarcheese (Post 4836862)
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?

cheddarcheese 11-27-2012 08:40 AM

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.

yancek 11-27-2012 09:12 AM

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

Quote:

extension=mysql.so

deswarf 11-27-2012 09:53 AM

Quote:

Originally Posted by cheddarcheese (Post 4836862)
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 (Post 4837134)
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.

cheddarcheese 11-27-2012 09:58 AM

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.