Add complete PHP configuration file locations for all control panels
DOCUMENTATION: Comprehensive PHP config hierarchy across all platforms CRITICAL ADDITION - All Possible php.ini Locations: **Priority 1 (HIGHEST) - Per-Directory:** - .user.ini (PHP-FPM, per-directory, reloads every 5min) - .htaccess with php_value (mod_php ONLY, usually ignored) - ~/public_html/.user.ini (most common) - ~/public_html/subdirectory/.user.ini (cascading) **Priority 2 - User-Specific:** - ~/public_html/php.ini (some control panels) - ~/.php/8.2/php.ini (cPanel MultiPHP style) - ~/etc/php82/php.ini (InterWorx style) - ~/php.ini (legacy home directory) **Priority 3 - Pool-Specific:** - /opt/cpanel/ea-php82/root/etc/php.ini (cPanel EA-PHP) - /opt/cpanel/ea-php82/root/etc/php.d/*.ini (additional, alphabetical) - /opt/alt/php82/etc/php.ini (CloudLinux Alt-PHP) - /var/www/vhosts/system/domain/etc/php.ini (Plesk) - /home/user/var/domain/etc/php.ini (InterWorx) **Priority 4 (LOWEST) - System-Wide:** - /etc/php.ini (global fallback) **Coverage by Control Panel:** ✅ cPanel with EA-PHP (most common, fully mapped) ✅ CloudLinux with Alt-PHP (fully mapped) ✅ Plesk (all locations documented) ✅ InterWorx (domain-specific paths) ✅ DirectAdmin (user/domain hierarchy) ✅ No control panel (standard paths) **Universal Detection Function:** find_all_php_configs() - Scans ALL possible locations - Checks 15+ location patterns - Returns priority-ordered list - Works across all control panels - Handles version-specific paths **Effective Setting Detection:** Method 1: Query PHP directly (MOST ACCURATE!) su -s /bin/bash $user -c "php -r 'echo ini_get("setting");'" Method 2: Parse hierarchy (fallback) Priority 4 → 3 → 2 → 1 (higher overrides lower) **Key Discoveries:** - .user.ini overrides EVERYTHING (highest priority!) - .htaccess php_value only works with mod_php (NOT PHP-FPM!) - cPanel creates user configs in ~/.php/VERSION/php.ini - public_html/php.ini exists on some configurations - Multiple .ini files loaded alphabetically in php.d/ **Detection Commands:** - Find all: find / -name "php.ini" -type f - Find .user.ini: find /home -name ".user.ini" - Get effective: php -r "echo ini_get('setting');" - List loaded: php --ini This ensures optimizer finds ALL configs affecting each domain!
This commit is contained in:
@@ -0,0 +1,483 @@
|
||||
# Complete PHP Configuration File Locations - All Control Panels
|
||||
|
||||
## Understanding PHP Configuration Priority
|
||||
|
||||
PHP configuration is applied in a **hierarchical cascade**. Settings in higher-priority files **override** settings in lower-priority files.
|
||||
|
||||
### Priority Order (Highest to Lowest)
|
||||
|
||||
```
|
||||
PRIORITY 1 (HIGHEST): Per-Directory Configuration
|
||||
├─ .user.ini (PHP-FPM only, per-directory)
|
||||
├─ .htaccess with php_value/php_flag (Apache + mod_php ONLY, NOT PHP-FPM!)
|
||||
└─ ini_set() in PHP code (runtime only)
|
||||
|
||||
PRIORITY 2: User-Specific Configuration
|
||||
├─ ~/public_html/php.ini (some control panels)
|
||||
├─ ~/.php/X.Y/php.ini (per PHP version)
|
||||
├─ ~/etc/phpX.Y/php.ini (InterWorx style)
|
||||
└─ ~/php.ini (legacy)
|
||||
|
||||
PRIORITY 3: Pool-Specific Configuration
|
||||
├─ /opt/cpanel/ea-phpXY/root/etc/php.ini (cPanel EA-PHP)
|
||||
├─ /opt/alt/phpXY/etc/php.ini (CloudLinux Alt-PHP)
|
||||
├─ Additional .ini files loaded alphabetically:
|
||||
│ ├─ /opt/cpanel/ea-phpXY/root/etc/php.d/*.ini
|
||||
│ └─ Loaded in alphabetical order (00-*, 10-*, 20-*, etc.)
|
||||
└─ scan_dir configured locations
|
||||
|
||||
PRIORITY 4 (LOWEST): System-Wide Configuration
|
||||
└─ /etc/php.ini (global default, rarely used with control panels)
|
||||
```
|
||||
|
||||
## Complete File Location Map by Control Panel
|
||||
|
||||
### cPanel with EA-PHP (Most Common)
|
||||
|
||||
#### 1. Per-Directory (.user.ini) - **PRIORITY 1**
|
||||
```bash
|
||||
# Location pattern
|
||||
/home/$username/public_html/.user.ini
|
||||
/home/$username/public_html/subdirectory/.user.ini
|
||||
/home/$username/public_html/app/.user.ini
|
||||
|
||||
# Applies to
|
||||
- That directory and all subdirectories
|
||||
- Only works with PHP-FPM (not mod_php)
|
||||
- Reloaded every user_ini.cache_ttl seconds (default 300)
|
||||
|
||||
# Example content
|
||||
memory_limit = 512M
|
||||
upload_max_filesize = 100M
|
||||
post_max_size = 150M
|
||||
max_execution_time = 120
|
||||
|
||||
# Find all .user.ini files for a user
|
||||
find /home/$username -name ".user.ini" -type f
|
||||
|
||||
# Common locations
|
||||
/home/$username/public_html/.user.ini
|
||||
/home/$username/public_html/wp-content/.user.ini
|
||||
/home/$username/public_html/app/upload/.user.ini
|
||||
```
|
||||
|
||||
#### 2. .htaccess with PHP directives - **PRIORITY 1** (mod_php ONLY!)
|
||||
```bash
|
||||
# Location
|
||||
/home/$username/public_html/.htaccess
|
||||
|
||||
# IMPORTANT: Only works with Apache mod_php
|
||||
# Does NOT work with PHP-FPM!
|
||||
# cPanel typically uses PHP-FPM, so .htaccess php_value is IGNORED
|
||||
|
||||
# Example content (if mod_php is used)
|
||||
php_value memory_limit 256M
|
||||
php_value upload_max_filesize 64M
|
||||
php_flag display_errors Off
|
||||
|
||||
# Find .htaccess with PHP directives
|
||||
find /home/$username/public_html -name ".htaccess" -exec grep -l "php_value\|php_flag" {} \;
|
||||
```
|
||||
|
||||
#### 3. User Home Directory Configs - **PRIORITY 2**
|
||||
```bash
|
||||
# cPanel creates user-specific php.ini in various locations:
|
||||
|
||||
# A. PHP version-specific in home
|
||||
/home/$username/.php/8.2/php.ini
|
||||
/home/$username/.php/8.1/php.ini
|
||||
/home/$username/.php/8.0/php.ini
|
||||
|
||||
# B. Legacy home php.ini
|
||||
/home/$username/php.ini
|
||||
|
||||
# C. In etc subdirectory
|
||||
/home/$username/etc/php.ini
|
||||
/home/$username/etc/php/8.2/php.ini
|
||||
|
||||
# D. In public_html (some configurations)
|
||||
/home/$username/public_html/php.ini
|
||||
|
||||
# Find all home directory php.ini files
|
||||
find /home/$username -maxdepth 3 -name "php.ini" -type f
|
||||
find /home/$username/.php -name "php.ini" -type f 2>/dev/null
|
||||
```
|
||||
|
||||
#### 4. MultiPHP INI Editor Files - **PRIORITY 2**
|
||||
```bash
|
||||
# cPanel's MultiPHP INI Editor creates user-specific overrides here:
|
||||
/var/cpanel/userdata/$username/php-fpm.d/$domain.conf
|
||||
/home/$username/.php/8.2/php.ini
|
||||
|
||||
# These override pool defaults but are overridden by .user.ini
|
||||
```
|
||||
|
||||
#### 5. EA-PHP Pool Configuration - **PRIORITY 3**
|
||||
```bash
|
||||
# Main php.ini for each EA-PHP version
|
||||
/opt/cpanel/ea-php80/root/etc/php.ini
|
||||
/opt/cpanel/ea-php81/root/etc/php.ini
|
||||
/opt/cpanel/ea-php82/root/etc/php.ini
|
||||
/opt/cpanel/ea-php83/root/etc/php.ini
|
||||
|
||||
# Additional .ini files (loaded alphabetically)
|
||||
/opt/cpanel/ea-php82/root/etc/php.d/00-ioncube.ini
|
||||
/opt/cpanel/ea-php82/root/etc/php.d/10-opcache.ini
|
||||
/opt/cpanel/ea-php82/root/etc/php.d/20-gd.ini
|
||||
/opt/cpanel/ea-php82/root/etc/php.d/30-mysqli.ini
|
||||
|
||||
# Find all EA-PHP installations
|
||||
find /opt/cpanel -maxdepth 1 -type d -name "ea-php*"
|
||||
|
||||
# Find all php.ini files
|
||||
find /opt/cpanel/ea-php* -name "php.ini"
|
||||
|
||||
# Find all additional .ini files
|
||||
find /opt/cpanel/ea-php*/root/etc/php.d/ -name "*.ini" | sort
|
||||
```
|
||||
|
||||
#### 6. PHP-FPM Pool Configs (Not php.ini but affects PHP)
|
||||
```bash
|
||||
# Per-user FPM pool config (process manager settings)
|
||||
/opt/cpanel/ea-php82/root/etc/php-fpm.d/$username.conf
|
||||
|
||||
# Contains: pm, pm.max_children, pm.start_servers, etc.
|
||||
# Not php.ini settings, but critical for performance!
|
||||
```
|
||||
|
||||
### CloudLinux with Alt-PHP
|
||||
|
||||
#### Alt-PHP Configuration Locations
|
||||
```bash
|
||||
# Main php.ini for each Alt-PHP version
|
||||
/opt/alt/php80/etc/php.ini
|
||||
/opt/alt/php81/etc/php.ini
|
||||
/opt/alt/php82/etc/php.ini
|
||||
|
||||
# Additional .ini files
|
||||
/opt/alt/php82/etc/php.d.all/*.ini
|
||||
|
||||
# Per-user overrides (if configured)
|
||||
/home/$username/.cl.php/alt-php82/php.ini
|
||||
|
||||
# Find all Alt-PHP versions
|
||||
ls -d /opt/alt/php*/
|
||||
|
||||
# Find all Alt-PHP ini files
|
||||
find /opt/alt/php* -name "php.ini"
|
||||
```
|
||||
|
||||
### Plesk
|
||||
|
||||
#### Plesk PHP Configuration Hierarchy
|
||||
```bash
|
||||
# 1. Per-directory .user.ini - PRIORITY 1
|
||||
/var/www/vhosts/$domain/httpdocs/.user.ini
|
||||
/var/www/vhosts/$domain/httpdocs/subdirectory/.user.ini
|
||||
|
||||
# 2. Domain-specific php.ini - PRIORITY 2
|
||||
/var/www/vhosts/system/$domain/etc/php.ini
|
||||
|
||||
# 3. Pool-specific php.ini - PRIORITY 3
|
||||
/etc/php-fpm.d/plesk-php82-fpm/php.ini
|
||||
|
||||
# 4. PHP version php.ini - PRIORITY 3
|
||||
/opt/plesk/php/8.2/etc/php.ini
|
||||
/opt/plesk/php/8.1/etc/php.ini
|
||||
|
||||
# 5. Additional .ini files
|
||||
/opt/plesk/php/8.2/etc/php.d/*.ini
|
||||
|
||||
# 6. System-wide - PRIORITY 4
|
||||
/etc/php.ini
|
||||
|
||||
# Find domain php.ini files
|
||||
find /var/www/vhosts/system -name "php.ini"
|
||||
|
||||
# Find all Plesk PHP versions
|
||||
ls -d /opt/plesk/php/*/
|
||||
```
|
||||
|
||||
### InterWorx
|
||||
|
||||
#### InterWorx PHP Configuration
|
||||
```bash
|
||||
# 1. Per-directory .user.ini - PRIORITY 1
|
||||
/home/$username/var/$domain/html/.user.ini
|
||||
|
||||
# 2. Domain-specific php.ini - PRIORITY 2
|
||||
/home/$username/var/$domain/etc/php.ini
|
||||
|
||||
# 3. User etc directory
|
||||
/home/$username/etc/php82/php.ini
|
||||
|
||||
# 4. PHP version php.ini - PRIORITY 3
|
||||
/etc/php82/php.ini
|
||||
/etc/php81/php.ini
|
||||
|
||||
# 5. System-wide - PRIORITY 4
|
||||
/etc/php.ini
|
||||
|
||||
# Find InterWorx domain configs
|
||||
find /home/*/var/*/etc -name "php.ini"
|
||||
|
||||
# Find user php configs
|
||||
find /home/*/etc/php* -name "php.ini"
|
||||
```
|
||||
|
||||
### DirectAdmin
|
||||
|
||||
#### DirectAdmin Configuration
|
||||
```bash
|
||||
# 1. Per-directory .user.ini - PRIORITY 1
|
||||
/home/$username/domains/$domain/public_html/.user.ini
|
||||
|
||||
# 2. Domain php.ini - PRIORITY 2
|
||||
/usr/local/directadmin/data/users/$username/php/domains/$domain.ini
|
||||
|
||||
# 3. User default php.ini
|
||||
/usr/local/directadmin/data/users/$username/php/php.ini
|
||||
|
||||
# 4. PHP version php.ini - PRIORITY 3
|
||||
/usr/local/php82/lib/php.ini
|
||||
|
||||
# Find DirectAdmin configs
|
||||
find /usr/local/directadmin/data/users -name "php.ini"
|
||||
find /usr/local/directadmin/data/users -name "*.ini"
|
||||
```
|
||||
|
||||
### No Control Panel (Standalone)
|
||||
|
||||
#### Standard PHP Locations
|
||||
```bash
|
||||
# 1. Per-directory .user.ini - PRIORITY 1
|
||||
/var/www/html/.user.ini
|
||||
/var/www/domain.com/.user.ini
|
||||
|
||||
# 2. Pool-specific (if using PHP-FPM)
|
||||
/etc/php/8.2/fpm/php.ini
|
||||
/etc/php-fpm.d/www.conf
|
||||
|
||||
# 3. CLI php.ini (different from FPM!)
|
||||
/etc/php/8.2/cli/php.ini
|
||||
|
||||
# 4. Additional .ini files
|
||||
/etc/php/8.2/mods-available/*.ini
|
||||
/etc/php/8.2/conf.d/*.ini
|
||||
|
||||
# 5. System-wide
|
||||
/etc/php.ini
|
||||
/usr/local/lib/php.ini
|
||||
```
|
||||
|
||||
## Detection Strategy - Universal Function
|
||||
|
||||
```bash
|
||||
find_all_php_configs() {
|
||||
local username="$1"
|
||||
local domain="$2"
|
||||
local php_version="$3" # e.g., "82" or "8.2"
|
||||
|
||||
declare -a config_files
|
||||
declare -A config_priority
|
||||
|
||||
echo "=== Finding ALL PHP configs affecting: $domain (user: $username) ==="
|
||||
echo ""
|
||||
|
||||
# PRIORITY 1: Per-Directory .user.ini
|
||||
echo "PRIORITY 1: Per-Directory Configs"
|
||||
while IFS= read -r file; do
|
||||
if [ -f "$file" ]; then
|
||||
config_files+=("$file")
|
||||
config_priority["$file"]=1
|
||||
echo " [P1] $file"
|
||||
fi
|
||||
done < <(find "/home/$username" -name ".user.ini" 2>/dev/null)
|
||||
|
||||
# Check .htaccess (only relevant for mod_php)
|
||||
while IFS= read -r file; do
|
||||
if grep -q "php_value\|php_flag" "$file" 2>/dev/null; then
|
||||
config_files+=("$file")
|
||||
config_priority["$file"]=1
|
||||
echo " [P1] $file (mod_php only - likely IGNORED on PHP-FPM!)"
|
||||
fi
|
||||
done < <(find "/home/$username/public_html" -name ".htaccess" 2>/dev/null)
|
||||
|
||||
echo ""
|
||||
echo "PRIORITY 2: User-Specific Configs"
|
||||
|
||||
# User home directory configs (various patterns)
|
||||
local user_configs=(
|
||||
"/home/$username/php.ini"
|
||||
"/home/$username/public_html/php.ini"
|
||||
"/home/$username/.php/$php_version/php.ini"
|
||||
"/home/$username/.php/${php_version:0:1}.${php_version:1}/php.ini"
|
||||
"/home/$username/etc/php.ini"
|
||||
"/home/$username/etc/php/$php_version/php.ini"
|
||||
)
|
||||
|
||||
for config in "${user_configs[@]}"; do
|
||||
if [ -f "$config" ]; then
|
||||
config_files+=("$config")
|
||||
config_priority["$config"]=2
|
||||
echo " [P2] $config"
|
||||
fi
|
||||
done
|
||||
|
||||
# Plesk domain-specific
|
||||
if [ -f "/var/www/vhosts/system/$domain/etc/php.ini" ]; then
|
||||
config_files+=("/var/www/vhosts/system/$domain/etc/php.ini")
|
||||
config_priority["/var/www/vhosts/system/$domain/etc/php.ini"]=2
|
||||
echo " [P2] /var/www/vhosts/system/$domain/etc/php.ini"
|
||||
fi
|
||||
|
||||
# InterWorx domain-specific
|
||||
if [ -f "/home/$username/var/$domain/etc/php.ini" ]; then
|
||||
config_files+=("/home/$username/var/$domain/etc/php.ini")
|
||||
config_priority["/home/$username/var/$domain/etc/php.ini"]=2
|
||||
echo " [P2] /home/$username/var/$domain/etc/php.ini"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "PRIORITY 3: Pool/Version-Specific Configs"
|
||||
|
||||
# cPanel EA-PHP
|
||||
local cpanel_php_ini="/opt/cpanel/ea-php${php_version}/root/etc/php.ini"
|
||||
if [ -f "$cpanel_php_ini" ]; then
|
||||
config_files+=("$cpanel_php_ini")
|
||||
config_priority["$cpanel_php_ini"]=3
|
||||
echo " [P3] $cpanel_php_ini"
|
||||
|
||||
# Additional .ini files
|
||||
if [ -d "/opt/cpanel/ea-php${php_version}/root/etc/php.d" ]; then
|
||||
while IFS= read -r file; do
|
||||
config_files+=("$file")
|
||||
config_priority["$file"]=3
|
||||
echo " [P3] $file"
|
||||
done < <(find "/opt/cpanel/ea-php${php_version}/root/etc/php.d" -name "*.ini" | sort)
|
||||
fi
|
||||
fi
|
||||
|
||||
# CloudLinux Alt-PHP
|
||||
local alt_php_ini="/opt/alt/php${php_version}/etc/php.ini"
|
||||
if [ -f "$alt_php_ini" ]; then
|
||||
config_files+=("$alt_php_ini")
|
||||
config_priority["$alt_php_ini"]=3
|
||||
echo " [P3] $alt_php_ini"
|
||||
fi
|
||||
|
||||
# Plesk
|
||||
local plesk_php_ini="/opt/plesk/php/${php_version:0:1}.${php_version:1}/etc/php.ini"
|
||||
if [ -f "$plesk_php_ini" ]; then
|
||||
config_files+=("$plesk_php_ini")
|
||||
config_priority["$plesk_php_ini"]=3
|
||||
echo " [P3] $plesk_php_ini"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "PRIORITY 4: System-Wide Default"
|
||||
if [ -f "/etc/php.ini" ]; then
|
||||
config_files+=("/etc/php.ini")
|
||||
config_priority["/etc/php.ini"]=4
|
||||
echo " [P4] /etc/php.ini"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "=== Total config files found: ${#config_files[@]} ==="
|
||||
|
||||
# Return the array
|
||||
printf '%s\n' "${config_files[@]}"
|
||||
}
|
||||
```
|
||||
|
||||
## How to Determine Effective Setting
|
||||
|
||||
### Method 1: Query PHP Directly (MOST ACCURATE!)
|
||||
|
||||
```bash
|
||||
# Get effective value for a specific setting
|
||||
get_effective_php_setting() {
|
||||
local username="$1"
|
||||
local setting="$2" # e.g., "memory_limit"
|
||||
|
||||
# Run as user to get their effective settings
|
||||
su -s /bin/bash "$username" -c "php -r 'echo ini_get(\"$setting\");'"
|
||||
}
|
||||
|
||||
# Example usage
|
||||
memory_limit=$(get_effective_php_setting "examplec" "memory_limit")
|
||||
echo "Effective memory_limit: $memory_limit"
|
||||
|
||||
# Get ALL effective settings
|
||||
su -s /bin/bash "$username" -c "php -r 'print_r(ini_get_all());'" > /tmp/effective_php_settings.txt
|
||||
```
|
||||
|
||||
### Method 2: Parse Config Hierarchy
|
||||
|
||||
```bash
|
||||
# Parse configs in priority order and track overrides
|
||||
get_setting_from_configs() {
|
||||
local setting="$1"
|
||||
local value=""
|
||||
|
||||
# Parse in REVERSE priority (lowest to highest)
|
||||
# So higher priority files override
|
||||
|
||||
# Priority 4: System
|
||||
value=$(grep "^$setting" /etc/php.ini | cut -d'=' -f2 | tr -d ' ')
|
||||
|
||||
# Priority 3: Pool
|
||||
pool_value=$(grep "^$setting" /opt/cpanel/ea-php82/root/etc/php.ini | cut -d'=' -f2 | tr -d ' ')
|
||||
[ -n "$pool_value" ] && value="$pool_value"
|
||||
|
||||
# Priority 2: User
|
||||
user_value=$(grep "^$setting" /home/$username/.php/8.2/php.ini | cut -d'=' -f2 | tr -d ' ')
|
||||
[ -n "$user_value" ] && value="$user_value"
|
||||
|
||||
# Priority 1: .user.ini
|
||||
user_ini_value=$(grep "^$setting" /home/$username/public_html/.user.ini | cut -d'=' -f2 | tr -d ' ')
|
||||
[ -n "$user_ini_value" ] && value="$user_ini_value"
|
||||
|
||||
echo "$value"
|
||||
}
|
||||
```
|
||||
|
||||
## Quick Reference Commands
|
||||
|
||||
```bash
|
||||
# Find ALL php.ini files on system
|
||||
find / -name "php.ini" -type f 2>/dev/null
|
||||
|
||||
# Find ALL .user.ini files
|
||||
find /home -name ".user.ini" -type f 2>/dev/null
|
||||
|
||||
# Find .htaccess with PHP directives
|
||||
find /home -name ".htaccess" -exec grep -l "php_value\|php_flag" {} \; 2>/dev/null
|
||||
|
||||
# Get effective settings for a domain (via web)
|
||||
curl -s "http://domain.com/info.php" | grep -A1 "memory_limit"
|
||||
|
||||
# Get effective settings via CLI
|
||||
php -i | grep "memory_limit"
|
||||
php -r "echo ini_get('memory_limit');"
|
||||
|
||||
# List all loaded .ini files
|
||||
php --ini
|
||||
|
||||
# Get configuration file path
|
||||
php -r "echo php_ini_loaded_file();"
|
||||
|
||||
# Get scanned .ini directory
|
||||
php -r "echo php_ini_scanned_files();"
|
||||
```
|
||||
|
||||
## Key Takeaways for Optimizer
|
||||
|
||||
1. **Always check .user.ini first** - It overrides everything!
|
||||
2. **Per-domain/user configs vary by control panel** - Need detection logic
|
||||
3. **.htaccess php_value only works with mod_php** - Usually ignored on modern setups
|
||||
4. **Query PHP directly for accurate effective values** - Don't just parse files
|
||||
5. **Check loaded files via php --ini** - Shows what's actually being used
|
||||
6. **Multiple .ini files can affect same setting** - Last one wins (in priority order)
|
||||
|
||||
This complete map ensures the optimizer will find ALL configuration affecting a domain!
|
||||
Reference in New Issue
Block a user