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
PHP 5.2 requires some essential dependencies. Install them by running:
sudo yum install httpd gcc make libtool
Download the PHP 5.2 source package using wget:
wget http://museum.php.net/php5/php-5.2.17.tar.gz
Once downloaded, extract the source package:
tar -zxvf php-5.2.17.tar.gz
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
After configuration, compile and install PHP:
make sudo make install
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
Restart Apache to apply the changes:
sudo systemctl restart httpd
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.
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.