Apache24 and PHP 8.1

Hi all, I've read through several threads about this, but so far haven't seen anything that has helped me solve this. I have a machine running freeBSD 12.4 with Apache24 and PHP8.1. Sort of. A couple of days ago I updated from PHP74 to PHP81, and since then I've been unable to get Apache running with PHP. The logs aren't particularly helpful as from what I can tell Apache is crashing before the log is written. Here's some information that hopefully someone can help with. I'm pretty much an idiot with this - I run the server as a development platform.

Code:
# uname -a
FreeBSD hmgdev.com 12.4-RELEASE FreeBSD 12.4-RELEASE r372781 GENERIC  i386

Starting Apache:
Code:
# service apache24 start
Performing sanity check on apache24 configuration:
Syntax OK
Starting apache24.

However, Apache doesn't start and worse nothing is written to httpd-error.log

messages.log tells me
Code:
May  2 10:08:39 xxxx kernel: pid 14992 (httpd), jid 0, uid 0: exited on signal 11 (core dumped)

Here's my loaded Apache modules:
Code:
# httpd -M
Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 authn_file_module (shared)
 authn_core_module (shared)
 authz_host_module (shared)
 authz_groupfile_module (shared)
 authz_user_module (shared)
 authz_core_module (shared)
 access_compat_module (shared)
 auth_basic_module (shared)
 socache_shmcb_module (shared)
 reqtimeout_module (shared)
 filter_module (shared)
 deflate_module (shared)
 mime_module (shared)
 log_config_module (shared)
 env_module (shared)
 headers_module (shared)
 session_module (shared)
 setenvif_module (shared)
 version_module (shared)
 ssl_module (shared)
 mpm_prefork_module (shared)
 unixd_module (shared)
 status_module (shared)
 autoindex_module (shared)
 dir_module (shared)
 alias_module (shared)
 rewrite_module (shared)
 php_module (shared)

My PHP
Code:
php -v
PHP 8.1.17 (cli) (built: Apr  2 2023 01:32:18) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.17, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.17, Copyright (c), by Zend Technologies
    with Xdebug v3.2.1, Copyright (c) 2002-2023, by Derick Rethans
#

I disabled all php extensions for testing:

Code:
# php -m
[PHP Modules]
Core
date
hash
json
libxml
mysqlnd
openssl
pcre
Phar
Reflection
SPL
standard

[Zend Modules]


finally here's my http.conf

Code:
 cat /usr/local/etc/apache24/httpd.conf
ServerRoot "/usr/local"
Listen *:80

LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so
LoadModule authn_file_module libexec/apache24/mod_authn_file.so
LoadModule authn_core_module libexec/apache24/mod_authn_core.so
LoadModule authz_host_module libexec/apache24/mod_authz_host.so
LoadModule authz_groupfile_module libexec/apache24/mod_authz_groupfile.so
LoadModule authz_user_module libexec/apache24/mod_authz_user.so
LoadModule authz_core_module libexec/apache24/mod_authz_core.so
LoadModule access_compat_module libexec/apache24/mod_access_compat.so
LoadModule auth_basic_module libexec/apache24/mod_auth_basic.so
LoadModule socache_shmcb_module libexec/apache24/mod_socache_shmcb.so
LoadModule reqtimeout_module libexec/apache24/mod_reqtimeout.so
LoadModule filter_module libexec/apache24/mod_filter.so
LoadModule deflate_module libexec/apache24/mod_deflate.so
LoadModule mime_module libexec/apache24/mod_mime.so
LoadModule log_config_module libexec/apache24/mod_log_config.so
LoadModule env_module libexec/apache24/mod_env.so
LoadModule headers_module libexec/apache24/mod_headers.so
LoadModule session_module libexec/apache24/mod_session.so
LoadModule setenvif_module libexec/apache24/mod_setenvif.so
LoadModule version_module libexec/apache24/mod_version.so
LoadModule ssl_module libexec/apache24/mod_ssl.so
LoadModule unixd_module libexec/apache24/mod_unixd.so
LoadModule status_module libexec/apache24/mod_status.so
LoadModule autoindex_module libexec/apache24/mod_autoindex.so
LoadModule dir_module libexec/apache24/mod_dir.so
LoadModule alias_module libexec/apache24/mod_alias.so
LoadModule rewrite_module libexec/apache24/mod_rewrite.so
LoadModule php_module         libexec/apache24/libphp.so

IncludeOptional etc/apache24/modules.d/[0-9][0-9][0-9]_*.conf

<IfModule unixd_module>
  
    User www
    Group www

</IfModule>

ServerAdmin admin@somedomain.com


<Directory />
    AllowOverride none
    Require all denied
</Directory>

DocumentRoot "/usr/local/www/apache24/data"
<Directory /usr/local/www/apache24/data>
     Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
<Files ".ht*">
    Require all denied
</Files>
ErrorLog "/var/log/httpd-error.log"
LogLevel warn
<IfModule log_config_module>
    LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
    LogFormat "%h %l %u %t \"%r\" %>s %b" common
    <IfModule logio_module>
        LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
    </IfModule>
    CustomLog "/var/log/httpd-access.log" common
</IfModule>

<IfModule alias_module>
    ScriptAlias /cgi-bin/ "/usr/local/www/apache24/cgi-bin/"
</IfModule>

<Directory "/usr/local/www/apache24/cgi-bin">
    AllowOverride None
    Options None
    Require all granted
</Directory>

<IfModule headers_module>
    RequestHeader unset Proxy early
</IfModule>

<IfModule mime_module>
    TypesConfig etc/apache24/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
</IfModule>
<IfModule proxy_html_module>
    Include etc/apache24/extra/proxy-html.conf
</IfModule>

Include etc/apache24/extra/httpd-ssl.conf
<IfModule ssl_module>
    SSLRandomSeed startup builtin
    SSLRandomSeed connect builtin
</IfModule>


Include etc/apache24/Includes/*.conf

ServerTokens ProductOnly
KeepAlive on
I've reached the extent of my limited knowledge so if there's anyone who might have an idea what's breaking I would be extremely grateful for the advice!
 
There are a few issues with newer versions of PHP and at least one outstanding issue - but that seems to be more to do with FreeBSD 13.2.

Looks like you are running 32-bit i386 rather than 64-bit?
 
Have you tried to start apache24 without all the modules?

You could also try to comment out other lines of your httpd.conf.

Just try until it works. Or do it the other way around: comment out "everything" and then uncomment one and one line until it breaks again.
 
So, no... nothing in the https-error.log. If I disable libphp.so I"ll see the something along the lines of
Code:
[Tue May 02 10:25:38.191979 2023] [mpm_prefork:notice] [pid 16959] AH00171: Graceful restart requested, doing restart
[Tue May 02 10:25:38.207492 2023] [mpm_prefork:notice] [pid 16959] AH00163: Apache/2.4.56 (FreeBSD) OpenSSL/1.1.1q-freebsd configured -- resuming normal operations
[Tue May 02 10:25:38.207499 2023] [core:notice] [pid 16959] AH00094: Command line: '/usr/local/sbin/httpd'

but I'll see nothing at all written when libphp.so is enabled.

I'm running 32bit yes.. the development server (VM) is admittedly long in the tooth, but it had 'just worked' until this, or at least had broken in ways that I could stumble through fixing. My last resort is to move everything to a new VM, but that goes against my personality :)

I haven't tried disabling all the Apache modules, mainly because the vhosts wants a lot of em, but I will certainly try a bare bones attempt and let you know.

Thanks everyone!
 
but I'll see nothing at all written when libphp.so is enabled.
Then it's safe to assume it's mod_php that's crashing Apache. Might be a bit of a long shot but can you try installing www/mod_php81 from ports? I assume you installed everything with the FreeBSD packages?
 
I did use the packages, yes. I deleted mod_php81 and tried installing using ports. I got the following.

Code:
Performing sanity check on apache24 configuration:
Segmentation fault
Starting apache24.
Segmentation fault (core dumped)
/usr/local/etc/rc.d/apache24: WARNING: failed to start apache24

I forgot to mention I did also try disabling all the apache mods with the same result.
 
Alright, just ruling out some possible causes. Do you have to use mod_php or can your site run on php-fpm? That would circumvent the issue.
 
  • Thanks
Reactions: PPC
I tried using php-fpm, following some guides online. I was able to get the server to load, but got a ton of errors on my development sites, enough that I backed off until I could see if there was a way to fix what I had. My laziness has brought me full circle. If you could recommend a simpletons guide to getting php-fpm working, I'd be grateful.
 
in httpd.conf add the following, I'd recommend using the mpm_event rather than mpm_prefork, that's very old these day so disable that while you are here
Code:
#LoadModule mpm_prefork_module libexec/apache24/mod_mpm_prefork.so
LoadModule mpm_event_module libexec/apache24/mod_mpm_event.so

# modules required for php-fpm
LoadModule proxy_module libexec/apache24/mod_proxy.so
LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so
# disable the mod_php as we don't need that for fpm
# LoadModule php_module         libexec/apache24/libphp.so

<FilesMatch "\.php$">
        <If "-f %{REQUEST_FILENAME}">
            SetHandler  "proxy:unix:/var/run/yourdomain-php-fpm.sock|fcgi://localhost/"
        </If>
</FilesMatch>

in /usr/local/etc/php-fpm.conf, (these are mostly the default settings I think)
Code:
;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;
[global]
pid = run/php-fpm.pid
error_log = log/php-fpm.log
syslog.facility = daemon
syslog.ident = php-fpm
log_level = notice

emergency_restart_threshold = 2
emergency_restart_interval = 30
process_control_timeout = 60
process.max = 128
daemonize = yes

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;
include=/usr/local/etc/php-fpm.d/*.conf

in/usr/local/etc/php-fpm.d/yourdomain.conf:
Code:
;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ;
;;;;;;;;;;;;;;;;;;;;

[yourdomain]
user = www
group = www

listen = /var/run/$pool-php-fpm.sock
listen.owner = www
listen.group = www
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.max_requests = 500
request_terminate_timeout = 300
security.limit_extensions = .php

; php setting overrides
php_admin_value[error_log] = /var/log/fpm-php.$pool.log

then enable php-fpm and start service and restart apache24
Code:
sysrc php_fpm_enable="YES"
service php-fpm start
service apache24 restart

and that should be serving PHP using php-fpm
 
  • Thanks
Reactions: PPC
I once helped troubleshoot crashing apache on i386 here. Without coredump it's hard to say but it's worth checking out that link.

If it doesn't help please do provide the backtrace of it: gdb /usr/local/sbin/httpd /path/to/httpd.core, use the bt to show us the backtrace.
 
but got a ton of errors on my development sites, enough that I backed off until I could see if there was a way to fix what I had
Try the following php file on you apache site,
Code:
<?php
info();
?>

If phpinfo() works with PHP-FPM setup, but you're getting tons of errors, then that may be just php7 to php8 migration issues?

There are a couple open bugs with mod_php82 crashing apache.
 
I deployed 12i VM, installed the apache+php81 and did quick analysis of the problem. All packages were installed from binary packages. Problem is the same one I described before in the link I shared (register smashed, ebx points incorrectly to plt).

To solve this you need to compile the mod_php81 from packages and use gcc to do so. Howto is in that link too. For future googlers I'm putting it also here:

Code:
pkg install gcc
cd /usr/ports/www/mod_php81/
export CC=/usr/local/bin/gcc
make install clean
 
Back
Top