When multiple PHP installations exist on a system (like /usr/local/bin/php
and /usr/local/bin/php5
), determine the active version with these methods:
# Basic version check
php -v
# Locate the PHP binary path
which php
# or
command -v php
# For detailed configuration path
php -i | grep 'Configuration File'
Create a test file (info.php) with this content:
<?php
phpinfo();
?>
Access it via browser to see:
- Loaded configuration file path
- PHP binary location
- All active extensions
Run this script to output execution details:
<?php
echo "PHP Binary: " . PHP_BINARY . "\n";
echo "Include Path: " . get_include_path() . "\n";
echo "Loaded Config: " . php_ini_loaded_file() . "\n";
?>
When using alternatives system (common in Linux):
# List all available PHP versions
update-alternatives --list php
# Manually switch versions
sudo update-alternatives --config php
For web applications, verify which PHP processor is active:
# For Apache
apachectl -M | grep php
# For Nginx + PHP-FPM
ps aux | grep php-fpm
When multiple PHP installations exist on a system (e.g., /usr/local/bin/php
and /usr/local/bin/php5
), determining the actual PHP interpreter being used requires several diagnostic approaches. This is particularly important for:
- Debugging version-specific behaviors
- Ensuring compatibility with frameworks
- Validating CLI vs web server environments
The most comprehensive way to check your active PHP configuration:
<?php
// Create a test file named phpinfo.php
phpinfo();
?>
Access this via web browser and check:
- "Loaded Configuration File" path
- "Configuration File (php.ini) Path"
- Top-line version information
For CLI scripts, use these terminal commands:
# Check default PHP path
which php
# Verify executable path
readlink -f $(which php)
# Get version details
php -v
php -i | grep "Loaded Configuration File"
Create a diagnostic script:
<?php
echo "Executable path: " . PHP_BINARY . "\n";
echo "Include path: " . get_include_path() . "\n";
echo "php.ini location: " . php_ini_loaded_file() . "\n";
For Apache/Nginx environments:
# Apache
grep -i "php" /etc/apache2/sites-enabled/*.conf
# Nginx
grep -i "fastcgi_pass" /etc/nginx/sites-enabled/*
Common handler patterns:
- mod_php:
LoadModule php_module
- PHP-FPM:
fastcgi_pass unix:/run/php/phpX.X-fpm.sock
- CGI:
Action application/x-httpd-php
When using version managers:
# For phpbrew
phpbrew list
# For update-alternatives
update-alternatives --list php