Reputation: 6789
I have this as my index.php on a basic EC2 instance.
<?php
$conn = new mysqli('localhost', 'testdb_user', 'testpass', 'testdb', '');
$result = $conn->query("SELECT message FROM test");
$row = $result->fetch_assoc();
echo $row['message'];
?>
When I visit my public DNS I get this:
query("SELECT message FROM test"); $row = $result->fetch_assoc(); echo $row['message']; ?>
printed to the browser.
I've installed php and the table in mysql is fine (i have repleaced db name etc with my actual credentials.
Upvotes: 3
Views: 5346
Reputation: 606
In my case PHP cli was working on ec2 ubuntu instance and as you said browser just prints source code instead of executing it
sudo apt-get update
sudo apt-get install apache2
sudo apt-get install libapache2-mod-php php
sudo apt-get install mysql-server php-mysql
sudo service apache2 restart
I have run from 3rd line (install php) and that fixed my issue
Ref: http://fredericpaladin.com/kb/aws-ec2-instance-with-ubuntu-apache2-web-server/
Upvotes: 0
Reputation: 7157
You have either installed PHP incorrectly or failed to restart your web server after installing it. If it's apache, try this:
/etc/init.d/httpd restart
It doesn't have anything to do with your mysql config - php is not trying to execute the script at all.
Upvotes: 6