Upgrade from php5 to php7 issue in apache

One application forced me to upgrade from php5 to php7. Now when I go to a local website it tries to open the php file instead of running the file which is simply index.php.

After some investigating I found out that it tried open the file like this:


however when accessing it like this:


it actually runs the file. In php5 it behaved correctly.

Also, I notices this:

<IfModule mod_php7.c>
       <FilesMatch "\.ph(p[345]?|tml)$">
           SetHandler application/x-httpd-php
       <FilesMatch "\.php[345]?s$">
           SetHandler application/x-httpd-php-source
        DirectoryIndex index.php4
        DirectoryIndex index.php5
        DirectoryIndex index.php

and I was wondering if it should be like this:

<IfModule mod_php7.c>
       <FilesMatch "\.ph(p[3457]?|tml)$">
           SetHandler application/x-httpd-php
       <FilesMatch "\.php[3457]?s$">
           SetHandler application/x-httpd-php-source
        DirectoryIndex index.php4
        DirectoryIndex index.php5
        DirectoryIndex index.php7
        DirectoryIndex index.php

Can you please confirm that the “it” you are talking about is Apache2?
And that the configuration parts you show are somewhere in the Apache 2 configuration files on the Apache server? And then please name that file!

apache version 2.4.

Of coarse they are from my setup that worked with php5 but now not php7. The version of apache has not changed from 2.4 but perhaps changed by some revision number that I didn’t notice.

the files is



Talking about “it” can be very confusing. I have seen cases here where people thought that the browser/client is responsible for processing the PHP and happily talked about “it” not doing it. Took some time before we found out that his “it” was Firefox where we thought “it” was Apache. The lesson is that one never can be too precise in describing computer problems. :wink:

What you think should be changed in /etc/apache2/conf.d/php7.conf are only suffixes of files that should be processed by PHP7 (you add the suffix php7 to the range). But as you use a file which ends in the suffix .php, it falls in that category already.

What you tell is that when having index.php in the URL it works as expected.
When omitting the file name, it falls back to directory indexing, but the DirectoryIndex statements tell it to use one of the files named there instead when available. Because index.php is there (I hope there are no other files there?) it will then serve index.php instead of doing directory indexing. But then it forgets to process it through php. Which worked in the PHP5 case.

Perhaps php7.conf is not included in your www.domain.local.conf file?
If this is a VirtualHost the file will probably either exist in /apache2/vhosts.d or there will be an entry in ip-based_vhosts.conf.
there is normally something like:

DocumentRoot /srv/www/vhosts.d/domain.local
 Include /etc/apache2/conf.d/*.conf

But you might have a list with php5.conf included.

Anyway please show your active server configuration files.

You would only need separate index.php[457] entries for DirectoryIndex if you actually had page files with those names. I just have index.html and assign .html to be parsed by the PHP module.

Fixed (for now, hopefully it stays) but I can’t say I know the exact reason.

I added a new PHP module, php7-macros in this case, and when it restarted it worked correctly. I did a visual compare of the before and after of the apache configuration files (using meld and comparing against my nightly backups) and it seems to have re-ordered the loading of the apache modules. Maybe there was just some configuration change that didn’t happen when it was supposed to and that adding of the php module caused it to correct itself or maybe php had an issue that was fixed when the module was added. One of those is my best guess but I don’t really know for sure.

Nice it works now, but a bit unsatisfactory.

My sentiments exactly.

So… I had to install a couple of more php7 modules and once I did the problem returned but this time it doesn’t recognise PHP at all and even with http://domain/index.php it opens up a save box instead of executing PHP. Uhg!

You need to enable php7 for apache2. Add it through YaST or through

sudo a2enmod php7 && sudo systemctl restart apache2.service

Clearly it’s enabled because sometimes it processes PHP, other times it doesn’t, on the same URL. I haven’t figured out what the factor is that causes it to succeed/fail processing PHP.