Search code examples
phpmysqllinuxlamp

PHP include not working on new LAMP server


I am working on converting an application I wrote in .NET over to a LAMP server.

I built a very basic PHP file that connects to a MySQL database and creates a drop-down list of usernames. This works fine by itself, and by executing it from the command line using "PHP -f file.php":

<?php
mysql_connect('localhost', 'user', 'password');
mysql_select_db("database");

$sql = "SELECT Username,Guid FROM Usernames";
$result = mysql_query($sql);

echo "<td><select name='users'>";

while($row = mysql_fetch_assoc($result)){
echo "<option value='" . $row['Guid'] . "'>" . $row['Username'] . "  </option>";
}   

echo "</select></td></tr> ";
?>

HOWEVER, when I try to include this file in an html file, it simply does not display, and I am not getting any errors. Here is the source from the basic HTML file:

<HTML>
<H1>This is my homepage</H1>
<?php 
error_reporting(E_ALL ^ E_NOTICE);
include 'ShowData.php';?>
</HTML>

My question is this: does apache2 natively allow for php include? In my case, both files are in the same directory "/var/www/html/". Or am I missing some base configuration somewhere to allow this? My LAMP server is a brand new install of Ubuntu 14LTS. LAMP was installed using the published "apt-get" commands.


Solution

  • You can't run php in a .html file change the extension to .php