WordPress.org

Forums

[resolved] Subdomains on localhost (11 posts)

  1. gan35h
    Member
    Posted 3 years ago #

    Because of the requirement of a site in the network called 'blog', I had to use sub-domains instead of subfolders. WordPress doesn't allow a subfolder called 'blog'.

    Anyway, so I added these changes in my hosts file:

    # 127.0.0.1 site1.localhost
    # 127.0.0.1 site2.localhost
    # 127.0.0.1 blog.localhost

    Then I went to my httpd.conf file and added the setup for each individual subdomains for localhost:

    For site 1:
    NameVirtualHost *:80
    <VirtualHost *:80>
    ServerName localhost
    ServerAlias site1.localhost
    DocumentRoot "..\htdocs\wordpress\site1"
    DirectoryIndex index.php index.html index.html index.htm index.shtml
    </VirtualHost>

    and so on for site2 and blog. I am a little unsure about using * there. I think something else goes there. :/

    I went on to activate multisite in my wp-config file as:
    define('WP_ALLOW_MULTISITE', true);

    But, at the end of the process I'm getting this message:

    Because you are using localhost, the sites in your WordPress network must use sub-directories. Consider using localhost.localdomain if you wish to use sub-domains.

    What must I do to get subdomains then?

    Would really appreciate your help here. Thanks!

  2. In your hosts file, change localhost to localhost.something. Or peas.corn. Or localhost.com. Or mytestsite.loc.

    See? :D

  3. gan35h
    Member
    Posted 3 years ago #

    1. So I should change the site1.localhost to localhost.site1 in the hosts file? And so on?

    2. I assume I must also repeat those changes in the conf file?

  4. So I should change the site1.localhost to localhost.site1 in the hosts file? And so on?

    No. You'd have to change it to site1.localhost.something.

    A domain is something.something. That's what multisite is looking for.

    subdomain.localhost throws it off, because it ads like a full domain. thus you need subdomain.localhost.whatever.

  5. We keep suggesting .loc because it's easy to replace with .com/org/net when you go live :)

  6. gan35h
    Member
    Posted 3 years ago #

    I don't think I've still got it.

    So I've made the following changes:

    Changed hosts file to read:

    127.0.0.1 localhost
    127.0.0.1 localhost.corn

    But does this mean that I have to install wordpress all over again? To point the new database towards this address?

    How about this as an alternative? I use sub-folders and use the word 'blogs' instead of 'blog' but while transferring the site to a web host, I use subdomains where I get to use 'blog' again. Would this work?

  7. If you're going to export/import your sites to move them, sure.

    If you want to just pick up your files and DB to move it, you should do

    127.0.0.1 YOURREALDOMAIN.loc
    127.0.0.1 blogs.YOURREALDOMAIN.loc

    instead. Then right before you move, do a search/replace. We speak from experience. You REALLY want to use that kind of pattern. WPMUGuru can explain it better, I jut remember that it works better.

  8. gan35h
    Member
    Posted 3 years ago #

    OK, so finally going for subdomains on localhost.

    Trouble is that I'm getting stuck.

    I added 127.0.1.1 local.loc in my hosts file along with its subdomains. I installed Apache with this address.

    When I type 127.0.1.1 in my browser, I get the 'It works' message. But it tries to look for the address 'local.loc' on the internet, which then fails.

    I changed my httpd-vhosts.conf file also to include:

    <VirtualHost *:80>
    ServerAdmin [email address]
    DocumentRoot "../htdocs/local"
    ServerName local.loc
    ServerAlias local.loc
    DirectoryIndex index.php index.html index.html index.htm index.shtml
    </VirtualHost>

    Also did this for its subdomains.

    Any suggestions?

  9. If you're using MAMP you have to edit /Applications/MAMP/conf/apache/httpd.conf

    <VirtualHost *>
    DocumentRoot "/Applications/MAMP/htdocs"
    ServerName ipstenu.loc
    </VirtualHost>

    for example

  10. gan35h
    Member
    Posted 3 years ago #

    Using Apache 2.2.19, but I added this line too. No luck :(

  11. gan35h
    Member
    Posted 3 years ago #

    OK, this is silly. But I deleted the hosts file and then made a new one using Notepad. AND IT WORKED! WHEW!

Topic Closed

This topic has been closed to new replies.

About this Topic