Skip to main content
LinuxLinuxUbuntuOpen Source

Convert localhost to domain name in Ubuntu

Apisylux TeamMay 30, 20172 min read

Knowledge map

Article briefing

Published
Linux
Topic category
2 min read
Estimated reading time
Apisylux Team
Author
May 30, 2017
Published
July 8, 2026
Last updated
4
Tags
1
Category
2m
Read Time
1
Next Step
Convert localhost to domain name in Ubuntu
Convert localhost to domain name in Ubuntu article image
Convert localhost to domain name in Ubuntu - preserved image from the migrated article.

Overview

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 <u>Apache2</u>.

Free Consultation

Need help with Linux?

Get a free strategy session with our experts — no commitment required.

Contact Us

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

Key steps and notes

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:

Final notes

127.0.0.1 anything.local

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

Launch readiness

Let's turn your website into a working growth system.

Bring the goal. We'll help shape the offer, interface, lead flow, launch plan, and next actions so your website feels ready for real buyers.

Start Your Project

Project readiness panel

Online

Scope clarity

Discovery ready

Performance plan

Speed-first build

Launch path

Secure deploy

Lead flow

CRM-ready handoff

Free

Consultation

<24h

Response

Clear

Plan

Next action

Share your current website, project goal, and deadline. We'll return with a practical improvement path and first-step estimate.