简体   繁体   中英

PHP on EC2 is just printing out my PHP file and not executing

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.

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM