0

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:

  1. 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.
pi@raspberrypi:/ $ 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
  1. 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
  1. 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[345]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
  1. 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.

They do.

  1. 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).

Double-checked this.

  1. 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.

Puckster
  • 1
  • 1
  • 5
  • Possible duplicate of [PHP code is not being executed, instead code shows on the page](http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-instead-code-shows-on-the-page) – SH- May 22 '17 at 02:46
  • I went through that post more than once before I posted this question. Maybe I missed something, but none of the solutions there fit my problem. – Puckster May 22 '17 at 03:22
  • There is probably a http.conf that is named something else. – SH- May 22 '17 at 15:03
  • https://raspberrypi.stackexchange.com/questions/13398/where-is-the-httpd-conf-file – SH- May 22 '17 at 15:04
  • apache2.conf and httpd.conf are not the same (from what I can figure out). Some of the functionality that was/is in httpd.conf in other installs is distributed to other .conf files in several directories. This post https://help.ubuntu.com/lts/serverguide/httpd.html, and others with similar information, as well as the Apache Debian Default page are the basis for my conclusion. I have edited my original post to show point by point comparisons to the similar post. – Puckster May 23 '17 at 21:07
  • You didn't say if you restarted apache after installing php. – symcbean May 23 '17 at 21:31
  • Good point. Yes. sudo service apache2 restart. – Puckster May 23 '17 at 21:45

1 Answers1

0

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!

Puckster
  • 1
  • 1
  • 5