Migrating servers - php fcgi breaks after importing virtualmin domain backup

The dreaded “end of script headers before output” error that will not end!

I’ve been racking my brain for over week on this, I’m not even sure where to start listing everything I’ve tried (I’ve tried A LOT).

I’m migrating to new servers. The old servers were:
CentOS Linux 7.7.1908
Webmin 1.932
Usermin 1.780
Virtualmin 6.08

New servers are the same.

The only significant difference, is the old servers had more versions of php installed (5.4, 5.5, 5.6, 7.0, 7.1, 7.2). And the new servers are using Apache MPM event, the old servers used MPM worker. I did try using MPM worker as well. However, if I add new virtual domains to the server BEFORE I restore any domains from backup, those newly created domains work without issue.

The new servers have only 5.4, 7.0 and 7.2. However the domains I’m importing only use 7.2 or 7.0, so that shouldn’t be an issue.

I’ve tried importing virtualmin config settings first, no luck, I’ve tried manually configuring before import, no luck.

When I do the import, the only error I get is regarding let’s encrypt no longer supporting v1 client, so I manually add a self sign cert after import. And that appears to work.

Virtualmin re-check config shows the same both before and after importing the domain backup. (all passes, with the expected php versions shown). Validate virtual servers also passes without errors.

If I enable php-fpm for the domain, all 3 versions work. If I enable mod_php, that also works. However, if I try to use fcgi, or even cgi, I get the dreaded error. And for the life of me, I can not figure out why.

The real insanity here, is I migrated two servers. The first one is working perfectly, however I migrated that server at the beginning of October, when the webmin/virtualmin version was 1930/6.07. That first server works without any issues, even after being updated to 1.932 and 6.08

Virtualmin Config Check:

The status of your system is being checked to ensure that all enabled features are available, that the mail server is properly configured, and that quotas are active …
Your system has 31.26 GB of memory, which is at or above the Virtualmin recommended minimum of 256 MB.
Apache is installed.

The following PHP versions are available : 5.4.45 (/bin/php-cgi), 7.0.33 (/bin/php70-cgi), 7.2.24 (/bin/php72-cgi), 5.4 (mod_php)

The following PHP-FPM versions are available on this system : 5.4.45 (php-fpm) 7.0.33 (php70-php-fpm) 7.2.24 (php72-php-fpm)

Apache is configured to host SSL websites.

MariaDB 10.3.20 is installed and running.

Logrotate is installed.

Plugin Protected web directories is installed OK.

Using network interface eth0 for virtual IPs.

IPv6 addresses are available, using interface eth0.

Default IPv4 address for virtual servers is XXXXXX.

Default IPv6 address for virtual servers is XXXXXX.

Both user and group quotas are enabled for home and email directories.

All commands needed to create and restore backups are installed.

The selected package management and update systems are installed OK.

Chroot jails are available on this system

… your system is ready for use by Virtualmin.

Apache Config

SuexecUserGroup “#1002” “#1002
ServerName test.domain
ServerAlias www.test.domain
DocumentRoot /home/test.domain/public_html
ErrorLog /var/log/virtualmin/test.domain_error_log
CustomLog /var/log/virtualmin/test.domain_access_log combined
ScriptAlias /cgi-bin/ /home/test.domain/cgi-bin/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory /home/test.domain/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch +ExecCGI
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted
AddType application/x-httpd-php .php
AddHandler fcgid-script .php
AddHandler fcgid-script .php5
AddHandler fcgid-script .php7.0
AddHandler fcgid-script .php7.2
FCGIWrapper /home/test.domain/fcgi-bin/php7.2.fcgi .php
FCGIWrapper /home/test.domain/fcgi-bin/php5.fcgi .php5
FCGIWrapper /home/test.domain/fcgi-bin/php7.0.fcgi .php7.0
FCGIWrapper /home/test.domain/fcgi-bin/php7.2.fcgi .php7.2

<Directory /home/test.domain/cgi-bin>
allow from all
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
Require all granted

RemoveHandler .php
RemoveHandler .php5
RemoveHandler .php7.0
RemoveHandler .php7.2
php_admin_value engine Off
IPCCommTimeout 121
FcgidMaxRequestLen 1073741824

I’ve check owner:group permissions. I’ve disabled suex just to be sure that’s not involved. And i can not for the life of me figure out what I’m missing.

Any suggestions are appreciated. If there’s any additional info needed, just let me know what I need ot provide.

If I enable php-fpm for the domain, all 3 versions work. If I enable mod_php

IIRC - mod_php only works well with Apache’s Prefork MPM no Worker or Event. - https://medium.com/@jacksonpauls/moving-from-mod-php-to-php-fpm-914125a7f336

mod_php works fine. it’s fcgi that’s the problem.

can you try changing the php mode in website options, change to CGI wrapper, then change it back again

PHP script execution mode
Apache mod_php (run as Apache’s user)
CGI wrapper (run as virtual server owner)
FCGId (run as virtual server owner)
FPM (run as virtual server owner)

Thanks. I did try that. Neither CGI or FCGI work. This seems like some type of server configuration issue. But I just can’t figure out what that issue is.

I’m really confused by the fact that FPM works. I would think if FCGI has a problem, fpm couldn’t work either

Does anyone have any other ideas on this. I was never able to solve it, and ended up having to rebuild the entire server from scratch. Everything was working fine until I had to restore a backup yesterday, and now this dreaded error has returned.

I can not for the life of me figure out what is going wrong here. All is working, all is great. But if I restore a fully functional backup, FCGI breaks. No matter what I do, I can not get fcgi to work again, and I literally have no other option but to download every single site and database from the server…rebuild the entire server from scratch, and then manually add back the virtual servers, files, database to get this FCGI error to stop.

There has to be something I’m missing here. This just makes no sense. Something is getting corrupted when the backup is restored. I know it’s not the backup itself, becuase if I restore just one virtual server, every virtual server on the system breaks that uses fcgi. Even though I’m not restoring virtualmin settings, and literally only restoring one virtual server. Somehow, the virtualmin restore script changes something, that affects all virtual servers and breaks everything.

Please someone give me some hints where to look.