I am running two Ubuntu Servers (ubuntu-14.10-server-amd64.) in a virtual VMWARE test environment on an ESXI.
- The first server is a Back-end mysql server. IP: 192.168.253.140
- 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.