1

I am running two Ubuntu Servers (ubuntu-14.10-server-amd64.) in a virtual VMWARE test environment on an ESXI.

  1. The first server is a Back-end mysql server. IP: 192.168.253.140
  2. The Second server has an Apache2 service with PHP to serve a webpage. IP: 192.168.253.143

1 MYSQL SERVER: 192.168.253.140

A) I configured the server so that is has 2 users for 2 specific machines to be able to connect to a specific database.

User 'apache', to let the apache server connect to the mysql server:

create user 'apache'@'192.168.253.143' IDENTIFIED BY    'abc123';     
grant    ALL PRIVILEGES ON Modulus_Docker_IW.* TO  'apache'@'192.168.253.143'    WITH GRANT OPTION;

User 'pc', to let my own pc connect via a WAMP server (PHP) to the remote mysql server.

create user 'pc'@'192.168.253.1' IDENTIFIED BY 'abc123';  
grant ALL PRIVILEGES ON Modulus_Docker_IW.* TO   'pc'@'192.168.253.1' WITH GRANT OPTION;

FLUSH PRIVILEGES; FLUSH HOSTS;

B) I also configured the bindings /etc/mysql/my.cnf so that the mysql server accepts any host (not only localhost)

bind-address = 0.0.0.0

2 APACHE SERVER: 192.168.253.143

The Apache server is installed and I uploaded my test php page on the server. It is a simple page that gets usernames and passwords from a database on mysqlserver.

I created an connection in dreamweaver with the "pc" user and I could retreve some data, processing the PHP with a WAMP server.

If I uploaded the files to the remote Apache server I changed the connection string to the apache user and hoped for the best. But I just got a blanc page with nothing... .

Is there somthing in Apache2 that I have to do, to allow outgoing or incoming connections to the mysqlserver?

PHPcode:

<?php 
$username = "pc";
$password = "abc123";
$host="192.168.253.140";
$database="Modulus_Docker_IW";

$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_select_db ($database, $link); 

$strSQL = "SELECT naam, paswoord FROM tblUsers ORDER BY naam ASC"; 
$result = mysql_query( $strSQL, $link );

mysql_close($link);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>
<p>echo 'Connected successfully';<p>
<?php 
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
    echo "Naam :{$row['naam']}  <br> ".
         "--------------------------------<br>";
} 

 ?>
</body>
</html>

Thanks to your comments. I now get some debugging information from apache php.

Fatal error: Call to undefined function mysql_connect() in /var/www/html/modulus/connectHand.php on line 7

OK it is solved: the solution was found on PHP/Apache: PHP Fatal error: Call to undefined function mysql_connect()

I had not installed "sudo apt-get install php5-mysql" on the apache server.

Thanks for your quick responses.

Community
  • 1
  • 1
Ive Weygers
  • 31
  • 2
  • 3
  • 8
  • A blank page in PHP (the "white screen of death") means a fatal 500 error occurred and you should go look in the Apache error log for details. When developing and testing code, turn on PHP's display_errors so they show on screen, but disable it in production. At the top of the script `error_reporting(E_ALL); ini_set('display_errors', 1);` or in php.ini `error_reporting = E_ALL` and `display_errors = On` but again don't forget to turn off display_errors in production. – Michael Berkowski Dec 28 '14 at 21:59
  • Now in /etc/php5/apache2/php.init ?? error_reporting = E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED and display_errors = On – Ive Weygers Dec 28 '14 at 22:14
  • Change it to just `E_ALL` so the notices and deprecations aren't suppressed. Then look in `/var/log/apache2/error_log` or whatever your error log path is on that Ubuntu server. Something is failing to cause the blank screen. Note you have to restart Apache after changing php.ini – Michael Berkowski Dec 28 '14 at 22:15
  • Okay so the mysql extension isn't installed. You would need to `apt-get install php5-mysqlnd` But note that the `mysql_*()` functions are deprecated. You should instead start learning to use `mysqli_*()` or PDO. – Michael Berkowski Dec 28 '14 at 22:23
  • Yes that was the problem... Thanks for your quick response – Ive Weygers Dec 28 '14 at 22:30
  • yes After changing Binding Address to bind-address = 0.0.0.0 , you must restart Apache server using sudo /etc/init.d/apache2 restart ,its works Thanks – Milind Morey Aug 19 '16 at 02:42

4 Answers4

1

OK it is solved: the solution was found on PHP/Apache: PHP Fatal error: Call to undefined function mysql_connect()

I had not installed "sudo apt-get install php5-mysql" on the apache server.

Thanks for your quick responses.

Ive Weygers
  • 31
  • 2
  • 3
  • 8
0

Check iptables on the MySQL server to ensure it's not blocking the connection. The default port is TCP/3306. Also, check the MySQL configuration to ensure connections from outside localhost are allowed.

  • Connections from outside are allowed on the Mysql server. How do I ensure that port 3306 isn't blocked on the apache server? – Ive Weygers Dec 28 '14 at 22:16
0

MySQL users aren't the same as Unix system users. Just because you created an user named "apache" in your DB, that doesn't mean that it's the user that the PHP program is using to connect to it. It would be better if you showed us here your PHP code.

Felipe Oriani
  • 37,948
  • 19
  • 131
  • 194
PaulJ
  • 1,646
  • 5
  • 33
  • 52
  • Thanks for the quick respons. I updated the post with the code that works on my own local machine. – Ive Weygers Dec 28 '14 at 22:00
  • Okay. The username that your PHP code was using to connect to the DB was "pc" (in your first line). You need to change that to "apache" (or whatever is the name of the user you created in MySQL). – PaulJ Dec 28 '14 at 22:02
  • Sorry, I see now that you did change your username in the file that you uploaded to the remote server. – PaulJ Dec 28 '14 at 22:10
  • @Ipapp: my comment was just to retract my previous suggestion, since I later saw that she had already done what I was suggesting as a solution. – PaulJ Dec 29 '14 at 08:57
0

Another suggestion: in your code, you are closing the MySQL connection before iterating through the results. Maybe try to put the mysql_close($link) at the end of the PHP file?

PaulJ
  • 1,646
  • 5
  • 33
  • 52