Apache2 HTTP server does not execute php code

Recently I have switched from Leap 42.3 to Leap 15.
Now I have configured an HTTP server through Yast2; if I try to open a local page containing php code, the server asks me for downloading the php file instead of execute it.
The server configuration in Leap 15 is identical to the Leap 42.3 one; the only difference is that Leap 42.3 provides php5, while Leap 15 provides php7.
The package apache2-mod_php7 is installed and in Yast2 the php7 module is enabled.

Bug report I submitted on this:

https://bugzilla.suse.com/show_bug.cgi?id=1099106

Go back into the YaST HTTP Server configuration and make sure the http server is enabled to start on boot and the firewall port is open.
Add the mod7 module. It should be enabled when you add it, but insure that it is.

PHP should then work.

In /etc/apache2/conf.d there should be a file php7.conf


dmzweb:/etc/apache2/conf.d # cat php7.conf 
<IfModule mod_php7.c>
       <FilesMatch "\.ph(p[345]?|tml)$">
           SetHandler application/x-httpd-php
       </FilesMatch>
       <FilesMatch "\.php[345]?s$">
           SetHandler application/x-httpd-php-source
       </FilesMatch>
        DirectoryIndex index.php4
        DirectoryIndex index.php5
        DirectoryIndex index.php
</IfModule>

dmzweb:/etc/apache2/conf.d # ls -l php7.conf
-rw-r--r-- 1 root root 354 May 18 09:19 php7.conf
dmzweb:/etc/apache2/conf.d # 

In /etc/apached2/sysconfig.d there should be a file loadmodule.conf. the last line on mine is:


dmzweb:/etc/apache2/sysconfig.d # tail -1 loadmodule.conf 
LoadModule php7_module /usr/lib64/apache2/mod_php7.so
dmzweb:/etc/apache2/sysconfig.d # 

Hope that solves the issue.

Have you enabled your php7 Apache2 module?

a2enmod php7

TSU

I does not work.
As I have written before, all the configuration files are identical to the leap 42.3 ones; all required modules are loaded and enabled, but I still get the message: “What should Firefox do with this file?” (Open with Kate / Save).

P.S. Now I have discovered that Google Chrome executes PHP code in my HTTP server; so, it seems a Firefox configuration problem.

OK! I have discovered the problem!
In Leap 42.3 I can enter the server writing either “localhost” or “127.0.0.1” in the Firefox address bar, and php scripts are correctly executed.
For some strange reason, Firefox under Leap 15 distinguishes between “localhost” and “127.0.0.1”; only with “127.0.0.1” php scripts are executed.

Wonder if that is because if you ping localhost (at least in my case), it pings through IPv6 ::1

Edit: It is actually ::1

Exactly!
But only Firefox has this issue.
Konqueror also works with either localhost (::1) or 127.0.0.1.

Additional information. Apache documentation says: “IPv6 addresses must be enclosed in square brackets”.

So, in the Firefox address bar you have to write ::1].
localhost is incorrect because it will be translated to ::1 instead of ::1].

You should post your /etc/hosts for inspection.

TSU

It is identical to the Leap 42.3 one.

/etc/hosts


#    
# IP-Address  Full-Qualified-Hostname  Short-Hostname
#

127.0.0.1       localhost

# special IPv6 addresses
::1             localhost ipv6-localhost ipv6-loopback

fe00::0         ipv6-localnet

ff00::0         ipv6-mcastprefix
ff02::1         ipv6-allnodes
ff02::2         ipv6-allrouters
ff02::3         ipv6-allhosts

Remove you FF history, cookies etc. And, do restart FF if you change things on the webserver side. FF can behave really weird.

You may also want to check the box in YaST Networksettings - Hostname / DNS for hostname to loopback-ip.

Yes, but not only “in the Firefox address bar”, but “in general”. :wink:

For example, what about ::1:80? Is :80 the port number or part of the IPv6 address?

To solve that ambiguity is why, in general, in URLs one has to enclose the IPv6 address between square brackets.

So, http://::1]/ and http://::1]:8080/, etc.

See e.g. IPv6 address - Wikipedia for more information.

Kind regards,

Leen

I do not understand this at all.
What you type in the address bar of FF is to begin with only relevant to FF. It has to resolve a host/domain name (when there) and then use the (resulting) IP address - port combination to use TCP/IP to connect to the wanted system and port. I do not think that that part of the URL is ever transferred to the server software (Apache). Of course the part after the // is (in the HTTP protocol) because that is used to tell the server (Apache) what to do.

Looks illogical to me that Apache prescribes you how you specify the server’s IP address/port combination in your client, whatever the client may be.

Or am I complete wrong here?

I think I can answer ny own question.

While it may heb been somewhere in an Apache document iy does not mean that Apache defines it as such. That must have been a quote or rewrite of the definition of an URL/URI. So I apparently missed the context of your citation.

Found in Wikipedia:

A non-empty host subcomponent, consisting of either a registered name (including but not limited to a hostname), or an IP address. IPv4 addresses must be in dot-decimal notation, and IPv6 addresses must be enclosed in brackets (]).

And indeed, when I type

::1]

in my FF address bar, I get the mainpage of my local Apache.

Also have a look in FF’s settings for handling of file extensions. I remember seeing FF having an entry there for .php files, where it shouldn’t.

Am thinking you may have an issue with the CN with your SSL certificate and how strictly domain name verification is done in the problem web browser (FF in your case). This is one of the possible uses of SSL which is to verify the address you’ve typed in your address bar to avoid phishing attacks. Since this capability was implemented, often times the browser might display a warning like turning an icon in the address bar red, but I think nowadays some think that’s not enough and are pro-actively denying access outright.

Perhaps at one time you were prompted to create a certificate exception and you declined to do so.
Perhaps the current set policy in your browser is to deny access without allowing you to create an exception, I’m now seeing this in Microsoft Edge in Win10 after the infamous April 2018 update which can be really irritating because I feel as a User I should be able to over-ride when I know the reason why a certificate CN might not match the name in the address bar.

But at least in Win10, the Edge browser clearly says why the website can’t/won’t be rendered, you don’t seem to describe a similar error message clearly saying why the browser won’t connect (or, maybe it’s there but you haven’t posted it).

TSU

Thanks Knurpht. This suggestion (probably) has solved the problem, but I’m not sure; anyhow, now “localhost” works. After installing Leap 15, I have imported cookies, bookmarks, etc. from the old Firefox profile; so, I suspect that in the old settings, there was something wrong.
I have also found a tabulation character in /etc/hosts between “127.0.0.1” and “localhost”, but I don’t think that that was the problem; in fact, Google Chrome and Konqueror were not affected.

Thanks! I have spent about 7 hours on this with 42.3 and V 15.
About to dump openSuse.