25 February 2018 | 1 min read

Creating Apache / httpd virtual host config for specific domain

This should be a simple thing but sometime I forgot how to created a vhost for domain instead just using IP address during local development. This tutorial is for Fedora user, but I think it also can be applied on RHEL and Centos. Assume that I have a folder called wordpress.oo which located inside /var/www/html , Now I want to surf my website using http://wordpress.oo host address.

First of all, we need to pust IP address to our hosts file so the domain will binded with the IP.

$ sudo -E vim /etc/hosts

Let’s put a new entry inside /etc/hosts with wordpress.oo and save it.

Next, create the domain conf file. It should be located inside /etc/httpd/conf.d/

$ sudo touch /etc/httpd/conf.d/wordpress.oo.conf
$ sudo -E vim /etc/httpd/conf.d/wordpress.oo.conf

I created wordpress.oo.conf file, inside the file, write some configuration like this:

<VirtualHost wordpress.oo:80>
	ServerAdmin your@email.com
	DocumentRoot /var/www/html/wordpress.oo
	ServerName wordpress.oo
	ErrorLog /etc/httpd/logs/wordpress.oo-error_log
	CustomLog /etc/httpd/logs/wordpress.oo-access_log common

Then restart the httpd

$ sudo systemctl restart httpd
$ sudo systemctl status httpd

Now open you browser and navigate to wordpress.oo, it should word like real website but it binded with you local host server. This should be usefull for development.

Robbi Nespu | Apache, Fedora, Linux

Discussion and feedback