Convert localhost to domain name in Ubuntu

Convert localhost to domain name in Ubuntu

Domain name or Host name is used for virtual host in a computer. It can give a specific domain name to your website on localhost or a direct route to your specific folder containing website on localhost. By this, you can access every web folder with specific domain name.

We need to set vhosts(Virtual Hosts) in configuration folder of Apache2.

Go to the directory: /etc/apache2/sites-available

For every vhost you will have to make a configuration file in this directory. In the vhost configuration you can set your document root. The name of the file must end with .conf

E.g.: /etc/apache2/sites-available/mysite1.conf

Where “mysite1.conf” is the name of file. You can change “mysite1” to your desired name.

Open it in editable mode. And copy the following lines into the file and save.

<VirtualHost *:80>

ServerName anything.local

DocumentRoot “/var/www/html/yousite1

</VirtualHost>

In these lines, “anything.local” is the domain name that you want to set for site in folder /var/www/html/yousite1. “yoursite1” is the name of folder that you want to access using your domain name.

Now enable your site with:

sudo a2ensite mysite1.conf

And now restart Apache2 to get it working.

Command: service apache2 restart

Then edit your /etc/hosts file.

Just paste the following line on the end:

127.0.0.1 anything.local

Now you can access your site with http://anything.local

3 thoughts on “Convert localhost to domain name in Ubuntu

  1. Howdy I am so grateful I found your web site, I really found you by accident, while I was browsing on Digg for something
    else, Anyhow I am here now and would just like to say cheers for
    a fantastic post and a all round entertaining blog (I also love the theme/design), I don’t have time to browse it all at the minute
    but I have bookmarked it and also added your RSS feeds, so when I have time I will be back to read more,
    Please do keep up the great job.

  2. I have noticed you don’t monetize your blog, don’t waste your traffic, you can earn additional bucks every month because you’ve got hi quality content.
    If you want to know how to make extra money, search
    for: Mertiso’s tips best adsense alternative


Leave a Reply

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

*