How to Install and Use XAMPP on Ubuntu

Learn to install and use XAMPP on Ubuntu for deploying websites and web applications on localhost for development and testing.
Warp Terminal

The purpose of XAMPP is to enable you to test your projects by setting up a local server, giving you a better understanding of how they will function when made available online.

And if you are curious about what XAMPP has to offer, have a look at its abbreviation:

  • X: Cross-platform, means you can use it on almost every operating system.
  • A: Apache server.
  • M: MariaDB for database operations.
  • P: PHP that you may want to use for dynamic websites.
  • P: Perl programming language.

This makes the XAMPP a complete package, which is why people want to have it since it saves you a tonne of time, so you can later peacefully copy codes from StackOverflow (just kidding).

In this tutorial, I'll teach you the following:

  • Installing XAMPP on Ubuntu
  • Using it to host websites locally
  • Removing it from the system

Sounds good? Let's go with the installation part.

Install XAMPP in Ubuntu

XAMPP is available in various versions which consist of different versions of Apache, MariaDB, and others so you can go with what your workflow demands.

Step 1. Download the XAMPP binary File

To download XAMPP binary file, visit their official download page and select the preferred version:

download binary file for xampp in ubuntu

Step 2. Execute binaries

Open your file manager and open the Downloads directory as per default settings, the binary files must be located under the Downloads directory.

Now, select the XAMPP binary and press Ctrl + i and click on the Permission tab. From there, enable the option to execute the file as a program:

allow binaries to execute in linux

Sure, you can do the same using the chmod command:

chmod 755 xampp-linux-*-installer.run

And now, you can use the given command to run the installer:

sudo ./xampp-linux-*-installer.run

Once executed, you will be met with the welcome screen:

1. welcome to xampp setup wizard

Click the forward button to get started with the setup.

Step 3. Working with XAMPP setup wizard

The next page is to select components; by default, both options will be checked. Let them as it is and click on the forward button:

2. select components

Next, it will tell you that the XAMPP will be installed in to /opt/lampp directory:

3. xampp will be installed at lampp

And in the next step, the setup wizard will notify you that the setup is ready and now you can start the installation process:

4. ready to install
5. unpacking and installing files

Once done, you can launch the XAMPP:

7. xampp in ubuntu

Similarly, you can also use the following command to open XAMPP:

sudo /opt/lampp/./manager-linux-x64.run

Step 4. Create XAMPP desktop shortcut

First, change your working directory to /usr/share/applications using the given command:

cd /usr/share/applications

Here, you will have to create a desktop file with .desktop extension. Here, I’m going with xampp.desktop:

sudo nano xampp.desktop

And paste the following lines in xampp.desktop file:

[Desktop Entry]
Version=1.0
Type=Application
Name=XAMPP Control Panel
Exec=sudo /opt/lampp/manager-linux-x64.run
Icon=/opt/lampp/htdocs/favicon.ico
Terminal=false
StartupNotify=false
create xampp desktop

But XAMPP requires superuser privileges and I have used Terminal=false line so how you are supposed to enter the password?

Well, you don’t have to. I will show you a workaround so that it won’t ask for a password. First, open the sudoers file using the given command:

sudo visudo

And if you are using nano, press Alt + / to jump to the end of the text file. And add the following line, so you can skip entering the password:

username ALL = NOPASSWD: /opt/lampp/manager-linux-x64.run

Make sure to add your actual username instead of pasting the username. For reference, my username is sagar so my line would look like this:

open xampp without entering password in ubuntu

Save the changes, and you can open XAMPP from your system menu:

access xampp control panel from system menu in ubuntu

Step 5. Start MySQL and Apache server

Open the XAMPP control center from your system menu and click on the second tab named Manage Servers:

manage servers in xampp

From here, you can start each one of them individually, or you can use Start All button, and it will start all three services at once:

start apache and mysql database in xampp

Once started, you can open any of the preferred browsers and type localhost in the search bar and if everything is done correctly, it will greet you with a welcome message:

open myphp admin with xampp

And if you are wondering about the dark mode I got in the locally hosted site, I’m using a plugin named Dark Reader. To learn more, check out the list of interesting Firefox Add-ons to improve your browsing experience.

Host websites locally using XAMPP

Start the Apache web server from the XAMPP control panel and use the given command to change the current working directory to /opt/lampp/htdocs/:

cd /opt/lampp/htdocs/

Now, create a directory with any name your heart desires. I’m going with Mysite:

sudo mkdir Mysite

Next, I will change the ownership of the directory (mine is named as Mysite)from the root to the user, so the directory can easily be accessed without superuser privileges:

sudo chown -R $USER:$USER Mysite/

Now, change your current directory to the recently created one:

cd Mysite

And create an index PHP file:

touch index.php

From here, you can use any of your preferred text editors, but for the sake of this guide, I’m going with VSCode. If you don’t have one, we have a detailed guide on how you can install VSCode in Ubuntu:

code index.php
create and host website locally using xampp in ubuntu

From here, it’s all up to your creative skills. But for the sake of this guide, I’m only going to make my site print hello world (don’t judge me):

<?php
    echo "Hello folks, I hope XAMPP is working fine!"
 ?>
create php website and host locally using xampp

Save the changes using Ctrl + S and now you can access your site from your browser:

http://localhost/site-name

For me, It was Mysite so I’m required to use the following:

http://localhost/Mysite
host website locally using xampp in ubuntu

And here you have it. A site hosted on your local network!

Uninstall XAMPP from Ubuntu

The good news is XAMPP already has the uninstallation script, which saves you the trouble of removing every package manually.

Open your terminal and use the given command to invoke the uninstallation script:

sudo /opt/lampp/./uninstall

And it will ask you whether you want to remove XAMPP and all of its modules or not:

do you want to uninstall xampp and all of its modules

Click on the Yes button, and it will start the uninstallation process:

uninstalling xampp

Similarly, you have to use the given commands to remove desktop shortcuts:

sudo rm /usr/share/applications/xampp.desktop

And that’s it. You have removed XAMPP from your system successfully!

Wrapping Up

In this tutorial, I installed XAMPP and hosted a PHP website using a local webserver.

While I have tried my best to keep this guide to the beginner’s level, if you have any queries or any issues with installation, setup, or removal, feel free to ask me in the comments.

About the author
Sagar Sharma

Sagar Sharma

A software engineer who loves to write about his experience with Linux. While reviving my crashed system, you can find me reading literature, manga, or watering my plants.

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.