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.
Before starting the compilation and installation, make sure your server has the necessary build tools and dependencies installed.
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
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>
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>
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>
Once configured, compile and install with these commands:
make
sudo make install
The compilation process might take some time, so please be patient.
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.
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.