7

How can I set up a VirtualHost on my local developer environment? Ideally I would also like to be able to access my site from a simply URL, such as www.joomla.loc rather than having to constantly use the localhost URL.

3 Answers 3

9

In this I will explain how to set this up for Wampserver 2.5 with Apache 2.4+.

Once you have downloaded, installed and started Wampserver, go to the following directory on your computer and created a new folder called "joomla"

C:\wamp\www

Within your newly created folder, extract the Joomla zip file.

Now that you have your new folder with the Joomla installation in there, you now need to open the following file in a text editor, such as Notepadd++

C:\Windows\System32\drivers\etc\hosts

In this file, add the following, which will map the localhost IP address to the defined URL:

127.0.0.1       joomla.loc www.joomla.loc

Note that I have 2 instances, 1 with www and 1 without. If you are unable to save and are thrown a permissions error, try running your text editor on Administrator Mode, by right clicking the .exe and going to "Run as Administrator".

Save the file, and then open the following file in your text editor

C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf

Add the following to the file above at the bottom:

<VirtualHost *:80>
    DocumentRoot "C:/wamp/www/joomla"
    ServerName joomla.loc
    <Directory  "C:/wamp/www/joomla">
        AllowOverride All
        Require local
    </Directory>
</VirtualHost>

The above code is only for Apache 2.4+ and will NOT work for Apache 2.2.

You've now created your VirtualHost for your newly created folder. All you need to do now is restart Apache, by clicking the green Wampserver on your taskbar, then clicking "Restart All Services" as shown in the screenshot below:

enter image description here

You can now type in www.joomla.loc in your browser and install Joomla

Hope this helps. Would be also nice if some people who are running other development environments such as Xampp, Lamp and Mamp could post an answer too

2
  • +1 very helpful thanks @Lodder! Is there any benefit to doing this, other than not having to add 'localhost/' before the address?
    – jonboy
    Aug 21, 2014 at 10:08
  • There are quite a few reasons, some being more technical than other. Hopefully the info on this page will help: httpd.apache.org/docs/2.0/vhosts/name-based.html ... for me personally, I just find it makes life much easier and also helps with CMS's as there can sometimes be problems with absolute and relative URL's
    – Lodder
    Aug 21, 2014 at 10:31
7

Instructions for Linux OS with Apache 2+ Server:

  1. Edit the file /etc/hosts and add this line:

    127.0.0.1    joomla
    
  2. Create a .conf file like joomla.conf inside the /etc/apache2/sites-enabled directory, then open it and add these lines:

    <VirtualHost *:80>
        ServerName joomla
        DocumentRoot /var/www/joomla
        <Directory /var/www/joomla>
            AllowOverride All
        </Directory>
    </VirtualHost>
    
  3. Restart the Apache server:

    sudo /etc/init.d/apache2 restart
    

Now type in your browser's address bar: http://joomla and hit Enter!

Note

  • You must be a super user in order to edit the above files.
  • If you use Geany text editor, the command would be:

    sudo geany /etc/hosts
    

    and

    sudo geany /etc/apache2/sites-enabled/joomla.conf
    
7

I've just did this with OSX and here's how;

All websites on OSX are stored in users/sites

Step 1

Create a new website folder called 'joomla'

cd ~/Sites/
mkdir joomla

Step 2

Now add a new record to Apache's host file - edit httpd-vhosts.conf file normally located in private/etc/apache2/extra/

Add the following to the file (change names accordingly);

<VirtualHost *:80>
    DocumentRoot "/Users/UserName/Sites/joomla"
    ServerName joomla
    <directory "/Users/UserName/Sites/joomla">
    AllowOverride All
    </directory>
</VirtualHost>

ServerName is the name you will type into your address bar to access your website.

DocumentRoot is where your website is located.

Step 3

Now edit the hosts file normally located in /private/etc/hosts

Add another record to point to the new website;

127.0.0.1    joomla

Step 4

Lastly, restart Apache apache restart

You should now be able to go to http://joomla and acces your website!

Worked for me.

Hopefully I haven't left anything out!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.