Current Location: Home> Latest Articles> CentOS PHP Installation Directory and Configuration Guide

CentOS PHP Installation Directory and Configuration Guide

gitbox 2025-07-15

CentOS PHP Installation Directory and Configuration Guide

On CentOS, understanding the PHP installation directory is fundamental to ensuring the efficient operation of the PHP environment. In this article, you will learn about the default PHP installation directory, configuration file paths, and how to customize installation paths and manage PHP extension modules.

Default PHP Installation Directory

On CentOS, the default installation directory for PHP is typically /usr/bin/php. This directory contains the core executable files for PHP, and users can invoke PHP directly from the terminal. To check if PHP has been correctly installed, use the following command:

<span class="fun">php -v</span>

If PHP is installed correctly, the system will display the PHP version information.

PHP Configuration File Path

The PHP configuration file is usually located at /etc/php.ini. This file contains key configuration options for PHP, such as error reporting, memory limits, and more. To modify PHP's behavior, you can edit this file. Use the following command to edit the configuration file:

<span class="fun">sudo vi /etc/php.ini</span>

After making changes, be sure to restart the relevant services to apply the modifications. For instance, if you are using the Apache server, restart it with the following command:

<span class="fun">sudo systemctl restart httpd</span>

PHP Extension Module Installation Directory

On CentOS, PHP extension modules are typically installed in the /usr/lib64/php/modules/ directory. You can check the installed extension modules in this directory and configure them in the php.ini file.

Custom PHP Installation Directory

In some cases, you might need to customize the PHP installation directory. This can be done by installing PHP from source and specifying the target directory. For example, use the following command to install PHP in a custom directory:

<span class="fun">./configure --prefix=/opt/php</span>

This command will install PHP in the /opt/php directory. You can customize the installation path based on your needs and make sure to correctly reference the new path in the configuration files.

Conclusion

Understanding PHP's installation directory and configuration file locations on CentOS is crucial for effective management and optimization of the PHP environment. By default, the PHP executable is located at /usr/bin/php, and the configuration file is at /etc/php.ini. If you need to customize the installation directory or install PHP extension modules, you can adjust these settings as needed. We hope this article helps you better configure and manage PHP on CentOS.