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.

techraf
  • 4,163
  • 8
  • 27
  • 44
hecrodjr
  • 11
  • 3

3 Answers3

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.

Paul
  • 211
  • 1
  • 9
  • php and php-mysql are installed on the apache box and mysql and mysql-server on the mysql box – hecrodjr Jul 28 '11 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();`? – Paul Jul 28 '11 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 – hecrodjr Jul 28 '11 at 22:18
  • @hecrodjr: Please add your solution as an answer and accept it, so that others may benefit from your knowledge. – womble Jul 29 '11 at 00: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.

cweiske
  • 781
  • 1
  • 13
  • 36
  • yes it is listening on port 3306. `code` Local Address *:mysql and Foreign Address *:* State LISTEN `code` – hecrodjr Jul 28 '11 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

hecrodjr
  • 11
  • 3