Current Location: Home> Latest Articles> Complete Guide to Installing and Configuring PHP 5.2 on CentOS

Complete Guide to Installing and Configuring PHP 5.2 on CentOS

gitbox 2025-08-04

Preparing the Environment

Before installing PHP 5.2, make sure your CentOS system is fully updated. Updating the system helps ensure a smooth installation process and avoids potential dependency conflicts. Use the following command to update your system:

sudo yum update

Installing Required Dependencies

PHP 5.2 requires some essential dependencies. Install them by running:

sudo yum install httpd gcc make libtool

Downloading PHP 5.2 Source Code

Download the PHP 5.2 source package using wget:

wget http://museum.php.net/php5/php-5.2.17.tar.gz

Extracting the Source Files

Once downloaded, extract the source package:

tar -zxvf php-5.2.17.tar.gz

Configuring PHP 5.2 Installation Options

Enter the extracted directory and configure the installation options, ensuring support for common modules:

cd php-5.2.17
./configure --with-apxs2=/usr/bin/apxs --with-mysql --enable-mbstring --with-zlib --with-curl --with-gd

Compiling and Installing PHP

After configuration, compile and install PHP:

make
sudo make install

Configuring Apache to Use PHP 5.2

To enable Apache to recognize PHP files, add the following to Apache’s configuration file:

echo "LoadModule php5_module modules/libphp5.so" | sudo tee -a /etc/httpd/conf/httpd.conf
echo "AddType application/x-httpd-php .php" | sudo tee -a /etc/httpd/conf/httpd.conf

Restarting the Apache Service

Restart Apache to apply the changes:

sudo systemctl restart httpd

Verifying the PHP Installation

Create a test PHP file to verify the installation:

echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php

Then, open your browser and visit http://your-server-ip/info.php to see the PHP configuration page.

Summary

This guide outlined the complete process for installing and configuring PHP 5.2 on CentOS. Although this version is outdated, it is still required for some legacy systems. It is recommended to pay attention to security and consider upgrading to newer versions to ensure better performance and safety.