Setting up your linux for php development

Sebastian Muchui
3 min readAug 3, 2023

Linux is a great operating system to develop php applications on, however if you are coming from windows there could be a few differences in how you run your local server, folder arrangement etc.

In this post, I will discuss how to set up your developer environment for php on linux from the browser to your IDE.

  1. Download xampp for linux

The first step is to download xampp for linux. You can get it from apachefriends.org. You could also use other sources but for now let’s use the official source.

2. Permissions

Once the download is over, navigate to your ~/Downloads/ directory and open your terminal and type:

sudo chmod a+rwx xampp-linux-x64-8.2.4-0-installer.run

Please note that the name could change depending on the file you download, versions etc. Always double check.

3. Execute the .run file

Once you have given the permissions, the next step is to execute. Now this is pretty straightforward as well.

./xampp-linux-x64-8.2.4-0-installer.run

An installation wizard appears and the installation is normal.

But sometimes this may not work due to compatibility issues between 32-bit applications and 64-bit machines. To fix this you just install libxcrypt-compat on your computer. The package manager you use will really depend on your distro e.g dnf for fedora, pacman for arch etc.

4. Starting your local server

The server we have just installed ships with apache, mysql and proftpd. Usually, linux distributions have an inbuilt apache service as well. To run the server, you may need to disable the inbuilt apache first. But in most cases you will not need to do that.

After installation your xampp server and all its files can be found in /opt/lampp/

To run the local server all you need to do is

sudo /opt/lampp/lampp start

The converse is true if you want to stop it

sudo /opt/lampp/lampp stop

This will start all your servers ( apache, mysql and proftpd )

You can also use the GUI app to manage your servers. To do this, cd into /opt/lampp then

sudo ./manager-linux-x64.run

This should give you a graphical manager for your servers. You could also change ports depending on your preferences.

Note that the manager name could change, so always remember to check before running any command.

To test if the installation worked fine, open your browser and type localhost. A webpage with the xampp logo should show up.

5. Starting to develop

Remember how on windows you had to place all your php projects in C:\xampp\htdocs\ directory ?

The rules are the same for linux, only that we use the /opt/lampp/htdocs/ directory instead.

With this in mind, now let’s create our first project

sudo mkdir myapp

You need the sudo keyword because elevation is required in order to perform any modifications.

Similarly, to clone anything from github, you need the sudo keyword

sudo git clone -b branch_name https://github.com/user/repo.git

Make sure to authenticate your git before hand. More on this later.

Usually you may be using an IDE or text editor for your development. If you open such an application at this point in time, you will need to authenticate anytime you make a change to a file. This is not something you want.

To fix that:

sudo chmod a+rwx -R .

This will give sufficient permissions to all the folders in the htdocs folder. And now you can develop comfortably on your linux.

Just in case you need an interactive shell you can simply type

php -a

If php is a missing dependency, you can install it using your package manager. Example

sudo pacman -S php

Did you like this? Please leave a comment.

--

--