diff --git a/config/httpd.conf.template b/config/httpd.conf.template index f407124..1063549 100644 --- a/config/httpd.conf.template +++ b/config/httpd.conf.template @@ -29,9 +29,11 @@ LoadModule deflate_module modules/mod_deflate.so AcceptFilter http none AcceptFilter https none -# Required for PHP-FPM on Windows to avoid "No input file specified" +# Required for PHP-FPM on Windows ProxyFCGIBackendType GENERIC + # Fix for encoded spaces and special characters in Windows paths + SetEnv proxy-fcgi-pathinfo unescape ServerAdmin admin@localhost @@ -54,7 +56,7 @@ DocumentRoot "{{ROOT}}" ErrorLog "{{LOG_DIR}}/apache_error.log" -LogLevel warn +LogLevel warn proxy_fcgi:trace8 LogFormat "%h %l %u %t \"%r\" %>s %b" common diff --git a/config/php.ini.template b/config/php.ini.template index c3be093..37b9f14 100644 --- a/config/php.ini.template +++ b/config/php.ini.template @@ -45,6 +45,7 @@ session.save_path = "{{SESSION_DIR}}" upload_tmp_dir = "{{TEMP_DIR}}" sys_temp_dir = "{{TEMP_DIR}}" extension_dir = "{{EXT_DIR}}" +fastcgi.impersonate = 1 cgi.force_redirect = 0 cgi.fix_pathinfo = 1 diff --git a/tmp/fix_apache_configs.js b/tmp/fix_apache_configs.js new file mode 100644 index 0000000..889e958 --- /dev/null +++ b/tmp/fix_apache_configs.js @@ -0,0 +1,56 @@ +const fs = require('fs'); +const path = require('path'); + +const projectsDir = 'd:/Works/2026/multiphp/generated_configs/projects_apache'; + +if (!fs.existsSync(projectsDir)) { + console.log('No project configurations found.'); + process.exit(0); +} + +const confFiles = fs.readdirSync(projectsDir).filter(f => f.endsWith('.conf')); + +for (const file of confFiles) { + const filePath = path.join(projectsDir, file); + console.log(`Updating ${filePath}...`); + let content = fs.readFileSync(filePath, 'utf8'); + + // Extract HOST and PATH from Alias line + const aliasRegex = /Alias\s+\/([^\s]+)\s+"([^"]+)"/; + const match = content.match(aliasRegex); + + if (match) { + const hostname = match[1]; + let filepath = match[2]; + + // Extract PORT from current SetHandler (if present) + const portRegex = /proxy:fcgi:\/\/127\.0\.0\.1:(\d+)/; + const portMatch = content.match(portRegex); + const port = portMatch ? portMatch[1] : '9001'; + + // Ensure filepath ends with / + if (!filepath.endsWith('/')) filepath += '/'; + + // THE TRICK: URL-encode spaces in the path for ProxyPassMatch + const encodedPath = filepath.replace(/ /g, '%20'); + + // Re-construct the file: Keep Alias and Directory, replace PHP logic + const directoryBlockRegex = /[\s\S]*?<\/Directory>/; + let newContent = content.match(directoryBlockRegex)[0]; + + // Remove SetHandler from Directory block + newContent = newContent.replace(/[\s\S]*?<\/FilesMatch>/g, ''); + + // Start fresh: Alias + Directory + ProxyPassMatch + const finalContent = `Alias /${hostname} "${filepath}" +${newContent} + +# Explicit PHP mapping for ${hostname} (ProxyPassMatch pattern) +ProxyPassMatch "^/${hostname}/(.*\\.php(/.*)?)$" "fcgi://127.0.0.1:${port}/${encodedPath}$1" +`; + + fs.writeFileSync(filePath, finalContent, 'utf8'); + } +} + +console.log('Done.'); diff --git a/tmp/restore_slashes.js b/tmp/restore_slashes.js new file mode 100644 index 0000000..4a77a31 --- /dev/null +++ b/tmp/restore_slashes.js @@ -0,0 +1,41 @@ +const fs = require('fs'); +const path = require('path'); + +const generatedDir = path.join('d:/Works/2026/multiphp', 'generated_configs'); +const projectsDir = path.join(generatedDir, 'projects_apache'); + +function fixApacheConfig(filePath) { + if (!fs.existsSync(filePath)) return; + console.log(`Updating ${filePath}...`); + let content = fs.readFileSync(filePath, 'utf8'); + + // ENSURE trailing slash in SetHandler (opposite of my previous mistake) + // Match proxy:fcgi://127.0.0.1:PORT and ensure it ends with / + const newContent = content.replace(/SetHandler "proxy:fcgi:\/\/127\.0\.0\.1:(\d+)(?!\/)"/g, 'SetHandler "proxy:fcgi://127.0.0.1:$1/"'); + + // Ensure ProxyFCGIBackendType GENERIC is there (it should be in global httpd.conf) + let finalContent = newContent; + if (path.basename(filePath) === 'httpd.conf') { + if (!finalContent.includes('ProxyFCGIBackendType GENERIC')) { + // Find a good place, maybe after LoadModule + finalContent = finalContent.replace(/(LoadModule proxy_fcgi_module .+)/, '$1\n\n\n ProxyFCGIBackendType GENERIC\n'); + } + } + + fs.writeFileSync(filePath, finalContent, 'utf8'); +} + +// 1. Global config +fixApacheConfig(path.join(generatedDir, 'httpd.conf')); + +// 2. Project configs +if (fs.existsSync(projectsDir)) { + const projectFiles = fs.readdirSync(projectsDir); + for (const file of projectFiles) { + if (file.endsWith('.conf')) { + fixApacheConfig(path.join(projectsDir, file)); + } + } +} + +console.log('Done.');