DEV Community

Cover image for First impressions of using XAMPP on Linux for PHP development
Tushar Tyagi
Tushar Tyagi

Posted on

First impressions of using XAMPP on Linux for PHP development

I started web development 10 years ago. I was around 16 years old when I started learning PHP.

Just like most php developers at that time I was using plain old Windows 7 and XAMPP for local development and FileZilla for uploading my work to a remote web server running cPanel.

Since then many things have changed, both in web development industry and also my personal preferences regarding my work environment.

About my work

In 10 years I have switched to node.js and regularly work on developing, reviewing and maintaining Node.js based projects.

I personally use Node.js with Express, MySQL, MongoDB for creating APIs and on frontend I mostly use SvelteKit and TailwindCSS.

For PHP, I have a custom docker environment I use for all my PHP projects.

My current setup

Currently I'm using Arch Linux with GNOME Desktop environment on a failry old development machine : Dell Latitude 3400. It's not new but it gets the job done without any bottlenecks with 8GB of RAM, Intel core i5 8th Gen processor and a 1920x1080 panel which I recently upgraded.

Screenshot of terminal running neofetch
Screenshot of terminal running neofetch2

I'm aware that this setup will not work for most you guys as the specs are quite low. But, remember that web development on my tech stack doesn't require very high specs anyway.

And Linux based OS generally provide a significant performance boost compared to windows.

Why PHP?

Most of you are probably asking that question and let me tell you that PHP still a has a massive share for low to medium size websites.

As much as I love node, sometimes I have to work on PHP projects that can not be handled by my juniors. Untill now I was happy to work on PHP in my docker environment but recently, It came to my attention that XAMPP is available for linux as well.

I just had a SSD change recently and I'm currently in the process of setting up the machine for development. Docker is still not installed and I decided to install XAMPP instead and see how it goes.

For old time's sake, I had to try it.

Using XAMPP

XAMPP is available in AUR (Arch User Repository) as xampp and installing it would be quite simple by using a package manager that supports AUR.

paru -S xampp
# or yay -S xampp
Enter fullscreen mode Exit fullscreen mode

But I decided to install it using the "Official" method.

Step 1-
Visit https://www.apachefriends.org/download.html and download the .run file for linux.

Step 2-
Open console and navigate to the location where the file was downloaded and make the file executable by using :

chmod 755 xampp-linux-*-installer.run
Enter fullscreen mode Exit fullscreen mode

Step 3-
Launch the installer by using :

sudo ./xampp-linux-*-installer.run
Enter fullscreen mode Exit fullscreen mode

It opens the installer that will install xampp in /opt/lampp directory.

Screenshot of XAMPP Installer on Linux
Screenshot of XAMPP Installer on Linux

Now the installation process is as straightforward as clicking next a few times.

After installation is finished, the XAMPP control panel starts automatically and the UI difference is immediatly noticeable.

Screenshot of XAMPP Control Panel
Screenshot of XAMPP Control Panel

Screenshot of XAMPP Control Panel
Screenshot of XAMPP Control Panel

Looks outdated but I'll manage. On 'Manage Servers' tab, I tried to start apache and mysql but it did not start. On viewing application logs, I found an error complaining about libcrypt.so.1. A quick google search provided a solution and I installed this package:

sudo pacman -S libxcrypt-compat
# or paru -S libxcrypt-compat
# or yay -S libxcrypt-compat
Enter fullscreen mode Exit fullscreen mode

I closed the XAMPP control panel and tried to find it in applications menu. Apparently XAMPP installer does not create .desktop files needed so it does not show in applications menu.

I dug into the /opt/lampp directory and found two executable files named lampp and manager-linux-x64.run. The first file was a command line interface to xampp

Screenshot of 'lampp' executable in CLI
Screenshot of 'lampp' executable in CLI

Running it gives the above output and it provided the command to open graphical panel. But he command sudo /opt/lampp/lampp panel does nothing (maybe a bug) So i decided to try the second executable file.

sudo /opt/lampp/manager-linux-x64.run
Enter fullscreen mode Exit fullscreen mode

It opens the panel and now I can successfully start apache and mysql services. Everything works as expected and now I can create my PHP projects in /opt/lampp/htdocs directory.

Since /opt/lampp/htdocs is owned by root user, I need to chown this directory to my normal user by using chown command.

sudo chown -R $USER:$USER /opt/lampp/htdocs
Enter fullscreen mode Exit fullscreen mode

One thing I do on Linux is enable virtual hosts for the projects. Ex: http://localhost/project1 turns into http://project1.local and so on.

To do this we need to create the project folder with an index.php file to test.

// contents of /opt/lampp/htdocs/project1/index.php
<?php
phpinfo();
?>
Enter fullscreen mode Exit fullscreen mode

Now we can enable virtual hosts file support in apache by editing httpd.conf

sudo nano /opt/lampp/etc/httpd.conf
Enter fullscreen mode Exit fullscreen mode

and remove the # from the line Include etc/extra/httpd-vhosts.conf

Next step is to re enable http://localhost and add a new virtual host entry for http://project1.local by editing /opt/lampp/etc/extra/httpd-vhosts.conf

This is how the file looks like after adding appropriate entries:

<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs
ServerName localhost
ServerAlias www.localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot /opt/lampp/htdocs/project1
ServerName project1.local
ServerAlias www.project1.local
</VirtualHost>
Enter fullscreen mode Exit fullscreen mode

Last step is to add entry for project1 in the /etc/hosts file. The contents of this file will look like this :

127.0.0.1 project1.local
Enter fullscreen mode Exit fullscreen mode

Now after restarting apache I can access the project from http://project1.local which makes using absolute path on development same as on production.

Conclusion

As XAMPP has it's own cli binary, we don't even need to open xampp control panel. And the process of creating the virtual hosts can be automated with a simple bash script. One can even make a better control panel than XAMPP which supports creating projects, virtual hosts and managing server and configurations.

The installation was simple but the first run required some troubleshooting. Apart from that UI is quite outdated and cli option to open panel did not work.

As you can see using XAMPP on Linux has it's own issues but you can easily find workarounds. So far it's simpler than a docker environment and provide all features needed to develop a PHP project.

I'm gonna keep using it for more time and see how it goes.

Now this was a random article but I had fun writing it and sharing it with you guys. If you guys have any questions or suggestions please let me know in the comments below.

Tushar Tyagi
CTO @ Spexoid Tech

Top comments (0)