4

I updated php on my test platforms from php 7.4 to php 8.0. The update on the Centos 8 box works normally. The one on Centos 7 does not. The page with <?php phpinfo() ?> comes up blank while my tester page simply shows the code as text.

The command line seems to work:

[lhadmin@dho-dev01 ~]$ php --version
PHP 8.0.8 (cli) (built: Jun 29 2021 07:41:19) ( NTS gcc x86_64 )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies

[lhadmin@dho-dev01 ~]$ php -r 'echo "Hello World!\n";'
Hello World!

I tried uninstalling php and reinstalling httpd. Then I installed php again. Still no good. I can go back to php 7.4 and everything works.

The repos I'm switching between are remi-php74 and remi-php80.

Could there be any security policies suggested by cis-cat that might be interfering with this? I tried disabling selinux but that didn't do anything.


Thank you for your input.

First, we are not planning on moving to Centos 8 because of RHEL issues. We are looking at other distros. That choice is what they call "above my pay grade." I also don't think that php80 on centos 7 is the issue. I think there is something about this system, possibly related to security settings we've been implementing. We had a problem with a mail list because default permissions on /var/log were set to 600.

As Remi Collet mentioned, it should work out of the box. The package list is 923 lines long. Are there any packages in particular that I should be watching out for? I know apache is somehow interacting with php because the info page shows the text when php is not installed. It shows a blank page when it tries to access the function.

What I've tried:

On php 7.4 - everything works. phpinfo() shows PHP Version 7.4.21, etc.

Server version: Apache/2.4.48 (codeit) Server built: May 26 2021 11:40:06

7.4 config files:

    /etc/httpd/php.conf
    /etc/httpd/conf.module.d/15-php.conf
    /etc/httpd/modules/libphp7.so 
    /etc/httpd/modules/libphp7-zts.so 
    yum-config-manager --disable remi-php74
    yum-config-manager --enable remi-php80
    yum check-update  # verify 
    yum -y update

systemctl restart httpd # with php 8.0

Phpinfo() is a blank page. Php on the command line works, though.

8.0 config files:

    /etc/httpd/php.conf,
    /etc/httpd/conf.module.d/20-php.conf
    /etc/httpd/modules/libphp.so

Go back:

    yum remove php*
    yum-config-manager --disable remi-php80,
    yum-config-manager --enable remi-php74,
    systemctl restart httpd # with php 7.4

Repeat with different package settings.

My httpd config files:

autoindex.conf  php.conf  README  shib.conf  ssl.conf  ssl.conf.rpmnew  ssl.conf.rpmsave  userdir.conf  welcome.conf

I've even tried reinstalling httpd and building up from there. Still no go.

Contents of 20-php.conf

#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#

# Cannot load both php5, php7 and php modules
<IfModule !mod_php5.c>
  <IfModule !mod_php7.c>
    <IfModule prefork.c>
      LoadModule php_module modules/libphp.so
    </IfModule>
  </IfModule>
</IfModule>

Contents of php.conf :

#
# The following lines prevent .user.ini files from being viewed by Web clients.
#
<Files ".user.ini">
    <IfModule mod_authz_core.c>
        Require all denied
    </IfModule>
    <IfModule !mod_authz_core.c>
        Order allow,deny
        Deny from all
        Satisfy All
    </IfModule>
</Files>

#
# Allow php to handle Multiviews
#
AddType text/html .php

#
# Add index.php to the list of files that will be served as directory
# indexes.
#
DirectoryIndex index.php

# mod_php options
<IfModule  mod_php.c>
    #
    # Cause the PHP interpreter to handle files with a .php extension.
    #
    <FilesMatch \.(php|phar)$>
        SetHandler application/x-httpd-php
    </FilesMatch>

    #
    # Uncomment the following lines to allow PHP to pretty-print .phps
    # files as PHP source code:
    #
    #<FilesMatch \.phps$>
    #    SetHandler application/x-httpd-php-source
    #</FilesMatch>

    #
    # Apache specific PHP configuration options
    # those can be override in each configured vhost
    #
    php_value session.save_handler "files"
    php_value session.save_path    "/var/lib/php/session"
    php_value soap.wsdl_cache_dir  "/var/lib/php/wsdlcache"

    #php_value opcache.file_cache   "/var/lib/php/opcache"
</IfModule>
  • 1
    Welcome to Stackoverflow! You're expected to [try to solve the problem first](https://meta.stackoverflow.com/q/261592). Please update your question to show what you have already tried in a [minimal reproducible](https://stackoverflow.com/help/minimal-reproducible-example) example. For further information, please see [How to Ask](https://stackoverflow.com/questions/how-to-ask), and take the [tour](https://stackoverflow.com/tour). – hakre Jul 19 '21 at 18:49
  • 1
    Your question is pretty unclear what the problem is as you write yourself that you have two solutions: 1.) downgrade to PHP 7.4 2.) upgrade to centos 8. What is your problem then? – hakre Jul 19 '21 at 18:51
  • 1
    _" code as text."_: php is not installed, the webserver delivers the files as plain text. / _"The page with comes up blank"_ probably you mean the _white screen of death_, but its a guess. See [Nothing is seen. The page is empty and white.](https://stackoverflow.com/a/12772851) (also known as *White Page/Screen Of Death*) from the [PHP debugging reference](https://stackoverflow.com/q/12769982/367456). – hakre Jul 19 '21 at 18:56
  • Pure guess: because you use PHP as an Apache module and *php7_module* was renamed to just *php_module*? Can you provide your Apache configuration relative to PHP? – julp Jul 19 '21 at 19:14
  • both PHP 7.4 or 8.0 (or any other versions) should works out-of-the-box, the same way. So not enough information (at least, a list of installed packages) – Remi Collet Jul 20 '21 at 05:47
  • Can you prodive the content of /etc/httpd/conf.module.d/20-php.conf? > Phpinfo() is a blank page I assume, if you display its source, it literally shows "" right? – julp Jul 20 '21 at 19:25
  • Yes. The source is . This is visible when no php is loaded. It is a blank page when php80 is loaded. The contents of 20-php.conf are: # # PHP is an HTML-embedded scripting language which attempts to make it # easy for developers to write dynamically generated webpages. # # Cannot load both php5, php7 and php modules LoadModule php_module modules/libphp.so – Christopher Schulte Jul 21 '21 at 12:15
  • No error when you start Apache? Where is your line `AddType application/x-httpd-php ...` or better `SetHandler application/x-httpd-php`? In /etc/httpd/php.conf? Can you also remove the `IfModule` lines from 20-php.conf? – julp Jul 21 '21 at 12:56
  • I don't have a line that says 'AddType application/x-httpd-php ...'. I do have 'AddType text/html .php' at the beginning of the file. 'SetHandler application/x-httpd-php' is inside an IfModule mod_php.c block. I commented out the IfModule and httpd failed to start. Journalctl showed "Unregistered Authentication Agent for unix-process:2834:191900 (system bus name :1.39, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, local" – Christopher Schulte Jul 21 '21 at 15:57

1 Answers1

5

I got this working with many thanks going to julp.

I restarted httpd again with the IfModule conditionals commented out and looked more closely at the output from 'journalctl -xe' when httpd failed to restart.

The relevant error:

Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP.

A quick search showed that I needed to replace mod_mpm_event with mod_mpm_prefork in 00_mod_mpm.conf

# LoadModule mpm_event_module modules/mod_mpm_event.so
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so

I was curious so I compared my httpd configuration with other httpd on other servers.

Centos 8 with a working php80:

Server version: Apache/2.4.37 (centos)

Typical Centos 7:

Server version: Apache/2.4.6 (CentOS)

This Centos 7, which I wasn't able to update:

Server version: Apache/2.4.48 (codeit)

Since this is a development server, I experimented with non-backported versions of apache to stopped being flagged by security audits that my httpd was out of date, even though everyone knows about RHEL's backporting.