Current Location: Home> Latest Articles> Comprehensive Guide to Compiling and Installing PHP 7.2 from Source

Comprehensive Guide to Compiling and Installing PHP 7.2 from Source

gitbox 2025-07-28

Introduction

PHP is a widely used scripting language in web development, known for its simplicity and ease of use. Version 7.2 brings multiple performance improvements and new features. This article explains step-by-step how to install PHP 7.2 from source, helping developers build an efficient PHP environment.

Preparation

Before starting the compilation and installation, make sure your server has the necessary build tools and dependencies installed.

GCC and G++ Compilers

PHP 7.2 requires GCC and G++ compilers to build from source. You can check if they are installed with the following commands:

gcc --version

g++ --version

If not installed, use these commands to install them:

sudo apt-get update
sudo apt-get install build-essential

Installing Other Dependencies

Besides compilers, some essential libraries are required to ensure a successful build:

<span class="fun">sudo apt-get install libxml2-dev libssl-dev libsqlite3-dev libcurl4-openssl-dev libonig-dev libzip-dev</span>

Downloading PHP Source

The official PHP source package can be downloaded using wget. The following commands download the latest stable release of PHP 7.2:

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

tar -zxvf php-7.2.33.tar.gz

After extraction, enter the source directory:

<span class="fun">cd php-7.2.33</span>

Configuring Build Options

Before compiling, run the configuration script to set up desired modules and options:

<span class="fun">./configure</span>

For common modules, you can use options like:

<span class="fun">./configure --enable-opcache --enable-xml --with-curl --with-openssl</span>

Compiling and Installing

Once configured, compile and install with these commands:

make
sudo make install

The compilation process might take some time, so please be patient.

Verifying the Installation

After installation, verify PHP by checking its version:

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

You can also create a simple PHP test script to confirm the environment is working properly:

<span class="fun">echo "<?php phpinfo(); ?>" > test.php</span>

Access this script via a browser; if the PHP information page loads correctly, the installation was successful.

Conclusion

This article covers the full process of compiling and installing PHP 7.2 from source, including environment preparation, source retrieval, configuration, compilation, and verification. Mastering this method enables developers to set up a customized, high-performance PHP environment.