Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is php not running?

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.

like image 393
Christian Avatar asked Aug 06 '13 16:08

Christian


People also ask

Why is my PHP file not running?

To get PHP execution working properly, you need to disable and then enable mpm_event_module, and enable mpm_prefork and php7 modules.

Why is my PHP code not working in HTML?

Php files can always read and display HTML code, but HTML does not automatically parse php code. To do so, you will need to make adjustments to your . htaccess file. Once that is done, the php code will display within HTML files without issue.

How do I run a PHP program?

php” file is placed inside the “htdocs” folder. If you want to run it, open any web browser and enter “localhost/demo. php” and press enter. Your program will run.


1 Answers

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.

like image 166
MagicLAMP Avatar answered Sep 25 '22 23:09

MagicLAMP