Current Location: Home> Latest Articles> Complete Guide to PHP Source Installation on CentOS System

Complete Guide to PHP Source Installation on CentOS System

gitbox 2025-06-16

In modern web development, **installing PHP from source on CentOS** is an essential technical step. By installing PHP from source, users can customize the installation to meet their needs, adding or removing features. This article provides a detailed guide to help you successfully install PHP on a CentOS system from source.

Preparation

Before starting the installation, ensure that your CentOS system is up-to-date. You can update the system using the following command:

sudo yum update

Additionally, installing the required dependencies is crucial. You can use the following command to install necessary development tools and libraries:

sudo yum groupinstall "Development Tools"
sudo yum install -y libxml2-devel bzip2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel gmp-devel mariadb-devel

Download PHP Source Code

Next, you need to download the PHP source code from the official website. At the time of writing, the latest stable version is PHP 8.0.8 (please verify the latest version you need). Use the following command to download the PHP source code:

wget https://www.php.net/distributions/php-8.0.8.tar.gz

After the download is complete, extract the file:

tar -zxvf php-8.0.8.tar.gz

Compile and Install PHP

Navigate to the extracted directory and configure the PHP compilation options using the following command:

cd php-8.0.8
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-mbstring --with-curl --with-openssl --enable-soap --with-mysqli --enable-intl

This configuration includes several options, which you can modify based on your needs. After configuring, run the following commands to compile and install PHP:

make
sudo make install

Configure PHP

Once the installation is complete, you need to configure the PHP ini file. You can copy a sample configuration file using the following command:

cp php.ini-development /usr/local/php/php.ini

Afterward, you can modify the configuration file as needed, particularly to set the timezone and enable the required extensions.

Verify PHP Installation

To verify that PHP has been successfully installed, you can run the following command to check the PHP version:

/usr/local/php/bin/php -v

If the installed PHP version is displayed, it means your **PHP source installation on CentOS** has been successful!

Conclusion

By following the above steps, you have successfully installed PHP from source on your CentOS system. This method offers you greater flexibility and control, allowing you to configure PHP according to your project's requirements. We hope this guide helps you start your development journey!