1
votes

I have trying to configure AWS server myself.

Info1: EC2 as hosting and select Ubuntu 14 as OS and install Apache PHP and I have check that it php and http works. I have install Apache and php using below command:

sudo apt-get install apche2 php5 libapche2-mod-php5

and install MySQL client using

sudo apt-get install mysql-client-core-5.5

Info2: RDS as mysql database instance it is working.

Info3: When we trying to import sql from EC2 server using command it work

Info4: t2.micro as EC2 Instance and t2.micro as RDS instance

Issue:

When we try to connection RDS from a php script it showing error:

Call to undefined function mysqli_connect() in /var/www/html/awsmysql.php on line 3

My script code is:

<?php
echo  "Create connection";
$con=mysqli_connect("awsmysqlhost","root","password1223","db");

echo "Check connection";
try{
if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
echo  "Create database";

$sql="Select * from  test";
if (mysqli_query($con,$sql)) {

    $result = mysqli_query($con,"Select * from  test");

while($row = mysqli_fetch_array($result)) {
  echo $row['id'] . " " . $row['name'];
  echo "<br>";
}

  echo "Database my_db created successfully";
// var_dump($r);
} else {
  echo "Error creating database: " . mysqli_error($con);
}
}catch(Exception  $e)
{
    echo "<pre>";
    var_dump($e);
    echo "</pre>"; 
}
?> 

Question(s):

  • Is need to install some MySQL or PHP to library which will connect EC2 with RDS and running the system?

  • Need some Apache Configuration at EC2 Instance?

  • Is there need some setting at AWS?

2
see of this helps apt-get install php5-mysqlslayedbylucifer
slayedbylucifer, is it only install php mysql libary.?Amit Bera
I am not a php guy, but I have done similar MySQL connectivity work in Perl and Ruby. And they all need some specific module/library/extension installed. In case of php, it is php5-mysql. Hence try installing it and check if it works.slayedbylucifer
Hey slayed..please put 1st commit as answer.it is works...Amit Bera
I have added my comment as answer. Glad it helped :)slayedbylucifer

2 Answers

3
votes

You need a mysqli php extension. MySQLi extension is automatically installed in most cases, when php5 mysql package is installed.

sudo apt-get install php5-mysql    
sudo service apache2 restart
2
votes

Please install php extension for mysql. Run below command and then try.

apt-get install php5-mysql