Categories: Blog

How to Switch PHP Versions in XAMPP Easily: Managing Multiple PHP Versions on Ubuntu

Share your learning

Today we are going to learn about managing multiple PHP versions on ubuntu with xampp.

XAMPP is a popular development environment that combines Apache, MySQL, PHP, and Perl, making it easy for developers to create and test web applications locally. However, as projects evolve, you may need to switch between different PHP versions to ensure compatibility and functionality. 

In this article, we will guide you through the process of managing multiple PHP versions in XAMPP on a Linux Ubuntu operating system.

XAMPP Installation

Download and install XAMPP on your Ubuntu machine if you haven’t already. You can find the installation instructions on the Apache Friends website.

Now try to run following command:

sudo xampp start

If it is not working, then probably you haven’t configured the xampp cli yet. 

Setup XAMPP CLI

Run the below command to enable XAMPP commands.

sudo ln -s /opt/lampp/xampp /usr/local/bin/xampp

Here /opt/lampp is the directory where the xampp server is installed. Now, it will add the XAMPP to the CLI. You can run below command to test it.

sudo xampp start
sudo xampp stop

Okay, the next step is to install multiple xampp with different PHP versions.

Install XAMPP with multiple PHP Versions

Now rename the existing /otp/lampp to /opt/lampp_php_version, for example if current xampp is for PHP 5.6 then name it lampp_5.6

Run the following linux command to do that:

sudo mv /opt/lampp /opt/lampp_5.6

Let’s suppose you have installed a new XAMPP with PHP 7.4 then rename it lampp_7.4 to install the next XAMPP version. This way you can install as much as you need. At the end at least one XAMPP should be without a rename meaning it should be simply /opt/lampp.

Common htdocs folder for all PHP versions

You can create www folder in the home directory. For example, /home/username/www

Then run remove the htdocs from /opt/lampp directory. Now run the below command:

sudo ln -s /home/satpal/www /opt/lampp/htdocs

It will create the symlink in the lampp directory, when we switch the multiple PHP version even then this directory and included projects will be the same.

First you have to open all lampp, lampp_5.6, lampp_7.4 etc. and perform the same action.

Install switch xampp command

Till now, you have set everything properly. It’s time to install a command to switch the php versions with xampp. Download the switch-xampp and place it to /usr/local/bin/

You can run the following command from your downloads folder to copy and paste the switch-xampp file to the destination:

sudo cp switch-xampp /usr/local/bin/

Test the setup

Run the below command to test the whole setup:

sudo switch-xampp 7.4
Satpal

Recent Posts

How to Use Coding to Improve Your Website’s SEO Ranking?

Let's understand about how to use coding to improve your website's SEO. In today’s computerized…

1 year ago

Most Important Linux Commands for Web Developers

Let's understand the most important linux commands for web developers. Linux, as an open-source and…

1 year ago

Top 75+ Laravel Interview Questions Asked by Top MNCs

Today we are going to discuss top 75+ Laravel interview questions asked by top MNCs.Laravel,…

1 year ago

Mailtrap Integration for Email Testing with Laravel 10

Today we will discuss about the Mailtrap integration with laravel 10 .Sending and receiving emails…

1 year ago

Firebase Cloud Messaging (FCM) with Ionic 6: Push Notifications

Today we are going to integrate FCM (Firebase Cloud Messaging) push notifications with ionic application.Firebase…

1 year ago

Resolving the ‘Uncaught TypeError’ in jQuery AJAX: Understanding and Fixing the ‘append’ Interface FormData Error

Uncaught TypeErrror: append called on an object that does not implement interface FormData. JQuery has…

1 year ago