I've seen this question answered many times, but most end either unanswered or by telling the asker to put this:
<?php phpinfo() ?>
in a test file. Obviously, if that produced what was expected, I wouldn't be here. Instead, I get a 404 error.
I'm using an ubuntu 12.04 server with Amazon. Apache is installed, php5 is installed, and apache was restarted. I followed the following sequence:
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart
Each one of the first three commands now gives me "apache2 is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded" Obviously, replace apache2 with php5 and libapache2-mod-php5 for the other two.
This is a sure way to tell me it's installed, correct? Well, when I use the command "top", php is not one of the services that are running, which tells me it's not running, correct?
Navigating to the IP address gives me Amazon's "It Works!" page, but navigating to any other page on the server produces a 404 error.
Any help is much appreciated.
This question is related to
php
apache
ubuntu
amazon-web-services
To answer the original question "Why is php not running?" The file your browser is asking for must have the .php extension. If the file has the .html extension, php will not be executed.
Type in browser localhost:80//test5.php[where 80 is your port and test.php is your file name] instead of c://xampp/htdocs/test.php.
When installing Apache and PHP under Ubuntu 14.04, I needed to specifically enable php configs by issuing a2enmod php5-cgi
One big gotcha is that PHP is disabled in user home directories by default, so if you are testing from ~/public_html it doesn't work. Check /etc/apache2/mods-enabled/php5.conf
# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
#<IfModule mod_userdir.c>
# <Directory /home/*/public_html>
# php_admin_flag engine Off
# </Directory>
#</IfModule>
Other than that installing in Ubuntu is real easy, as all the stuff you used to have to put in httpd.conf is done automatically.
You need to add the semicolon to the end of all php things like echo, functions, etc.
change <?php phpinfo() ?>
to <?php phpinfo(); ?>
If that does not work, use php's function ini_set to show errors: ini_set('display_errors', 1);
Source: Stackoverflow.com