How to setup virtual host using Wamp Server properly?

前端 未结 6 2156
名媛妹妹
名媛妹妹 2020-12-06 00:43

I need your help here in creating a virtual host in wampserver. In office I can create a virtual hosts but when I try to create in my laptop it doesn\'t work. I still can\'t

相关标签:
6条回答
  • 2020-12-06 01:13

    Method 1:

    in hosts file

    127.0.0.1   mysite
    ::1 mysite
    

    in C:\wamp64\bin\apache\apache2.4.23\conf\extra\httpd-vosts.conf file add your virtual host as follows

    <VirtualHost *:80>
        ServerName mysite
        DocumentRoot "<path_to_your_local_site>"
        <Directory  "<path_to_your_local_site>">
            Options +Indexes +Includes +FollowSymLinks +MultiViews
            AllowOverride All
            Require local
        </Directory>
    </VirtualHost>
    

    Make sure vhost configuration is enable in httpd.conf file is enabled as follows C:\wamp64\bin\apache\apache2.4.23\conf\httpd.conf

    # Virtual hosts
    Include conf/extra/httpd-vhosts.conf
    

    After you have changed configuration as above, restart all service in wamp and load website as follows http://mysite your local site should open.

    Method 2:

    In latest versions of wamp, you can do this configuration via webpage. Open localhost in your browser. You would see wamp welcome page.

    Down below under Tools, there is option to add virtual host. click on the link which would take you to add virtual host page.

    In Name of the host, enter your site name eg: mysite Under Complete absolute path of the VirtualHost folder, enter the path of your site.

    Save the config and restart all services. you should be able to open mysite with the link http://mysite

    As pointed in another answer, in newer versions of wam

    0 讨论(0)
  • 2020-12-06 01:15

    If when you use the new domain in the browser it goes to a google search or something like that then the change to your hosts file has not been recognised.

    You have to either reboot after changing the hosts file or more simply run these 2 commands from a command windows ( as administrator )

    net stop dnscache
    net start dnscache
    

    This will refresh windows DNS cache and pick up your hosts file changes.

    It is also a good idea to ping your new domain to check it is being seen, use

    ping chelle.wpblog.local
    

    If it reports 127.0.0.1 as the ip address and 4 send and 4 receieved packet then the domain is now known to Windows, if it reports some other ip address the hosts file change has not succeeded.

    Also it is a good idea when creating VHOSTS to also create one for localhost or the wamp home page will not work. You also have old Apache 2.2 syntax (Order allow,deny allow from all) you could try using the Apache 2.4 syntax, see below

    So try this

    ## must be first so the the wamp menu page loads
    <VirtualHost *:80>
        ServerAdmin webmaster@mail.net
        DocumentRoot "D:/wamp/www"
        ServerName localhost
        <Directory  "D:/wamp/www">
            Require local
        </Directory>
    </VirtualHost>
    
    <VirtualHost *:80> 
        ServerAdmin webmaster@mail.net
        ServerName chelle.wpblog.local 
        ServerAlias www.chelle.wpblog.local 
        DocumentRoot "E:/Subversion/chelle.wpblog.local" 
        <Directory "E:/Subversion/chelle.wpblog.local"> 
            Options Indexes FollowSymLinks MultiViews 
            AllowOverride All 
            Require all granted
        </Directory>
    </VirtualHost>
    
    0 讨论(0)
  • 2020-12-06 01:21

    In WampServer 3.0.4 you do not need to run through all those setting up. Go to local host and under Tools area for "Add a Vertual Host" in the first time it will say turn on "Vertual Host sub menu" in wamp server settings. To get there right click on wamp icon > go to wamp server settings > and click on Vertual Host sub menu. Then re-fresh the page and follow the setup process, you just need to provide the server name and path. It will do all the works for you. Simple as that

    0 讨论(0)
  • 2020-12-06 01:25

    The answers above are overcomplicating the problem somewhat, and in fact the question is including extra information that's misleading the responders.

    The clues lie in step 2 and the symptoms described in 5. The hosts file is set up but when the request is made to "blah.local", google responds. Apache is not involved.

    The first step to diagnosis would be pinging blah.local and seeing that it maps correctly to 127.0.0.1. I have never (in many years as a developer) found it necessary to restart local DNS on either Windows or Linux/Mac so I would expect this to work out of the box. But if it doesn't, of course restart DNS and see that it does.

    However, late versions of Chrome at least do not recognize the TLD '.local' and so when you put the URL back in the browser, it's passed on to Google as a search term. There may be a setting in your browser to tell it to handle the unsanctioned TLD, but your simplest solution would be to use a TLD that's sanctioned by W3C like '.com'.

    In short, if your hosts file reads something like

    127.0.0.1     local.chelle.wpblog.com
    

    rather than

    127.0.0.1     chelle.wpblog.local
    

    everything should work.

    0 讨论(0)
  • 2020-12-06 01:34

    Fast and easy,

    1. Create the folder for your local website
    2. Go to localhost (browser)
    3. Click Add a Virtual Host button
    4. Add the name of the virtual host
    5. Add the complete absolute path
    6. Restart DNS

    Since this thread is old, perhaps you can just download WampServer from their website and install it. Once you have WampServer installed, you can check this article on How to Create Virtual Host Using WampServer & Install WordPress and follow the instruction. It is super fast and easy.

    0 讨论(0)
  • 2020-12-06 01:40

    I was installing the zend framework on my local wamp using apache server. First go and decide what will be your domain name for the local url. Ex->zend_tutorial then go and open the file located at "C:\WINDOWS\system32\drivers\etc\"

    hosts

    write

    127.0.0.1 (use one tab space) zend_tutorial

    then go to the folder located at

    D:\wamp\bin\apache\Apache2.2.17 (whatever is your version) \conf\

    and open the file

    httpd.conf

    and search for text

    Include conf/extra/httpd-vhosts.conf

    and uncomment it by removing the # tag from the start of the line.Save the file and close it. Now go to another folder located at

    D:\wamp\bin\apache\Apache2.2.17\conf\extra

    and open the file

    httpd-vhosts.conf

    and paste the code below at the last in this file

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot "D:\wamp\www"
        ServerName localhost
        ErrorLog "logs/localhost-error.log"
        CustomLog "logs/localhost-access.log" common
    </VirtualHost>
    
    <VirtualHost *:80>
        ServerName zend_tutorial
       DocumentRoot "D:\wamp\www\(your project folder name)\public"
        SetEnv APPLICATION_ENV "development"
        <directory "D:\wamp\www\(your project folder name)\public">
            DirectoryIndex index.php
            AllowOverride all
            Order Allow,Deny
            Allow from all
        </directory>
    </VirtualHost>
    

    and restart the wamp, now write the zend_tutorial in the browser and you will see the things working.

    0 讨论(0)
提交回复
热议问题