PHP合并CSS遇异常:同配置两虚拟主机结果不同,报loadproxy_fcgi错误
loadproxy_fcgi:error on Your Apache/PHP-FPM Setup Hey, let's dig into why your two seemingly identical virtual hosts are behaving differently and throwing that loadproxy_fcgi:error on your new Debian server. Given your setup (Apache 2.4 Event MPM + PHP 7.2 FPM) and the fact your CSS-merging PHP script worked for years, here are the most likely fixes to try:
1. Update Your Apache 2.4 Directory Permissions Syntax
Your current <Directory> block uses Apache 2.2-era rules (Order Deny,Allow + Allow from all). While Apache 2.4 supports these for backwards compatibility, they can cause weird permission glitches when paired with Event MPM and PHP-FPM. Swap it for the 2.4 standard syntax:
<Directory /var/www/balkenhantel> Require all granted AllowOverride All Options -Indexes </Directory>
Double-check that both virtual hosts have this updated config—even a tiny oversight here could throw things off.
2. Verify PHP-FPM Pool & Apache Proxy Configs
Since you're using Event MPM, you must run PHP via FPM (not mod_php). Make sure both vhosts are correctly pointing to the same FPM pool, and that Apache has the right modules loaded:
- First, enable the required Apache modules if you haven't already:
a2enmod proxy_fcgi setenvif - Then, add this PHP handler block to both vhosts (adjust the sock path if your FPM uses a different location):
<FilesMatch \.php$> SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost/" </FilesMatch>
If you set up separate FPM pools for each vhost, confirm the sock file permissions let the Apache user (www-data) access it—this is a super common cause of FPM connection failures.
3. Check File/Directory Permission Differences
Even if your vhost configs look identical, the actual file permissions in each site's DocumentRoot might not match:
- Run this to check ownership and permissions:
ls -l /var/www/
Ensure both balkenhantel and your other site directory are owned by www-data:www-data, or at least give www-data read access to all CSS files and the merging script.
- Also, check if either site has an
.htaccessor php.ini setting that restrictsopen_basedir—this could block the script from reading CSS files outside a specific directory.
4. Fix PHP 7.2 Compatibility Issues in Your CSS Merging Script
Your script worked for years, but PHP 7.2 deprecated/removed some older functions and tightened up defaults:
- Memory limits: If you're merging a lot of CSS files, PHP 7.2's default memory limit might be too low. Add this at the top of your script to bump it:
ini_set('memory_limit', '64M'); - Timeouts: If the merging process takes longer than expected, Apache or FPM might kill the request. Check your FPM pool config for
request_terminate_timeoutand Apache'sProxyTimeoutsetting, and increase them if needed. - File operations: Double-check that your script uses modern file functions (e.g.,
file_get_contentsinstead of outdated stream wrappers) and handles errors properly—PHP 7.2 is stricter about uncaught warnings.
5. Dig Into the Actual Error Logs
The loadproxy_fcgi:error is just a generic message—you need to look at the detailed logs to find the root cause:
- Apache error logs: Check
/var/log/apache2/error.logor the vhost-specific log files (if you set them up). - PHP-FPM logs: Look at
/var/log/php7.2-fpm.logor the log file for your specific FPM pool.
These logs will tell you exactly if it's a permission denied error, a script crash, or an FPM connection issue.
内容的提问来源于stack exchange,提问作者MrGlasspoole

