0

Setup:

Two separate boxes:

  1. Fedora 15, Apache, PHP and PHP modules
  2. Fedora 15, MySQL

I am unable to make a connection to MySQL from the Apache web server.

<?php echo "<br>begin test<br>"; mysql_connect('hostname[FQDN]','username','password') or ("Error" . mysql_error()); echo "<br>end test<br>"; ?> 

the 'begin test' text is being displayed but no MySQL error or the 'end test' text when Apache serves the page.

I am able to connect to the MySQL DB using the MySQL workbench on port 3306 from a remote machine. Privileges and access to the user and IP address have been left completely open (%) to avoid any issues in those respects.

2
  • 3
    Sounds like you have a fatal error because the mysql extension isn't installed. yum install php-mysql Commented Jul 28, 2011 at 21:07
  • Can you post the contents of your /var/log/httpd/error_log Commented Jul 28, 2011 at 21:11

3 Answers 3

4

Don't forget that, mysql_connect, mysql_error, etc are not part of PHP. They are an extension.

If you want to test if php has those functions you could do a little test like:

if(!function_exists('mysql_connect')) echo 'MySQL extension not installed'; 

You should have mysql and mysql-server installed on your MySQL Box

You should have php and php-mysql installed on your Apache box. If you haven't installed php-mysql install it: yum -y install php-mysql and then restart Apache.

4
  • php and php-mysql are installed on the apache box and mysql and mysql-server on the mysql box Commented Jul 28, 2011 at 21:17
  • @hecro What's the output from those two lines of code? If it outputs that you don't have the MySQL extension you may need to configure your php.ini. Can you edit your question with anything related to mysql output by phpinfo();? Commented Jul 28, 2011 at 21:17
  • 1
    The issue was resolved. The change I made was with SElinux and running setsebool -P httpd_can_network_connect=1 or running setenforce=0 which is permissive mode Commented Jul 28, 2011 at 22:18
  • @hecrodjr: Please add your solution as an answer and accept it, so that others may benefit from your knowledge. Commented Jul 29, 2011 at 0:08
0

Run

$ netstat -l 

You should see the mysql server listening on port 3306. If it's 127.0.0.1, the server listens on the loopback interface only. Fix your my.cnf in that case.

1
  • yes it is listening on port 3306. code Local Address :mysql and Foreign Address *: State LISTEN code Commented Jul 28, 2011 at 21:16
0

The issue was resolved. The change I made was with SElinux and running setsebool -P httpd_can_network_connect=1 or running setenforce=0 which is permissive mode

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.