Installing an Older PHP Version on Ubuntu 16.04 using XAMPP
If you’re trying to install Magento or any other software that requires a specific PHP version, you might encounter compatibility issues with your current system. In this guide, we’ll walk through the process of downgrading your PHP version specifically for XAMPP running on Ubuntu 16.04.
Understanding the Issue
Magento (and many other applications) have specific PHP requirements to ensure optimal performance and security. If you’re seeing an error like the one below, it means your current PHP version is not supported by the application:
PHP Version Check Your PHP version is 7.1.1. The required PHP version is ~5.6.5|7.0.2|7.0.4|~7.0.6.
In this case, you’ll need to downgrade your PHP version to meet the application’s requirements without affecting the rest of your system.
Downgrading PHP for XAMPP on Ubuntu
Step 1: Backup Your Current Installation
Before making any changes, it’s crucial to backup your current XAMPP installation. This ensures you can revert if anything goes wrong during the process:
cp -r /opt/lampp /opt/lampp_backup
Step 2: Remove the Existing PHP Directory
Next, remove the existing PHP directory from the XAMPP installation:
sudo rm -rf /opt/lampp/php
Step 3: Download and Extract the Required PHP Version
Download the desired version of PHP (e.g., PHP 7.0) for your architecture (32-bit or 64-bit). For this guide, let’s assume you’re using a 64-bit system:
wget https://www.php.net/distributions/php-7.0.9.tar.bz2
Extract the downloaded file:
tar -xvf php-7.0.9.tar.bz2
cd php-7.0.9/
Step 4: Configure and Compile PHP
Configure PHP to use the Apache module with the following command:
./configure --enable-fpm --with-config-file-scan-dir=/opt/lampp/php/conf.d
Then, compile it:
make -j$(nproc)
Step 5: Copy the PHP Files
Copy the compiled PHP files to your XAMPP installation directory:
sudo cp -r php /opt/lampp/
Step 6: Update the Apache Configuration
Update the extra/httpd-xampp.conf file in the /opt/lampp/etc/ directory to point to your new PHP version:
sudo nano /opt/lampp/etc/extra/httpd-xampp.conf
Change the following lines:
LoadModule php7_module "php/lib/php7.so"
AddType application/x-httpd-php .php .phtml
PHPIniDir "php"
DocumentRoot "/opt/lampp/htdocs/"
<Directory "/opt/lampp/htdocs/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Save and close the file.
Step 7: Restart XAMPP
Finally, restart XAMPP to apply the changes:
sudo /opt/lampp/xampp startapache
Verifying the Installation
To confirm that the downgrade was successful, open a web browser and navigate to http://localhost. You should see the XAMPP dashboard. Click on “PHPInfo” in the left menu, and check the version listed at the top:
PHP Version 7.0.9
Conclusion
Downgrading PHP for a specific application can be a complex process, but it’s possible with careful attention to detail. By following this guide, you should now have an older PHP version running specifically within your XAMPP installation while keeping the rest of your system unaffected.
Remember, this approach is a temporary solution for development and testing purposes only. For production environments or long-term projects, consider using a proper virtualization setup or containerization (e.g., Docker) to isolate different PHP versions for various applications.
For more insights into Laravel application development on XAMPP, visit LaravelCompany.