I am trying to set up a LAMP server on lubuntu 14.04.5, I erased index.html and replaced it with :
/var/www/html/index.php
Problem is that everything before this <?php
tag executes and this seems to crash it. I do not know why, is it because I MUST have index.html?
<?php
$dbhost = "localhost:3306";
$dbuser = "user1";
$dbpass = "pass1";
$connection = mysqli_connect($dbhost, $dbuser, $dbpass);
if(!$connection){
die("connection error " . mysqli_error());
}
echo "connected successfully";
mysqli_close($connection);
?>
So in my php error log I get undefined function mysqli_connect(). How do I make this an available function?
When I do aptitude search php5-mysql an i shows up meaning that it is installed. And there are no other mysql modules except for mysqlnd which I don't think I need since its just native directory and mysqlnd-ms How do I resolve this?
edit: I think I need to add the mysqli extension but having trouble locating it.
Your code has syntax errors right code to use:
Errors:
mysqli_erro()
==>mysqli_error()
dbpass
==>$dbpass
SO what I did was
sudo apt-get install php5-mysql
Then I was still getting the same webpage so I thought nothing happened, but after checking the/var/log/php5/error.log
It turns out the error changed from "undefined command mysqli_connect()" to some code related error like "mysqli_error requires 1 parameter and "object of class mysqli could not be converted to string" and "unknown mysql server 'localhost:3306'". localhost:3306 got changed to just locahost. so after updating my code, everything works fine.You say you did this...
And you never mention doing this, which is also required...
Just because you install php5-mysql, doesn't mean Apache has loaded either PHP or the PHP MySQL module.
You can find out for sure what's occurring by creating a phpinfo.php file containing...
Then check + ensure both PHP is loaded + PHP mysql module is loaded.
When in doubt, always check your phpinfo.php file output as your first debugging step.
Many times having this simple output, quickly resolves complex problems.