When working with PHP on CentOS servers, knowing the exact installation path is crucial for configuring web servers, debugging, or installing extensions. Here are several reliable ways to locate this information:
The simplest method to find the PHP binary path:
which php
This typically returns something like /usr/bin/php
on most CentOS installations.
For more detailed installation information including all configured paths:
php -i | grep "Configuration File"
This will show the loaded php.ini file location, usually in paths like /etc/php.ini
or /etc/php/[version]/php.ini
If you have development tools installed:
php-config --prefix
This returns the base installation directory, typically /usr
or /usr/local
To see all loaded PHP modules and their paths:
php -m
For PHP-FPM installations common in web server setups:
systemctl status php-fpm
This shows the service file location which typically contains the executable path.
Based on different installation methods, PHP might be found in:
- Default repository install:
/usr/bin/php
- Remi repository:
/opt/remi/php[version]/root/usr/bin/php
- Manual compilation:
/usr/local/php/bin/php
Here's how you might use this information to update PHP's include path:
sudo nano /etc/php.ini
Then locate and modify the include_path directive:
include_path = ".:/usr/share/pear:/usr/share/php"
When working with PHP on CentOS servers, knowing the exact installation path is crucial for configuration, module management, and debugging. Here are several reliable methods to locate your PHP installation directory.
The simplest method to find the PHP binary location:
$ which php
/usr/bin/php
This command reveals the configuration file path and additional information:
$ php --ini
Configuration File (php.ini) Path: /etc
Loaded Configuration File: /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed: /etc/php.d/curl.ini, /etc/php.d/dom.ini, ...
This shows binary, source, and manual page locations:
$ whereis php
php: /usr/bin/php /usr/lib64/php /etc/php.d /usr/include/php
For extension development or module management:
$ php -i | grep extension_dir
extension_dir => /usr/lib64/php/modules => /usr/lib64/php/modules
If you have multiple PHP versions installed, use alternatives:
$ update-alternatives --list php
/usr/bin/php54
/usr/bin/php74
/usr/bin/php80
For comprehensive PHP installation information:
$ php -i | grep "Configure Command"
Configure Command => './configure' '--build=x86_64-redhat-linux-gnu' ...
For PHP-FPM installations:
$ which php-fpm
/usr/sbin/php-fpm