fix(cac-lsphp): normalize $_SERVER DOCUMENT_ROOT/SCRIPT_FILENAME to /home
The symlink makes __FILE__/__DIR__/realpath/getcwd report /home/<user>/public_html (WordPress/frameworks), but $_SERVER['DOCUMENT_ROOT']/['SCRIPT_FILENAME'] are raw env vars OLS sets to its /mnt/users view — apps that build/compare paths from them would see /mnt/users. Added a tiny auto_prepend (cac-lsphp-normalize.php, wired via a scan-dir ini) that realpath-canonicalises those two back to /home. Customer sites have no auto_prepend by default, so no conflict. Verified clean-room (committed image, fresh boot): DOCUMENT_ROOT and SCRIPT_FILENAME both report /home/<user>/public_html through the shared OLS. Now byte-for-byte 1:1 with cac-fpm/cac-litespeed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
30
scripts/cac-lsphp-normalize.php
Normal file
30
scripts/cac-lsphp-normalize.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
* cac-lsphp $_SERVER path normaliser (auto_prepend).
|
||||
*
|
||||
* The shared-ols container serves from its bulk /docker/users->/mnt/users mount,
|
||||
* so OLS sends lsphp $_SERVER['DOCUMENT_ROOT'] / ['SCRIPT_FILENAME'] under
|
||||
* /mnt/users/<user>/<domain>/... . The sidecar symlinks that back to the real
|
||||
* /home/<user> mount, so file operations resolve and PHP's own __FILE__/__DIR__/
|
||||
* realpath()/getcwd() already report /home/<user>/public_html. But the RAW env
|
||||
* strings OLS set still read /mnt/users, which would leak to the (uncommon) apps
|
||||
* that build or compare paths from $_SERVER['DOCUMENT_ROOT'].
|
||||
*
|
||||
* Canonicalise those two via realpath() so cac-lsphp is byte-for-byte 1:1 with
|
||||
* cac-fpm/cac-litespeed (where DOCUMENT_ROOT is natively /home/<user>/public_html).
|
||||
* Cheap (two realpath calls, cached by realpath_cache) and side-effect-free.
|
||||
*
|
||||
* Customer sites have no auto_prepend by default, so this is the only prepend in
|
||||
* play. If a site sets its own auto_prepend_file via .user.ini it overrides this
|
||||
* (theirs wins) — acceptable: paths still resolve via the symlink, only the raw
|
||||
* string differs.
|
||||
*/
|
||||
foreach (array('DOCUMENT_ROOT', 'SCRIPT_FILENAME') as $__cl_key) {
|
||||
if (!empty($_SERVER[$__cl_key]) && strncmp($_SERVER[$__cl_key], '/mnt/users/', 11) === 0) {
|
||||
$__cl_real = realpath($_SERVER[$__cl_key]);
|
||||
if ($__cl_real !== false) {
|
||||
$_SERVER[$__cl_key] = $__cl_real;
|
||||
}
|
||||
}
|
||||
}
|
||||
unset($__cl_key, $__cl_real);
|
||||
Reference in New Issue
Block a user