Before you start compiling PHP 5.6, make sure to install the necessary dependencies on your system. These dependencies are crucial for a smooth compilation process. You can install the required packages using the following command:
<span class="fun">sudo yum install -y gcc make autoconf libtool bzip2-devel libxml2-devel curl-devel libpng-devel libjpeg-devel libXpm-devel freetype-devel</span>
Next, download the PHP 5.6 source code. You can directly download it using the command below:
<span class="fun">wget https://www.php.net/distributions/php-5.6.40.tar.gz</span>
After the download is complete, extract the source code:
<span class="fun">tar -zxvf php-5.6.40.tar.gz</span>
Enter the extracted directory and begin compiling PHP 5.6. You can adjust the configuration options based on your needs:
<span class="fun">cd php-5.6.40</span>
<span class="fun">./configure --prefix=/usr/local/php56 --with-config-file-path=/usr/local/php56 --enable-mbstring --with-curl --with-openssl --with-mysqli --with-zlib --enable-soap</span>
After running the configuration command, begin the compilation:
<span class="fun">make</span>
<span class="fun">sudo make install</span>
Once installation is complete, you need to configure PHP. In the default installation directory, you will find a sample php.ini file. Use the following command to copy it and create your configuration file:
<span class="fun">cp php.ini-development /usr/local/php56/php.ini</span>
Edit the php.ini file as needed to ensure the correct paths and extensions are configured.
Finally, you can check if PHP 5.6 has been installed correctly by running the following command:
<span class="fun">/usr/local/php56/bin/php -v</span>
If you see the PHP 5.6.x version information, congratulations! You have successfully compiled and installed PHP 5.6 on CentOS.
By following the steps above, you can easily compile and install PHP 5.6 on CentOS. Make sure to install all dependencies correctly and configure PHP options during the process. This will help ensure better performance. If you encounter any issues, you can refer to the official PHP documentation or seek help from the community.