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.
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
/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
/opt/lampp_php_version, for example if current xampp is for PHP 5.6 then name it
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
Common htdocs folder for all PHP versions
You can create
www folder in the home directory. For example,
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_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
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