Many developers and system administrators need to install PHP 5.4 on Linux systems. This guide provides comprehensive steps to help you quickly set up a PHP environment that meets your requirements.
Before starting, make sure your system package information is up to date. Open the terminal and run:
<span class="fun">sudo apt-get update</span>
PHP 5.4 depends on several libraries and extensions. Use the following command to install the necessary components:
<span class="fun">sudo apt-get install build-essential libxml2-dev libcurl4-openssl-dev pkg-config</span>
Download the PHP 5.4 source package from the official PHP archive:
<span class="fun">wget http://museum.php.net/php5/php-5.4.48.tar.gz</span>
After downloading, extract the files:
<span class="fun">tar -xzvf php-5.4.48.tar.gz</span>
Enter the extracted directory and run the configuration command:
cd php-5.4.48
./configure --with-config-file-path=/usr/local/lib --enable-mbstring --with-curl
Next, compile the source code:
<span class="fun">make</span>
After compilation, execute the installation:
<span class="fun">sudo make install</span>
Once installed, copy the development configuration file as the base:
<span class="fun">sudo cp php.ini-development /usr/local/lib/php.ini</span>
Edit the configuration file with a text editor to adjust settings such as timezone and error reporting as needed:
<span class="fun">sudo nano /usr/local/lib/php.ini</span>
Confirm the PHP 5.4 version by running:
<span class="fun">php -v</span>
If the version shows 5.4.x, the installation was successful.
This guide covers the entire process from environment preparation to final verification. Mastering these steps will help you successfully set up PHP 5.4 on Linux, providing a stable foundation for your development work.