-1

i have apache2 running as a local server. I had a wordpress site on localhost running happily. In trying to enable running phpMyAdmin apache2 somehow stopped executing php code, and I've been unable to re-enable it. any help most gratefully received

ruth
  • 3
  • 4
  • A bit of research will show you the usual culprits. Most probably the LoadModule line is commented out in httpd.conf. – Nic3500 Aug 07 '20 at 20:12
  • hi @Nic3500. i've been searching around for a solution, but unsuccessfully which is why i posted my question. Anyway: the loadmodule does include a line for php7, so that's not the problem. I've turned up logging to 'debug' - and now see (a) php7 is configured but (b) Python initialising. also if try to use index.php rather than index.html i'm presented with the file to open, rather than it executed. I guess part of the same problem. I'll go on digging, but if you have any other suggestions they'd be welcome. many thanks – ruth Aug 11 '20 at 11:33
  • There should be: **1** `LoadModule php7_module modules/libphp7.so`. And **2** ` SetHandler application/x-httpd-php `. This will configure all files that start with `ph`. Like .php and .phtml. The handler defines which extension files are processed by PHP. – Nic3500 Aug 11 '20 at 18:40
  • thanks @nic3500. 1. my loadmodule line is "LoadModule php7_module /usr/lib64/apache2/mod_php7.so" - which i believe is correct for my system. the .so file does exist owned root, permission 755. 2. I added the 'FilesMatch' line that you suggested into the file 'conf.d/php7.conf' - is this the correct file?. The problem hasn't changed i'm afraid. do you have any other suggestions? i'll go on exploring of course... – ruth Aug 12 '20 at 10:46
  • hi @nic3500 one problem solved - i can run a .php file, such as index.php: for various reasons i installed opensuse leap 15.2 (the next version of my o.s.) and so reinstalled apache2. enabled php module and apache2 complained php was not compiled for MPM threaded (the default). restarted apache2 with prefork instead. now i can execute .php files, such as index.php successfully. this doesn't explain why i was having problems with the earlier system, but does mean i can progress. I'm still unable to run php from within an .html file however, which should be possible? – ruth Aug 15 '20 at 14:56
  • Hi, the `` lines define which files should be handled as PHP script files. The example I posted earlier define `*.php` and `*.phtml` as PHP script files. If you want to have *.html files also processed, you have to add ` SetHandler application/x-httpd-php `. – Nic3500 Aug 16 '20 at 23:32
  • Great, I created an answer based on the comments. I would be grateful if you accepted it (check mark on the left of the answer). – Nic3500 Aug 19 '20 at 22:54

2 Answers2

0

This is a configuration issue.

There should be a line:

LoadModule php7_module        modules/libphp7.so. 

And:

<FilesMatch "\.ph(p?|tml)$"> 
     SetHandler application/x-httpd-php 
</FilesMatch> 

This will configure all files that start with ph. Like .php and .phtml. The handler defines which extension files are processed by PHP.

If you need to have .html files processed by PHP as well, you can put:

<FilesMatch ".html)$"> 
     SetHandler application/x-httpd-php 
</FilesMatch> 

Note that all your .html files would then be processes through the PHP interpreter.

Nic3500
  • 8,144
  • 10
  • 29
  • 40
  • thanks nic. and just to note that for openSuse linux the php7 module is found in /usr/lib64/apache2/mod_php7.so for the LoadModule directive. – ruth Aug 21 '20 at 07:42
0

My problem was that I used the Brave Browser. That seemed to be the problem. PHP on apache2 and OpenSuse was working perfectly fine on all other major browsers (Chrome, Firefox, Edge).

Behemoth
  • 5,389
  • 4
  • 16
  • 40