First impressions of using XAMPP on Linux for PHP development
Tags: php, xampp, linux, development
Published: 2023-12-16 17:13:42

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7srx2go6jg884yem86u5.png)<figcaption>Screenshot of terminal running neofetch2</figcaption>

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.
```sh
paru -S xampp
# or yay -S xampp
```
But I decided to install it using the "Official" method.

Step 1-
Visit [https://www.apachefriends.org/download.html](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 :
```sh
chmod 755 xampp-linux-*-installer.run
```

Step 3-
Launch the installer by using :
```sh
sudo ./xampp-linux-*-installer.run
```

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

![Screenshot of XAMPP Installer on Linux](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y1dvpw7l8l561cnr1tc5.png)<figcaption>Screenshot of XAMPP Installer on Linux</figcaption>

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rsbjfotqxbbv1zp5unli.png)<figcaption>Screenshot of XAMPP Control Panel</figcaption>

![Screenshot of XAMPP Control Panel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mk1k3m7t75qsfad1vk82.png)<figcaption>Screenshot of XAMPP Control Panel</figcaption>

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:
```sh
sudo pacman -S libxcrypt-compat
# or paru -S libxcrypt-compat
# or yay -S libxcrypt-compat
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dbcnmnvwks784zpce25k.png)<figcaption>Screenshot of 'lampp' executable in CLI</figcaption>

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.
```sh
sudo /opt/lampp/manager-linux-x64.run
```

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.

```sh
sudo chown -R $USER:$USER /opt/lampp/htdocs
```

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.

```php
// contents of /opt/lampp/htdocs/project1/index.php
<?php
phpinfo();
?>
```

Now we can enable virtual hosts file support in apache by editing `httpd.conf`
```sh
sudo nano /opt/lampp/etc/httpd.conf
```
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:
```conf
<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>
```

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
```

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](https://spexoid.com)