15 February 2013

Convert localhost to domain name for your project in Ubuntu/Mint

8 comments

Hello friends today Iam going to show you how you can convert http://localhost/your_project_name to http://your_domain_name in ubuntu. If you are working on some project then it will be easier to open your project using http://domain_name rather than typing http://localhost/your_project_name each and every time you view it in your browser.It is very easy to map your project directory to domain name. Lets get started...

Note: Iam assuming that you have Apache 2 installed on your machine.

Assumption: Let my current project is /var/www/mvc_project and I want to open it by domain name sjframework.com in my browser.

converting localhost to domain name in ubuntu


Step 1: Go to /etc/apache2/sites-enabled/

$ cd /etc/apache2/sites-enabled/

Step 2: Make copy of 000-default file.

$ sudo cp 000-default myproject

Step 3: Now open your newly created file i,e. myproject with your favorite text-editor and make following changes and save it.

$ sudo vim myproject

<VirtualHost *:80>
     ServerAdmin webmaster@localhost
     #add servername
     ServerName any_name_you_want
     #add domain name
     ServerAlias domain_name_you_want
     
     #specify your project directory
     DocumentRoot  /var/www/your_project_directory
     <Directory />
       Options FollowSymLinks
       AllowOverride All
    </Directory>

    <Directory  /var/www/your_project_directory>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Order allow,deny
      allow from all
    </Directory>


apache sites-enabled file

Here is my 000-default and myproject files

apache configuration file in ubuntu

Step 4: Now open /etc/hosts file and add following line and save it.

$ sudo vim /etc/hosts

127.0.0.1 your_domain_name

ubuntu /etc/hosts file

Step 5: Restart apache server.

$ sudo service apache2 restart

Now open your project with your specified domain name

how to add domain name in apache2

Note : You can specify different domain name for different projects by creating different files in /etc/apache2/sites-enabled directory.

Note : This domain name is only local.

Hope you Enjoyed the Article :).


If You Liked This Post Please Take a Time To Share This Post

You May Also Like...

8 comments:

  1. Thank you! It is advanced but simplify our works. And damn cool!

    ReplyDelete
  2. The same thing I wanted to learn, which you shared with us, really inspiring! http://www.lowhosting.com/bluehost-review/

    ReplyDelete
  3. How i can do the same with windows and xampp system?

    ReplyDelete
  4. This information is very helpful for me because you have shared great points about this concept. iPage Review

    ReplyDelete
  5. seems outdated cant find it in my version Apache 2.4.18

    ReplyDelete