Installing XAMPP on Ubuntu

Installing XAMPP on Ubuntu becomes familiar with many PHP developers. However, it’s new to me.

Sound funny, but I’ve just known that XAMPP can install on Ubuntu. My old way is installing nginx, php, mysql separately.

After installing XAMPP, there are some works you need to do before starting developments.

1. Some directories you must keep in mind

htdocs: /opt/lampp/htocs/
vhost config: /opt/lampp/etc/extra/

2. Directory permission

Change permission of htdocs directory to 777. Because this is just a development environment, so you don’t worry about the security.

sudo chmod -R 777 /opt/lampp/htdocs

3. Directory ownership

This thing makes my headache.

htdocs folder was created under the root account during the intallation of XAMPP, so you cannot edit files or folders in htdocs.

In order to change the owership of htdocs folder, you need the username and group name of the current user. You can easily get them with following commands:

$ whoami
thien #username
$ id -gn
thien #groupname

Once you know the both names, you can use the following command to change the both types of ownership:

sudo chown -R [username]:[groupname] /opt/lampp/htdocs

You can check the ownership with this command:

ls -ld /opt/lampp/htdocs
drwxrwxrwx 7 thien thien 4096 Thg 1 24 01:07 /opt/lampp/htdocs

4. Running apache(httpd) process under the current account.

Backup httpd.conf to ensure that we can rollback later.

sudo cp /opt/lampp/etc/httpd.conf /opt/lampp/etc/httpd.confg.bak

Edit the file.

sudo vim /opt/lampp/etc/httpd.conf

Locate following directives

User daemon
Group daemon

Change them with you username, groupname above.

Once file is saved, restart the XAMPP.

sudo /opt/lampp/lampp restart

5. Create virtual host

Allow vhost in lampp:

Find and uncomment this config in /opt/lampp/etc/httpd.conf

# Virtual hosts
Include etc/extra/httpd-vhosts.conf

Open httpd-vhost.conf and add the config like the given example in that file.

sudo vim /opt/lampp/etc/extra/httpd-vhost.conf

After all, restart the XAMPP.