I have installed apache2 and php 5 on my raspeberry pi 3 using the following:
apt-get -y install apache2 apt-get -y install php5 libapache2-mod-php5
When I point a browser at the pi via the IP address, I get the "it works" apache page, so it seems all is good ... until I try to access a simple .php file via http://192.168.1.102/test.php.
Test .php look like this:
<html> <head> <title>PHP Test</title> </head> <body> <?php phpinfo(); ?> </body> </html>
When I point a browser at that file as described above, it opens the file in a text editor rather than executing it.
Running a2enmod php5 returns "module php5 already enabled"
test.php is in var/www/html
I looked at PHP code is not being executed, instead code shows on the page, and the answers do not solve my problem. Mainly, the most popular/relevant answer has me editing httpd.conf, which does not exist in my installation.
Here is point-by-point notes for the most popular answer to that post:
- Make sure that PHP is installed and running correctly. This may sound silly, but you never know. An easy way to check is to run php -v from a command line and see if returns version information or any errors.
[email protected]:/ $ php -v PHP 5.6.30-0+deb8u1 (cli) (built: Apr 14 2017 16:20:58) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
- Make sure that the PHP module is listed and uncommented inside of your Apache's httpd.conf This should be something like LoadModule php5_module "c:/php/php5apache2_2.dll" in the file. Search for LoadModule php, and make sure that there is no comment (;) in front of it.
Under the directory /etc/apache2, in file apache2.conf:
# Include module configuration: IncludeOptional mods-enabled/*.load IncludeOptional mods-enabled/*.conf
Under the directory /etc/apache2/mods-enabled, in file php5.load:
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
- Make sure that Apache's httpd.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.
Under the directory /ect/apache2/mods-enabled, in file php5.conf:
<FilesMatch ".+\.ph(p?|t|tml)$"> SetHandler application/x-httpd-php </FilesMatch>
- Make sure your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.
- Make sure you are not using short tags in the PHP file (
<?), these are deprecated not enabled on all servers by default. Use
<?php instead (or enable short tags in your php.ini with short_open_tag=On if you have code that relies on them).
- Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php
I am accessing with http. Tried both local (same computer) and remote (computer on my network), with the same results.
Not sure what other info is of interest, but I've searched all over the net and not been able to find a solution that works (most go back to installing as above). I even completely purged and re-installed.
Thanks in advance for any help.phpdebianapache2
Ok, finally figured this out!
Turns out that, in a different evolution, my son had installed nginx. So that was what was running. Removing nginx solved the problem. Turns out I was trying to figure why Apache wasn't doing what I expected, but it wasn't apache tat was serving the site!