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:
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:
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:
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:
Next, it will tell you that the XAMPP will be installed in to /opt/lampp directory:
And in the next step, the setup wizard will notify you that the setup is ready and now you can start the installation process:
Once done, you can launch the XAMPP:
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
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:
Save the changes, and you can open XAMPP from your system menu:
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
:
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:
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:
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
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!"
?>
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
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:
Click on the Yes button, and it will start the uninstallation process:
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.