1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Fake domains in localhost

Discussion in 'Domain Names & Parking' started by Conor, Mar 4, 2014.

  1. Conor

    Conor Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,354
    Likes Received:
    5,415
    Gender:
    Male
    Location:
    South Africa
    Home Page:
    I had some free time today, so I thought I'd play around in Ubuntu (13.10), and see what I can do in LAMP. These steps can be transposed to Windows pretty easily though.

    So what are we doing? Well, as an ego boost, and convenient way to organise your sites in localhost, we are going to be making custom domain names. The "proper" word for this is "Virtual Host". I felt like making wordpress.local my official place for local Wordpress testing, mockup designs, etc.

    Of course, you can always just use a subfolder, but I think this is cooler.

    So where to start? Make sure LAMP is installed. If not, run this:
    Code:
    sudo apt-get install lamp-server^
    Check. Next, you'll want to edit /etc/hosts, and add your chosen domain "wordpress.local" after "localhost".

    It should look like this:
    Code:
    127.0.0.1    localhost wordpress.local www.wordpress.local
    Notice how I have the www version of my domain listed there too. That's so it works, no matter whether I type www.wordpress.local, or not. You can just keep adding to this line, for every new domain you want to add. The extension isn't important. You could have yoloswag.parishilton if you wanted.

    The next bit requires a bit of brain usage, so bear with me here. You want to run this command:
    Code:
    sudo a2enmod vhost_alias
    It just makes things work, don't ask me why. Google has a ton of answers.

    Next, you want to run:
    Code:
    sudo gedit /etc/apache2/sites-available/newsite.conf
    This will open your text editor, where the final bit of code can be pasted. Make sure to change Directory and DocumentRoot (/var/www/wordpress) to match the folder you wish to use for your site:
    Code:
    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName wordpress.local
        ServerAlias www.wordpress.local
        DocumentRoot /var/www/wordpress
        <Directory />
            Options FollowSymLinks
            AllowOverride None
        </Directory>
        <Directory /var/www/wordpress/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
            Require all granted
        </Directory>
    </VirtualHost>
    
    You can pretty much copy and paste this whole block of text, for every new domain you wish to create, after adding it to your hosts file. It's that easy.

    Done and dusted. Now all we need to do is activate it, and restart apache:
    Code:
    sudo a2ensite newsite
    sudo service apache2 restart
    
    And there you go. You can now go and add your index.php file, or install Wordpress in the directory you specified earlier. Navigate to http://wordpress.local in your browser, and you should be set!

    I have experienced problems with some WP themes and plugins in the past, when it's installed in a subfolder, so that was my main inspiration for doing this. If you have any questions, I'll try find the answer for you. I'm in no way an expert with stuff like this, but I know how Google works.

    For some extra reading, check these out:
    http://gregrickaby.com/how-to-install-lamp-on-ubuntu/
    http://ubuntuforums.org/showthread.php?t=1925236
    http://www.techrepublic.com/blog/smb-technologist/create-virtual-hosts-in-a-wamp-server/
    http://helpdeskgeek.com/windows-7/windows-7-hosts-file/

    Finally, like I mentioned before, I was using Ubuntu 13.10 for this, so some of the codes may be a little bit different for your version of Linux. To get this working in Windows, your "hosts" file is located in \system32\drivers\etc\.

    You will want to paste the big block of text in httpd-vhosts.conf, which can be accessed through your WAMP or XAMPP settings.

    I'll stop talking now. I'm sure someone could figure out a way of making money with this ;)
     
    • Thanks Thanks x 1
    Last edited: Mar 4, 2014
  2. DiamonMike

    DiamonMike Regular Member

    Joined:
    Aug 22, 2013
    Messages:
    217
    Likes Received:
    63
    How exactly could we make money with this?
     
  3. Conor

    Conor Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,354
    Likes Received:
    5,415
    Gender:
    Male
    Location:
    South Africa
    Home Page:
  4. innozemec

    innozemec Jr. VIP Jr. VIP

    Joined:
    Aug 19, 2011
    Messages:
    5,288
    Likes Received:
    1,799
    Location:
    www.Indexification.com
    Home Page:
    Yep, this works quite good for organizing your sites locally

    For years i am proud owner and hoster of a.com b.com c.com d.com and etc... all on my PC :)
     
    • Thanks Thanks x 3
  5. DiamonMike

    DiamonMike Regular Member

    Joined:
    Aug 22, 2013
    Messages:
    217
    Likes Received:
    63
    Like really really REALLY locally :)))
     
  6. indebt

    indebt Junior Member

    Joined:
    May 19, 2009
    Messages:
    108
    Likes Received:
    47
    Cool. Im going to host youtube.com, facebook.com and google.com on my computer. Plus Im going to take all the money from my Monoply board game and count how rich i am
     
  7. Conor

    Conor Jr. VIP Jr. VIP

    Joined:
    Nov 7, 2012
    Messages:
    3,354
    Likes Received:
    5,415
    Gender:
    Male
    Location:
    South Africa
    Home Page:
    Lol you're missing the point dude. This isn't just a fun party trick. It's about organising your testing sites more conveniently, for those of us who get sick of typing localhost/subfolder.

    Edit: I just looked over the total extent of your contributions to the forum. You sign in once a year, make one sarcastic post, and then hibernate for the next 364 days. See you next Winter...
     
    Last edited: Mar 6, 2014