How to create a local domain for XAMPP in Centos 7/RHEL 7

Instead of using the local domain localhost for your local development environment, you may create a custom domain name, named anything else and use it instead.

In this example, we will create local domain and create a vhost that will point it to a specific working directory. I’ll assume you already have XAMPP for Linux installed.

1. Open /etc/hosts file using your favorite editor

[wm@serv0-wal ~] sudo vim /etc/hosts

2. Add the custom domain you would like to the end of the lines as shown in the image below. In my case, I have created two domains, rawle.local and mwab.ini

When you access the domain, it will give you the same page that accessing localhost does. We can point the domain to a specific document root by creating a vhost for it.

3. In XAMPP for Linux, access /opt/lampp/etc/extra. This is the location of configuration files for Apache web server that comes with XAMPP

[wm@serv0-wal ~]$ cd /opt/lampp/etc/extra/

4. Create a config file for your vhost

[wm@serv0-wal extra]$ touch rawle.local.conf

5. Copy the code below in the config file

<VirtualHost *:80>

ServerAdmin [email protected]

DocumentRoot “/opt/lampp/htdocs/gportal-2.0”

ServerName rawle.local

ServerAlias www.rawle.local

ErrorLog “logs/rawle.local.error_log”

CustomLog “logs/rawle.local.access_log” common

</VirtualHost>

Replace rawle.local with your custom domain.

6. Start/Restart XAMPP

[wm@serv0-wal extra]$ sudo /opt/lampp/lampp restart

Restarting XAMPP for Linux 7.3.0-0…

XAMPP: Stopping Apache…not running.

XAMPP: Stopping MySQL…not running.

XAMPP: Stopping ProFTPD…not running.

XAMPP: Starting Apache…ok.

XAMPP: Starting MySQL…ok.

XAMPP: Starting ProFTPD…ok.

[wm@serv0-wal extra]$

7. Access your local website using your new local domain.

We’ll then ,in our next article, see how to secure the local environment with an SSL certificate. Not just a self signed one that will give warnings, but one that will show https with a green padlock, just as through it came from a real Certificate Authority.

Leave a Reply

Your email address will not be published. Required fields are marked *