June 3, 2012


How To Set Up Apache Virtual Hosts on Ubuntu 12.04 LTS

Tagged In: Ubuntu, Apache

What the Red Means

The lines that the user needs to enter or customize will be in red in this tutorial!

The rest should mostly be copy-and-pastable.

About Virtual Hosts

Virtual Hosts are used to run more than one domain off of a single IP address. This is especially useful to people who need to run several sites off of one virtual private server. The sites display different information to the visitors, depending on with which the users accessed the site.There is no limit to the number of virtual hosts that can be added to a VPS.

Set Up

The steps in this tutorial require the user to have root privileges. You can see how to set that up in the here Initial Server Setup. You can implement whatever username suits you.

Additionally, you need to have apache already installed and running on your virtual server
If this is not the case, you can download it with this command:
sudo apt-get install apache2

Step One— Create a New Directory

The first step in creating a virtual host is to a create a directory where we will keep the new website’s information.

This location will be your Document Root in the Apache virtual configuration file later on. By adding a -p to the line of code, the command automatically generates all the parents for the new directory.
sudo mkdir -p /var/www/example.com/public_html

You will need to designate an actual DNS approved domain, or an IP address, to test that a virtual host is working. In this tutorial we will use example.com as a placeholder for a correct domain name.

However, should you want to use an unapproved domain name to test the process you will find information on how to make it work on your local computer in Step Seven.

Step Two—Grant Permissions

We need to grant ownership of the directory to the user, instead of just keeping it on the root system.
 sudo chown -R $USER:$USER /var/www/example.com/public_html 

Additionally, it is important to make sure that everyone will be able to read our new files.
 sudo chmod -R 755 /var/www

Now you are all done with permissions.

Step Three— Create the Page

Within our configurations directory, we need to create a new file called index.html
sudo nano /var/www/example.com/public_html/index.html

We can add some text to the file so we will have something to look at when the IP redirects to the virtual host.
    <h1>Success: You Have Set Up a Virtual Host</h1>

Save and Exit

Step Four—Create the New Virtual Host File

The next step is to set up the apache configuration. We’re going to work off a duplicate—go ahead and make a copy of the file (naming it after your domain name) in the same directory:
 sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example.com

Step Five—Turn on Virtual Hosts

Open up the new config file:
 sudo nano /etc/apache2/sites-available/example.com

We are going to set up a virtual host in this file.

The first step is to insert a line for the ServerName under the ServerAdmin line.
  ServerName example.com 

The ServerName specifies the domain name that the virtual host uses.

If you want to make your site accessible from more than one name (for example, with www in the URL), you can include the alternate names in your virtual host file by adding a ServerAlias Line. The beginning of your virtual host file would then look like this:
<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName example.com
        ServerAlias www.example.com

The next step is to fill in the correct Document Root. For this section, write in the extension of the new directory created in Step One. If the document root is incorrect or absent you will not be able to set up the virtual host.

The section should look like this:
 DocumentRoot /var/www/example.com/public_html 

You do not need to make any other changes to this file. Save and Exit.

The last step is to activate the host, with the built in apache shortcut:
 sudo a2ensite example.com

Step Six—Restart Apache

We’ve made a lot of the changes to the configuration, and the virtual host is set up. However none of the changes that we made will take effect until Apache is restarted. Use this command to restart apache:
 sudo service apache2 restart

You may see an error along the lines of
Could not reliably determine the server's fully qualified domain name, using for ServerName 

The message is just a warning, and you will be able to access your virtual host without any further issues.

Optional Step Seven—Setting Up the Local Hosts

If you have pointed your domain name to your virtual private server’s IP address you can skip this step—you do not need to set up local hosts. Your virtual hosts should work. However, if want to try out your new virtual hosts without having to connect to an actual domain name, you can set up local hosts on your computer alone.

For this step, make sure you are on the computer itself, not your droplet.

To proceed with this step you need to know your computer’s administrative password, otherwise you will be required to use an actual domain name to test the virtual hosts.

If you are on a Mac or Linux, access the root user (su) on the computer and open up your hosts file:
nano /etc/hosts 

If you are on a Windows Computer, you can find the directions to alter the host file on the Microsoft site

You can add the local hosts details to this file, as seen in the example below. As long as that line is there, directing your browser toward, say, example.com will give you all the virtual host details for the corresponding IP address.
# Host Database
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##       localhost

#Virtual Hosts    example.com

However, it may be a good idea to delete these made up addresses out of the local hosts folder when you are done to avoid any future confusion.

Step Eight—RESULTS: See Your Virtual Host in Action

Once you have finished setting up your virtual host, you can see how it looks online. Type your ip address into the browser (ie.

It should look somewhat similar to my handy screenshot

Good Job!

Creating More Virtual Hosts

To add more virtual hosts, you can just repeat the process above, being careful to set up a new document root with the appropriate domain name, and then creating and activating the new virtual host file.

See More

Once you have set up your virtual hosts, you can proceed to Create a SSL Certificate for your site or Install an FTP server

By Etel Sverdlov

Share this Tutorial

Vote on Hacker News

Try this tutorial on an SSD cloud server.

Includes 512MB RAM, 20GB SSD Disk, and 1TB Transfer for $5/mo! Learn more

Create an account or login:


Write Tutorial
  • Gravatar Kurnia Ramadhan over 1 year

    How to make 'www' going to example.com when I call 'www.example.com' in the browser?

  • Gravatar jon over 1 year

    You need to add a server alias directive like so: ServerName example.com ServerAlias www.example.com

  • Gravatar Etel over 1 year

    Thank you for your help and feedback. We've updated the article to include info on Server Aliases.

  • Gravatar chris over 1 year

    Hi, Hope this helps Video http://youtu.be/QaZBly7_0zo http://wilson18.com/how-to/linux-net...-server-12-04/

  • Gravatar zenbuddha77 over 1 year

    This isn't working at all for me. I had previously used Webmin to configure Apache2 and Bind9 before finding this tutorial for 12.04. The set up I used then was based on settings for Ubuntu 11.xx. Any chance that the prior settings could be overriding the new ones I used based on what you said they should be? And if so any idea on how to correct them. Everything you said to edit I did and looked exactly like what you said they should look like except for the editing of: nano /etc/hosts. Mine looked like this: # Host Database # # localhost is used to configure the loopback interface #when the system is rebooting. Do not change this entry. ## localhost ubuntu # Virtual Hosts xx.xx.xx.xx www.broomeunderground.com # The following lines are desirable for IPv6 capable hosts (<-Or should I have deleted this & everything below this?) ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters Thanks.

  • Gravatar Moisey over 1 year

    You do not need to edit the /etc/hosts file unless you are on a Mac and want to test connecting to your webserver using the domain instead of the IP. If you give us some more information on what errors you are receiving, if you are installing over an existing Apache2 or something else we can help you troubleshoot it. You can also open up a support ticket and we'll do our best to guide you in the right direction.

  • Gravatar suhailqadeer over 1 year

    Not working for me either. snippet from my hosts file is given below: www.example.com I get the following error: Server not found Firefox can't find the server at

  • Gravatar Etel Sverdlov over 1 year

    You may need to clear the cache on your browser. Once you do that, the domain should resolve.

  • Gravatar jhawk44652 over 1 year

    But My Question how to you go about give a user to upload to there virtual host file area?

  • Gravatar Moisey over 1 year

    You can create normal users and set their virtualhost directories to be in their home directories such as: /home/user/domain.com/public_html

  • Gravatar shabeer.sheffa over 1 year

    My keep directing me to the default apache page where is says "it works", and not the new one i created, neither does www.example.com

  • Gravatar Etel Sverdlov over 1 year

    Is your new page located in the directory that the document root is pointing to? You can create a new directory for your site, point your document root there, and then upload all of your site files within it to ensure that the only possible files that are within it are the new ones you want online.

  • Gravatar jhawk44652 over 1 year

    i got everything working with my Virtual hosting. Is there away that I can also have it look for home.html and index.htm

  • Gravatar Moisey over 1 year

    You can specify multiple files to serve as your index: DirectoryIndex index.html index.htm home.html They will be processed in order of precedence from left to right, so from the above directive Apache will first look for an index.html, then index.htm, and finally home.html

  • Gravatar thekentos123 over 1 year

    this doesn't work for me either, I ended up backing everything up and reloading the OS ( 12.04 ) on my server. I ran through this basic set-up using two domain names, creating and enabling one then the other. the document root is not being used for either domain names, always going to the default index file, and im guessing the default web server.

  • Gravatar Moisey over 1 year

    You should have a DirectoryIndex setting inside your VirtualHost or a global one that is set outside of your VirtualHost declaration. That allows you to set multiple index files in order of precedence.

  • Gravatar a3070904 over 1 year

    Thanks for this article. All works like charm expect .htaccess. will you help? .htaccess not working for me! Regards- Raj

  • Gravatar admin over 1 year

    There is a good chance that AllowOverride has the wrong setting and will not allow .htaccess to function. Check the Apache configuration for this directive and set it to All then restart the web server. That should allow .htaccess to work, you can find more info about this directive here: http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

  • Gravatar spartak over 1 year

    thanks for the post but it doesnt work for new apache2. Cant connect!

  • Gravatar Etel Sverdlov over 1 year

    Hi Spartak—this tutorial is written for apache2. What issue are you experiencing when you try to connect?

  • Gravatar bydgoszcz about 1 year

    A very nice tutorial. THANK YOU :)

  • Gravatar anilkasar12 about 1 year

    i Want to assign domain as www.domain1.com for and dom.domain1.com for is it possible?

  • Gravatar Moisey about 1 year

    If you have a domain you can just point it directly to the directory you want to server from by updating the document root, so it would be: ServerName domain1.com DocumentRoot /path/to/www Then a separate VirtualHost directive with: ServerName dom.domain1.com DocumentRoot /path/to/www/dom

  • Gravatar ngilbert about 1 year

    It's important to note that while working through this tutorial I discovered that apache is running as user www-data a member of the www-data group. HTH

  • Gravatar mihai about 1 year

    In step 2, are you assuming there is a user:group www:www? This is not by default on my ubuntu, do I have to create it?

  • Gravatar Moisey about 1 year

    If you dont have them, you should create them, or you can set them to a user:group that you want your web files owned as.

  • Gravatar fsshl about 1 year

    I follow every steps in the article(except the last section), I already register an myolddomain.com associate with my public ip at some website,, not modify my ubuntuLinux pc, it work to see /var/www/index.html, so I repeat some process to do on my example.com, but when I type in http://example.com, it show same content as myolddomain.com(not /var/www/example.com/public_html/index.html), plz help

  • Gravatar Moisey about 1 year

    That looks like an issue with not updating the ServerName between the two VirtualHosts or the IP which the domain is pointed to vs having a catch-all for the IPs above. So check the VirtualHost directive and the IP it listens on and the ServerName directive.

  • Gravatar bigxblackxdogx about 1 year

    I modify /etc/apache2/sites-abailable/example.com , so in its VirtualHosts, *:80, I substitute * by my public ip, then rerun a2ensite and service apache2 restart, then I go outside to check http://example.com, it still show same content as /var/www/index.html. when I run service apache2 restart, my system reply: root@eric-laptop:/# service apache2 restart * Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName ... waiting ....apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName [ OK ] ------------ so where go wrong or where I should fix/modify?

  • Gravatar Rozi about 1 year

    ServerAlias is not working. I want to prepend www to my domain, but still no luck :(

  • Gravatar Moisey about 1 year

    You'll want to make sure that the DocumentRoot is also updated inside of your VirtualHost definition to point to where you want the content to be served from. As for ServerAlias it should just be: ServerAlias www.domain.com If you have that it is most likely something else that is having an issue. Also check your DNS to make sure that www.domain.com resolves to the IP that you expect.

  • Gravatar Ben Okumura about 1 year

    I've set everything up. ServerAlias is correct. The domain resolves when going to domainname.com but not when going to www.domainname.com. The DNS points to the Digital DNS. What else could be the issue?

  • Gravatar Ben Okumura about 1 year

    Update: the site resolves with www now, not sure how it got fixed but it started working a few hours later.

  • Gravatar Andrea about 1 year

    Hi, anyone get this error message: apache2: Syntax error on line 239 of /etc/apache2/apache2.conf: Cannot load /home/username/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/ext/apache2/mod_passenger.so into server: /home/username/.rvm/gems/ruby-1.9.3-p194/gems/passenger-3.0.12/ext/apache2/mod_passenger.so: cannot open shared object file: No such file or directory Action 'configtest' failed. The Apache error log may have more information. ...fail! at the final restarting of apache?

  • Gravatar Andrea about 1 year

    solved running again "passenger-install-apache2-module" and insert my user instead of "username" into the Apache configuration

  • Gravatar iesmandau about 1 year

    Got it working successfully but can't get the virtual host to parse my PHP files (Wordpress, etc) Any clue?

  • Gravatar dpatte about 1 year

    Hi. First, I'd like to say this is a very clear article, and it tought me a lot. But unfortunately, I may have done something wrong, because the virtual host I set up is not working. backgrounder: I set up a brand new system on ubuntu 64 12.10. Its working fine. apache was showing me a default page when I when I went to the ip. I even changed the default page to ensure it was using my change. So I decided to add a virtual host, and believe I did follow the above instructions. But my computer is on a network where I cannot use port 80, so i changed default and my new available to 8080. I have opened 8080 and 8081 on my router. My domain is registered and does point to my server. But after following my instructions going to my ip:8080 still shows me my default page, and trying to go to my domain:8080 cannot resolve and gives an error. If i go to my domain.com (at 80) it still goes to my old site on the old webserver as expected. Any ideas. I'm new to apache. Thanks

  • Gravatar benny.subarja about 1 year

    Sudo chown -R www-data:www-data /var/www/example.com/public_html This command line is working better for me

  • Gravatar kabir2eyes about 1 year

    How do I point my domain to this virtual host?

  • Gravatar local8 about 1 year

    possible with nginx?

  • Gravatar hu_davy about 1 year

    Hi there, I am trying to host my web site an home. I have my Apache Web Server and Tomcat Server integrated and running well on my computer. I have created the domain in no-ip. I have configured the no-ip DNS server (the status is connected after done) and 80 port forwarding on my d-link dir 615 router (I tested the 80 port in "http://www.canyouseeme.org/" and it said the port 80 is open). The no-ip client test everything good. I also added one line in my "hosts" file in windows like " 69.165.XXX.XXX webapp.no-ip.org". But when I try to access my website, I got "Internet Explorer cannot display the webpage". When I click "diagnose connection problem", I got "website is online but isn't responding to connection" first. When I do it again, it changed into "the remote device or resource won't accept the connection" and "The device or resource (webapp.no-ip.org) is not set up to accept connections on port "The World Wide Web service (HTTP)". when I ping the IP it is connected successfully Pinging 69.165.XXX.XXX with 32 bytes of data: Reply from 69.165.XXX.XXX: bytes=32 time=5ms TTL=64 ...... But when I telnet the IP with 80, I got Connecting To 69.165.XXX.XXX...Could not open connection to the host, on port 80: Connect failed I am using Kaspersky internet security 2013. Thanks a lot for any help in advance!

  • Gravatar Matt Dance about 1 year

    I have an issue. Followed the tutorial. www.mattdance.com works mattdance.com does not work. What might the issue be?

  • Gravatar Goran Ljubuncic about 1 year

    I have an issue, followed the article but when I access my server's ip address I get the default "It works!" page instead of the index.html I just created

  • Gravatar reloader about 1 year

    I set up localhost in a matter of minutes, but for me also: example.com works www.example.com keeps redirecting me to http://www.iana.org/domains/example My conf: ServerAdmin webmaster@localhost ServerName example.com ServerAlias www.example.com Tried changing ServerAlias to http://www.example.com, nothing helps. Also, I can't make step seven works, no matter how much I'm trying. Typing into the browser keep showing me "can't find the server at" Please help.

  • Gravatar reloader about 1 year

    Here's my /etc/hosts localhost shadow example.com # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters

  • Gravatar reloader about 1 year

    For www.example.com to start working i needed to add www.example.com To /etc/hosts. So that is solved. All that remains is to make step seven working.

  • Gravatar BeeTall about 1 year

    This article works quite good. Thanks. Using dot.tk for a free domain registration as mentioned in another digitalocean article ( https://www.digitalocean.com/community/articles/how-to-install-iredmail-on-ubuntu-12-10-x64 ) is helpful to test the virtual hosts. Working with local hosts file is good but having your domain name is the way to go. Once you have the virtual hosts set up, you can configure the location and names of the access or error logs for each of your virtual hosts.

  • Gravatar colmnolan 12 months

    Great article. Very Clear. Hey I just thought I would put this out there because I have found it quite useful and is related to this article. I wrote a bash script to quickly change the root in the default virtual host file and then restart the server. so to change the default root to say ~/www/mysite.com/public_html you simply run the following command me@UBU:~$ sudo script_below ~/www/mysite.com/public_html and it will change the root and restart the server. The site can then be viewed on localhost!! Make sure and copy the script into /usr/local/bin/ Also this has only been tested on Ubuntu 12.04 so check that the paths in the script match your system. ######start of script #!/bin/bash #script to change the root of the apache server and then restart server #configure the location to show wherever the default file is located apache2_config_file='/etc/apache2/sites-available/default' full_path_name="" full_path_name_with_escs="" str_1_start=" DocumentRoot " regex_1="" regex_1_start='s/[[:blank:]]+DocumentRoot ([[:alnum:]]|\/|_|-|\.){2,}$/' str_2_start=" " regex_2="" regex_2_start='s/[[:blank:]]+$/' temp_file="" #ensure the first parameter is included if [[ -n $1 ]]; then #ensure it is a directory if [[ -d $1 ]]; then full_path_name=$(readlink -f $1) full_path_name_with_escs=$(echo "$full_path_name" | sed -r 's/\//\\\//g') #ensure the user only hosts websites in the home directory if [[ "$full_path_name" =~ "$HOME" ]]; then #ensure the apache2 configuration file acually exists if [[ -e $apache2_config_file ]]; then regex_1="${regex_1_start}${str_1_start}${full_path_name_with_escs}/" temp_file=$(sed -r "$regex_1" $apache2_config_file) regex_2="${regex_2_start}${str_2_start}${full_path_name_with_escs}${str_2_end}/" temp_file=$(echo "$temp_file" | sed -r "$regex_2") echo "$temp_file" > $apache2_config_file /etc/init.d/apache2 restart exit 0 else echo "the file to configure does not exist" >&2 exit 1 fi else echo "the website root needs to be within the Home directory" >&2 exit 1 fi else echo "$1 is not a directory" >&2 exit 1 fi else echo "No argument provided to the command" >&2 exit 1 fi ####end of script

  • Gravatar thagaba 12 months

    To those who are seeing /var/www/ e.g. the default index.html, or a directory listing of virtual hosts, or a site which had been served prior to the virtual host configuration, i.e. thekentos123, fsshl, and Goran Ljubuncic try disabling the default site with sudo a2dissite default and then sudo service apache2 restart

  • Gravatar Eduard 11 months

    I'm moving a site, it's working now on the old server, how can I test the site on the new server without moving the domain? I've created some VirtualHosts (I'll have two or three sites), but I only can see the directory scafolding (no server running?). Thanks.

  • Gravatar Kamal Nasser 11 months

    @Eduard: You can manually edit /etc/hosts on your local pc so you can test on the new server before you switch the DNS.

  • Gravatar vikas.saroha 11 months

    Hi, Great Article. Thanks. My domain is redirecting to the server now and every thing seems to work fine. Except that in the URL bar, instead of example.com (my domain name), i see server IP/root directory If I set the document root to /var/www, the default Apache "It works" page loads and the domain name is also retained in the URL bar. Please help if I am missing any config. thanks

  • Gravatar Eduard 11 months

    Thanks @Kamal, it's working ;) Is it possible to acces the web with a url like XX.XX.XX.XX/folderName ?

  • Gravatar Kamal Nasser 11 months

    @vikas.saroha: Do you mean when you browse to yourdomain.com you get redirected to your server's IP address? @Eduard: Yes it is possible. You can create another Virtual Host, put your IP address as the ServerName, and point DocumentRoot to /var/www.

  • Gravatar dpatte 11 months

    Re- my post of March 2nd. I had a typo in my conf file. All's fine now

  • Gravatar gamalblake 10 months

    Hello; Unfortunately, DocumentRoot /var/www/example.com/public_html result in "command not found" via ssh Kind Regards.

  • Gravatar Kamal Nasser 10 months

    @gamalblake: Please read the article carefully. The DocumentRoot part isn't a command and should not be ran as you would run a command.

  • Gravatar gamalblake 10 months

    @ Kamal Nasser do forgive me, i certainly read the tutorial incorrectly above. On the other hand, thank you for any such assistance, on your part.

  • Gravatar Kamal Nasser 10 months

    @gamalblake It's fine :] Did you figure it out?

  • Gravatar james 10 months

    Thank you so much for the this article! It has helped me alot. I am running into the problem I see a lot of other people on here have had. I can get the mydomain.com to work just fine but www.mydomain.com will not come up at all. I have tried and retried these steps just to make sure I wasn't missing something and it still doesn't work. I have even created an A record for www.mydomain.com in DO DNS control panel and have it pointed to my droplets ip address. Any ideas as to why it doesn't work?

  • Gravatar Kamal Nasser 10 months

    @james, both of your domain names are resolving properly. Please pastebin your apache virtualhost config - make sure you restart apache2 after adding virtualhosts.

  • Gravatar vinod.maurya1 10 months

    Best solution for creating virtual host on ubantu linux system: Open terminal and write some command: /etc/apapche2/sites-enabled$ sudo gedit 000-default ServerName symfony.localhost DocumentRoot /var/www/Symfony/web DirectoryIndex app.php ErrorLog /var/log/apache2/jobeet-error.log CustomLog /var/log/apache2/jobeet-access.log combined AllowOverride All Allow from All again on termint write /etc$ sudo gedit hosts symfony.localhost and restart you apache

  • Gravatar jkhiebert 10 months

    I did all the steps above but when I navigate to my domains, they cannot be found. I set my domains nameservers to the digital ocean ones. Am I missing a step? I can get to the www root directory when I navigate to the IP address, though.

  • Gravatar Kamal Nasser 10 months

    @jkhiebert DNS takes time to propagate, both of your domains are resolving for for me - please try again.

  • Gravatar Fabio Baccaglioni 10 months

    I'm another one with the same problem with example.com working and www.example.com failing, i don't understand what's wrong: ServerName domain.com ServerAlias www.domain.com *.domain.com works perfect with the domain, but no response at www. or anything *.domain.com i added in my /etc/hosts localhost domain www.domain.com but still not working of course i restarted apache every time i made a change but with no results. in the DNS admin of Digital Ocean i have only configured the domain.com, do i need some extra dns record? thanks

  • Gravatar Kamal Nasser 10 months

    @Fabio: You have to add a CNAME record for www: www CNAME @

  • Gravatar Fabio Baccaglioni 10 months

    found the solution, add a CNAME in the DNS configuration to redirect www to @

  • Gravatar neil.niekerk 10 months

    mark@Lexington:~$ sudo a2ensite example.com Enabling site example.com. To activate the new configuration, you need to run: service apache2 reload mark@Lexington:~$ service apache2 reload /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted) apache2: Syntax error on line 237 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-enabled/example.com: /etc/apache2/sites-enabled/example.com:1: was not closed. Action 'configtest' failed. The Apache error log may have more information. ...fail! I'm beyond lost.

  • Gravatar Kamal Nasser 10 months

    @neil.niekerk: what's the output of the following command? cat /etc/apache2/sites-enabled/example.com | curl -F 'sprunge= http://sprunge.us

  • Gravatar mikeneqa 9 months

    One thing to remember ( and it's been already mentioned) is to add the domain and cname in your digital ocean account under the DNS settings. The got me for a couple days.

  • Gravatar maks.rafalko 9 months

    Thank you, @thagaba Hey, if you have a problem -> always see "It works!", DISABLE default site sudo a2dissite default and then sudo service apache2 restart Please ADD THIS TO ARTICLE. I'm sorry for caps lock, but it will save hours for many people. Thank you, Maks

  • Gravatar Marshall Moore 9 months

    @maks.rafalko Yeah, totally. The docs are great, but I think this could be added. My problem was that I was seeing a directory tree when I went to my domain. It was like default was overriding my other available-sites. After I used your command (sudo a2dissite default), it worked. Thanks for adding this.

  • Gravatar psTryk 9 months

    Hi, I have a small problem with vhost. When I use phpmyadmin.mydomain.tk it opens the main page (mydomain.tk) config file: ServerAdmin [email protected] ServerName phpmyadmin.mydomain.tk ServerAlias phpmyadmin.mydomain.tk DocumentRoot /usr/share/phpmyadmin/ I also have A record in DNS setting pointing to my phpmyadmin to machine IP. Of course mydomain.tk is example...

  • Gravatar psTryk 9 months

    Please disregard. Resolved - problem was in /etc/hosts

  • Gravatar postcreative 9 months

    How do I delete a virtual host? I stupidly pasted in the line with example.com and pressed return without changing the domain name - now I have example.com and I want rid of it?

  • Gravatar Kamal Nasser 9 months

    @postcreative: Do you mean you accidentally called the file 'example.com'? You can rename it by running the following command: "mv /etc/apache2/sites-available/example.com /etc/apache2/sites-available/yourdomain.com"

  • Gravatar Julian Wiegmann 9 months

    nice guide!

  • Gravatar mattryanmay 8 months

    *FIXED ISSUE* www.domain.com would work while domain.com would serve the default server page. *FIX* run this command to disable the serving of files from /var/www sudo a2dissite default sudo service apache2 reload Now when i go to domain.com my virtual host files are served and not the default directory (i.e. /var/www/index.html) I saw this fix in a comment above and I thought that I would share it. Credit goes to "thagaba" for helping me with this. Thanks!

  • Gravatar david 8 months

    I have apache serving my WordPress site for http://mysite.com but I am having trouble getting www.mysite.com to work; it goes to 400 Bad Request (nginx). I have ServerAlias www.mysite.com in the virtual host file, I've reloaded apache2, I have the proper IP address as an A record in the DNS for www. Clearly others have had the same issue; any help with this would be appreciated.

  • Gravatar Kamal Nasser 8 months

    @david: Do you have nginx installed?

  • Gravatar mkstlouis 8 months

    Do these steps work for 12.10? I set up my droplet and got permalinks working, but I did it with a site I originally wasn't going to do first. So now I want to put my business site on my droplet and this is the only guide I found thus far.

  • Gravatar Kamal Nasser 8 months

    @mkstlouis: Yes, this article works on 12.10 as well.

  • Gravatar jesse 8 months

    Hello - Thanks for this writeup. I've got it working for both example.com and www.example.com. However, I can't seem to get a subdomain working such as test.example.com. I repeated steps 1-6 for the subdomain (while leaving off the ServerAlias). Can you give me a pointer on what I should try next?

  • Gravatar mkstlouis 8 months

    Followed everything to a T with no error message, but the test just brings me to my primary domain. Wondering what to do now.

  • Gravatar Kamal Nasser 8 months

    @mkstlouis: Did you restart apache?

    service apache2 restart
    Try clearing your browser's cache -- is it still not working?

  • Gravatar firminoata 8 months

    @mattryanmay tks man! works for me :)

  • Gravatar sefa 8 months

    http://www.ramkitech.com/2012/02/understanding-virtual-host-concept-in.html This article is very good for work with Java :)

  • Gravatar aaron 8 months

    Nice article. I want to use one user to manage multiple domains. I have created the user and added as an admin. I have one issue, when I upload new files from Dreamweaver the permissions are -rw------- instead of -rwxr-xr-x. Is there a way to set the permissions for my user to 755 for any file that is uploaded to the server by default? Thank you!

  • Gravatar Kamal Nasser 8 months

    @aaron: You can change that in Dreamweaver's settings - let me know if that works.

  • Gravatar ste.wright 8 months

    Worked an absolute treat, thanks!

  • Gravatar Joel Chu 8 months

    How about setting up automatic virtual hosting? such as /var/www/mydomain.com/html (based) --> http://mydomain.com / http://www.mydomain.com /var/www/mydomain.com/somethingelse --> http://somethingelse.mydomain.com

  • Gravatar Joel Chu 8 months

    I still have problem with setting it all up. I got the my default host working (http://the-smart.co.uk) but the alias not working www.the-smart.co.uk (so I just wait for one night) nope the next day still not working. I add several most host, reboot the machine. Some of them working (http://joelskitchen.com) and its the same the www.joelskitchen.com not working. Then my default host stop working. Its pointing back to my /var/www ... what gives?

  • Gravatar Kamal Nasser 8 months

    @Joel: Please pastebin your apache virtualhosts config.

  • Gravatar Joel Chu 8 months

    Figure that one out. I need to add the www @ in the DNS setting from the Droplet control panel. Now its working. Also worth noting is - if you have many domain names (we have over 20, but they point to only 5 different website) Use a numbering system to control the priority like 001-website1.com 002-website6.com 003-website2.com Because Apache catch those name by its order. We got some different virtual hosting like (db.websitex.com) Hope this help someone else out there.

  • Gravatar stephenwgreen 8 months

    ubuntu 12.04 & apache 2.2.22 on a really old beast of a server (that I love dearly) 2 important steps i pulled my hair out over should be in here. 1 create a 000-add-virtualhosts-map file ---this file needs to be 000 or something that puts it first (alphabetically) in the sites-available/sites-enabled category & it needs a2ensite ran to make it active for apache to read.

    NameVirtualHost *:80
        ServerName blah.com
        DocumentRoot /var/www/blah.com
        ServerName blah.blah.com
        DocumentRoot /var/www/blah.blah.com
    2 this is optional, but i a2dissite default...i am not expecting a lot of traffic & the websites/webapps i run handle if someone decides to put a /something at the end of blah.com so it was unnecessary for me to have this option. hope this helps someone

  • Gravatar Koopman7731 7 months

    Once you've setup a second virtual hosts, do you need a new DNS entry on the digital ocean dashboard pointing the second domain name? (My guess is yes, but it's not working yet, maybe it's just taking longer to propagate the changes.) Also, do serveraliases and A records conflict? Say if I setup an A record with 'www', '@' for one domain name, and have a ServerAlias www.example.com for the same domain. Is this just redundant? Thanks -Koop

  • Gravatar Kamal Nasser 7 months

    @Koopman7731: Yes, you also have to create a DNS record. Also, do serveraliases and A records conflict? Say if I setup an A record with 'www', '@' for one domain name, and have a ServerAlias www.example.com for the same domain. Is this just redundant? I'm not sure what you're referring to. DNS records only handle resolving a domain name to an IP address.

  • Gravatar benmcclanahan 7 months

    Followed the tutorial and I think I did everything correctly but may be confused on the DNS setup. I'm trying to point a subdomain that is using different nameservers on a Network Solutions DNS account. Here's what I've done: I followed the tutorial and created a virtual host with a subdomain of cloud.(domain).org. I also setup a domain record in my Digital Ocean admin area for (domain).org and entered my DO IP address. I then added an A record called "cloud" and entered my DO IP address. Then in my Network Solutions account, I created a new A record and pointed it to the DO IP address as well. Is there a step I've missed somewhere? I also tried adding the domain in Digital Ocean's DNS setup as cloud.(domain).org without creating a separate A record for cloud (the subdomain).

  • Gravatar benmcclanahan 7 months

    I can't delete my comment above but never mind. It is working, actually. It was just an issue inside our network at work that was preventing it from showing up. Everything seems to be fine outside of the building.

  • Gravatar Kamal Nasser 7 months

    @benmcclanahan: Glad to hear it's working now :]

  • Gravatar whytester 7 months

    Hi , hope someone can help. I had migrated a wordpress site onto my droplet , was working fine. Created a virtual host following the (nicely written) instructions above and site seemed to work OK ( www.somethingdoing.com ) but when i go to visit a post I get a 404 error. The admin area is strangely OK , not sure if this is a wordpress issue or if it is an issue with the config, but the site did work fine before I created the virtual host and moved the wordpress files from root to somethingdoing.com/public_html. Hoping someone can advise and it is something stupid I have done, thanks

  • Gravatar Kamal Nasser 7 months

    @whytester: Did you migrate the .htaccess file as well? You need that file for permalinks to work. Also try enabling the rewrite module:

    sudo a2enmod rewrite 
    sudo service apache2 restart

  • Gravatar whytester 7 months

    Hi Kamal Thanks for the reply, I had realized early on that the .htaccess file was missing but I had not known to change the apache config where it said AllowOveride NONE to ALL, Once the config file was corrected permalinks worked fine ( but only because I had the htaccess file added ) , cheers for the assistance.

  • Gravatar Kamal Nasser 7 months

    Sweet! Glad it's working now :]

  • Gravatar KiwoT 7 months

    Great tutorial, but I have one question. Im about to add Varnish and a few apache modules to my server like mod_rewrite, mod_evasive, and also SSL for my ( subdomain only ). Should I add those things before or after I start making Virtual Hosts for my subdomains, or it doesnt matter? Thanks!

  • Gravatar Kamal Nasser 7 months

    @KiwoT: It doesn't matter, it should work either way.

  • Gravatar sarvij10 7 months

    This was the only link that worked for me when I tried setting up Apache2! Thank you!

  • Gravatar thenewosama 6 months

    Hello, I followed these steps to create a subdomain for my domain that I own osamabox.com and I replaced every example.com with ar.osamabox.com to create my subdomain I the tried to go to the browser and go to ar.osamabox.com and www.ar.osamabox.com but no result. What did I do wrong? am I following the wrong tutorial? If so can you guide me? Thanks.

  • Gravatar casper.rock 6 months

    I'm using Ubuntu 12.10, Apache 2.4.6 now, and used to set up it on Windows. After many unsuccessful tries, it came out that where it reads "/etc/apache2/sites-available/example.com", one could be more accurate by explaining that the name of the file MUST be the name used as host name and MUST contain the extension ".conf", at least in my machine and server configuration, otherwise you will get a "ERROR: Site does not exist!". Thus "/etc/apache2/sites-available/example.com.conf" would do the job. Because the document root can be named after whatever you want (it looks like that they must have the same name, but you document root could be named "/var/www/example"). Best regards.

  • Gravatar casper.rock 6 months

    Edit: [...] you will get an "ERROR: Site does not exist!" message after running "$ a2ensite". [...] I had been stuck for too long because the document root can be named after whatever you want (it looks like that they must have the same name, but your document root could be named "/var/www/example" ou "/var/www/blablabla").

  • Gravatar Kamal Nasser 6 months

    @thenewosama: Did you add a DNS record so that ar.osamabox.com points to your droplet? Add a CNAME record with the hostname/name of ar and the value of @.

  • Gravatar Harry van der Valk 6 months

    Yes, got severall servers up and running in no-time. Oke. Now I have to put the content on the site.

  • Gravatar iesmandau 6 months

    I Switched apache from Prefork to Worker and now have no access to the virtual hosts anymore.

  • Gravatar Kamal Nasser 6 months

    @iesmandau: How did you switch to mpm-worker? Did you edit any config files?

  • Gravatar Kumar Sanjeev 6 months

    I Was using Ubuntu one click install WordPress On my ubuntu vps. After following this tutorial i did exactly now my new domain working but the old WordPress site is also redirecting to new directory i created by above method . How to fix it ?

  • Gravatar Kamal Nasser 6 months

    @Kumar: Please pastebin all of your virtualhost files.

  • Gravatar igor.agatti 6 months

    FOR PEOPLE WANTING TO SETUP A SUBDOMAIN: sudo nano /etc/apache2/httpd.conf default will be blank, write: ServerName domain.com DocumentRoot /var/www ServerName sub.domain.com DocumentRoot /var/www/sub after that, restart apache2: sudo service apache2 restart and voilá, it should work now

  • Gravatar igor.agatti 6 months

    there should be "virtualhost *;80" tags around the servername and document root on the post above

  • Gravatar stewenbusiness 6 months

    Please help me, I have this error message: Starting web server: apache2apache2: Syntax error on line 268 of /etc/apache2/apache2.conf: Syntax error on line 6 of /etc/apache2/sites-enabled/tesztszerver111.com/index.html: Expected

    but saw Action 'start' failed. Somebody? :(

  • Gravatar Kamal Nasser 6 months

    @stewenbusiness: Are you storing files in /etc/apache2/sites-enabled/tesztszerver111.com?

  • Gravatar henry.wu 5 months

    Yes its important to note that the file in sites-available should be named 'example.com.conf' as in .conf needs to be appended to any configuration file

  • Gravatar jmug.68 5 months

    Went through and created virtual host with this great article (using domain name "www.****.com). Everything works great and can see Success: You Have Set Up a Virtual Host from home network. When I try to connect from outside of home network I get nothing but connection has timed out. I have forwarded the needed ports in the router to the server. Is there something I'm missing in config of Apache?

  • Gravatar saif0909 5 months

    i getting this error on Step Four—Create the New Virtual Host File "cp: cannot stat ‘/etc/apache2/sites-available/default’: No such file or directory"

  • Gravatar Kamal Nasser 5 months

    @saif0909: Are you setting this up on a fresh new droplet? Is apache2 installed?

  • Gravatar tonysonlineorders 5 months

    Hey guys i did everything as shown here but for some reason i still get an error * Reloading web server config /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted) apache2: Could not reliably determine the server's fully qualified domain name, using for ServerName httpd not running, trying to start (13)Permission denied: make_sock: could not bind to address [::]:80 (13)Permission denied: make_sock: could not bind to address no listening sockets available, shutting down Unable to open logs Action 'graceful' failed. The Apache error log may have more information. [fail] What am i doing wrong ?

  • Gravatar Kamal Nasser 4 months

    @tonysonlineorders: You need to run that command using sudo so that it has root privileges to be able to bind to a port under 1024.

  • Gravatar suprit7 4 months

    Thank you for your great work and I appreciate. I followed and it works but i would like to know how can i made that available to whole world. I bought a domain that is www.tirpus.com and i would like to host it from my old desktop. so instead of example.com i replaced it with my dns . Please help and thank you again for the great work.

  • Gravatar screwgravityinfo 4 months

    error message: "cp: cannot stat ‘/etc/apache2/sites-available/default’: No such file or directory". Not a fresh install tho, already had one domain running from var/www root folder, now trying do devide everything in /var/www/site1 & var/www/site2 & var/www/site3 and so on. The file is not there :( only 2 files in /etc/apache2/sites-available: 000-default.conf & default-ssl.conf.what should I do? :(

  • Gravatar screwgravityinfo 4 months

    @Kamal Nasser Looks like setting-up VirtualHosts changed a little bit in Apache 2.4, the tutorial is a little bit outdated now as the process is different on a clean droplet with Ubuntu 13.10 with latests apache 2.4(.6?). http://lyemium.com/content/virtual-host-issues-when-upgrading-apache-22-24 Maybe an new tut is needed or divde between 2.2 and 2.4? :)

  • Gravatar Kamal Nasser 4 months

    @suprit7: See https://www.digitalocean.com/community/articles/how-to-set-up-a-host-name-with-digitalocean

  • Gravatar Kamal Nasser 4 months

    @screwgravityinfo: Thanks, this article is for Ubuntu 12.04, we might publish a new article for Ubuntu 13.10 soon :]

  • Gravatar suprit7 4 months

    @kamal Nasser thank you I havent tried it yet but i will take a look at it

  • Gravatar alex 4 months

    This tutorial is outdated and must be marked since it misleads those, who configuring current systems, as it already was said above. The "fix" is outdated too, and leads to many problem in the featured, since Apache 2.4 changed the filenames and add extension ".conf" everywhere . Besides, there is nothing broken, the Apache 2.4 update just add ".conf" extension to the configuration files. For those who configuring Ubuntu Apache 2.4+ (Ubuntu 13.10+) and getting an error "ERROR: Site yourdomain does not exist!" At Step Four, instead of: sudo cp /etc/apache2/sites-available/default /etc/apache2/sites-available/example.com Do this: sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf And keep in mind to use to use "000-default.conf" instead of "default", and "domain.conf" instead of "domain". If you receiving an error that file "000-default.conf" doesn't exist inside the /etc/apache2/sites-enabled directory, then just copy it from /etc/apache2/sites-available. :) To check what version of Apache is installed use the apache2 command with the v option: apache2 -v root@alex:/# apache2 -v Server version: Apache/2.4.6 (Ubuntu) Server built: Dec 5 2013 18:32:22 To find the name of the configuration file that your server mpm being used and other details about how apache configuration on your system, use the command (with "-S" or with "-S" option": $ apache2ctl -S The main configuration file, that located is located at "/etc/apache2/apache2.conf" states: # Include generic snippets of statements IncludeOptional conf-enabled/*.conf # Include the virtual host configurations: IncludeOptional sites-enabled/*.conf I was using the fix to remove the "/.conf" extension at first, and doing so brought me into a bunch of troubles, therefore, my recommendation is not fixing Apache, it's not broken, just use the right tutorial and documentation.

  • Gravatar joe.zingaro 4 months

    This tutorial worked perfectly for me, setting up my subdomains. The only thing missing (which was covered in a comment) was adding my subdomain, i.e. "subdomain.domain.com", within my Digital Ocean control panel. Might seem obvious, but it wasn't for me! Thanks for the tut.

  • Gravatar David Bielik 3 months

    I suggest adding one point to the otherwise extremely helpful tutorial: .htaccess files might not work until you enable rewrite: sudo a2enmod rewrite sudo service apache2 restart AND change in the config file: 10 11 Options Indexes FollowSymLinks MultiViews 12 AllowOverride All

  • Gravatar alexander 3 months

    what is the diff btw this and (making virtual hosts and point to your ip from the registry)

  • Gravatar alexander 3 months

    please email me the answer: [email protected] thank you.

  • Gravatar Kamal Nasser 3 months

    @alexander: What do you mean by making virtual hosts and point to your ip from the registry?

  • Gravatar romeiroe 3 months

    Hi. Do i need to create a server alias for every cname record I have?

  • Gravatar Kamal Nasser 3 months

    @romeiroe: No, you only need to add them for domains that should serve the same site, e.g. www.example.org and example.org.

  • Gravatar kbalu.web 3 months

    please help me how to re-start after virtual host..

  • Gravatar paul.alford51 3 months

    @kablu.web sudo service apache2 restart should do it.

  • Gravatar paul.alford51 3 months

    Hi, I would like to restrict access to a directory on a virtual so that only my IP address can connect. If I place the following in the config file stored under /etc/apache2/sites-available/some_virtual_host - will that block access from all IP's except my own? Order allow,deny Allow from my.ip.addy Allow from 127 Thx in advance.

  • Gravatar paul.alford51 3 months

    Damn, why did the "" go missing in the above post?

  • Gravatar paul.alford51 3 months

    OK, we can't use less than or greater than symbols in posts... Hopefully you get the idea - the directory section will list the directory I want to restrict access to followed by the above commands, followed by a close Directory statement.

  • Gravatar contato 3 months

    Hi. Thanks for the helpful article! I'm pretty new on managing a VPS. So, after following the tutorial I successfully set up a Virtual Host for another domain of mine, but now that the Virtual Host is ready to be used, how can I set up proper DNS records for this specific domain, I mean, I have 2 domain, let's say domain1.com and domain2.com and within DigitalOcean Admin Panel I've set up my custom DNS records for domain1.com, including MX records for Google Apps. Anyway, now I need to set up DNS records for domain2.com so that I can activate outlook.com hosted domain webmail service. How can I achieve that for domain2.com? or better yet, can I use DigitalOcean DNS tool to create the proper dns records for domain2.com without causing conflicts with domain1.com? Sorry for the confusion, but I'm stuck regarding this issue now. Thanks in advance.

  • Gravatar Kamal Nasser 3 months

    @paul.alford51: I believe this should work:

    Order deny,allow
    Deny from all
    Allow from your.ip.addy

  • Gravatar Kamal Nasser 3 months

    @contato: Simply add a new domain called domain2.com (see https://www.digitalocean.com/community/articles/how-to-set-up-a-host-name-with-digitalocean). Point the @ record to your droplet's IP address and you should be good to go. :]

  • Gravatar tuncaucer 3 months

    Hello, How can i change documentroot of my primary domain? Thanks

  • Gravatar Kamal Nasser 3 months

    @tuncaucer: Simply edit the DocumentRoot directive in your domain's virtualhost file and restart Apache.

  • Gravatar Derek McKercher 3 months

    Will it be the same process for Ubuntu 13.10 ?

  • Gravatar Kamal Nasser 3 months

    @Derek: It should be the same as long as you're on Apache 2.2. You can check what version is install by running

    apache2 -v

  • Gravatar hosting 3 months

    Minor issue. I did it all without issue and all seemed well, but accidentally pointed the wrong domain at my droplet (using A record and the IP of the droplet) and it was working. When I noticed my error, I changed the A records for the other domain. Now I notice both end up displaying the site. It seems that the server doesn't discriminate and allows ALL domains to be pointed at it and it'll display my singular virtual site's content. I disabled default site, but note the additional domains resolve to the default site if enabled and if not to the only virtual host. How can I add additional domains and allow only those domains to display my servers content, as I can see this being incredibly easy for someone to be malicious?

  • Gravatar hosting 3 months

    Sorry, forgot to say thanks! :D

  • Gravatar Joshua 2 months

    I'd suggest mentioning that you need to disable the default vhost, otherwise you'll have conflicts when visiting example.com vs www.example.com.

  • Gravatar Kamal Nasser 2 months

    @hosting: You can edit the default virtualhost and point its DocumentRoot to /dev/null and create virtualhosts for the domains that you want to serve (https://www.digitalocean.com/community/articles/how-to-set-up-apache-virtual-hosts-on-ubuntu-12-04-lts). This way any domains that you didn't configure apache to serve will return a 404 error.

  • Gravatar pablophg33 2 months

    Thanks for the tutorial and for keeping things simple when explaining things. It really helped me a lot, before I was doing everything in a more complex way and getting worse results.

  • Gravatar hosting 2 months

    Thanks very much @Kamal, worked perfectly, although now I've got the same problem with Nginx (I'm posting question in relevant article, so expect no response here). :)

  • Gravatar rick.bolt 2 months

    Works great!! Thanks for the information. I only do this every once in a while and always need a refresher. I have bookmarked for future access!

  • Gravatar ara.online 2 months

    Hi. Newbie here. Glad to see this thread is still getting attention. I followed your tutorial and got it to work fine but that was just a test run for what I really need to do. I need to point my virtual host at a windows partition instead of at var/www/. I can access the partition from linux but when I alter the conf files to reflect the path /media/myname/drive name/www/example I get this error message after I try to activate the host: ERROR: Site not properly enabled: /etc/apache2/sites-enabled/example.conf exists but does not point to /etc/apache2/sites-available/example.conf, not touching it Any ideas? I think this has something to do with how linux sees the partition mounting point.

  • Gravatar Kamal Nasser 2 months

    @ara.online: That looks like an issue with newer versions of Apache. What version of Ubuntu are you using? Try running the following commands:

    sudo mv /etc/apache2/sites-enabled/example.conf /etc/apache2/sites-available/example.conf
    sudo ln -s /etc/apache2/sites-available/example.conf /etc/apache2/sites-enabled/example.conf

  • Gravatar Vinoth Shankaran 2 months

    I keep getting this error when i try to save and exit error writing /etc/apache2/site-available/example.com.conf no such file or directory

  • Gravatar Kamal Nasser 2 months

    @Vinoth: Does /etc/apache2/site-available/ exist?

    stat /etc/apache2/site-available/

  • Gravatar about 1 month

    I got stuck at Step 2 where sudo mkdir -p /var/www/[my domain name]/public_html sudo: unable to resolve host [my domain name] Any ideas?

  • Gravatar david_h_mercer about 1 month

    Excellent tutorial... as always, got mine up and running the first try!! Now my question is , how do I get php working on it. I see where the question asked above in the comments but didn't see an answer.. any suggestions??

  • Gravatar Kamal Nasser about 1 month

    @david_h_mercer: It should work automatically. If it doesn't, try installing the php5 package:

    sudo apt-get install php5

  • Gravatar yifan.yang9 about 1 month

    This doesn't work for me. My domain name is yzzzd.me, according to whois, Iv already changed it to digital ocean. Then I followed this tutorial, however, yzzzd.me leads to an empty webpage. Please offer me hint. what's going on here.

  • Gravatar Kamal Nasser about 1 month

    @yifan.yang9: It works fine for me -- can you try again?

  • Gravatar nmohanan about 1 month

    I have two sites in my var/www/ folder. folder name is pro1 and pro2 both are different projects. Our admin created two urls it is pointing to the same server location. when i call pro1.example.com should got to the var/www/pro1 and pro2.example.com should go to the /var/www/pro2. how can i get both urls like this? please help me.

  • Gravatar pperry about 1 month

    Hi, I followed your tutorial but when I typed in it goes to the "it works" page, and when I type in it displays the directory tree. Only when I type in does it actually display the index.html page. What have I done wrong?

  • Gravatar pperry about 1 month

    I think I found the problem. When I type in mydomain.com with my internet turned off it works. Is there something I can do to make it work with my internet turned on?

  • Gravatar Kamal Nasser about 1 month

    @pperry: Set DocumentRoot to /path/to/mydomain/public_html

  • Gravatar Movian about 1 month

    I tried to follow this tutorial however the web page shows the contents of /var/www and not the contents of /var/www/domain.com any suggestions ?

  • Gravatar Kamal Nasser about 1 month

    @Movian: Set DocumentRoot to /var/www/domain.com instead of /var/www.

  • Gravatar arcigo1 about 1 month

    This tutorial really works? Because I'm new doing this and I read some comments about the problems they had with the Apache Server, the directory, etc.

  • Gravatar aknath.707 about 1 month

    Here is a step by step tutorial: http://wp.me/p3Po0l-hq

  • Gravatar jplew108 about 1 month

    Thanks @thagaba! OP please add his suggestion to the original article. My virtual host was misdirecting to /var/www/ instead of /var/www/example.com/public_html because of the site default. I had to run `sudo a2dissite default` then restart.

  • Gravatar kenpachi 26 days

    1 letter and 3 words I love you

  • Gravatar b_d_m_p 24 days

    Thanks for the tutorial. I do have one issue though. I can't use edit or create directories with my SFTP client. Strangely, I can create files though. Any idea how to fix this? I've looked at any relevant tutorials out there.

  • Gravatar kyiphyukhaing 15 days

    Hello! I do exactly what you write and everything is ok with commands. But when i call the created domain, it shows another site. pls help me what i continue. thanks.

  • Gravatar Kamal Nasser 14 days

    @kyiphyukhaing: Can you pastebin all of your virtualhosts? (i.e. all of the files in /etc/apache2/sites-enabled)

  • Gravatar Leon Amarant 14 days

    I am using GoDaddy as my registrar (not changing to DO) and after following these steps, www.example.com worked for me but example.com resolved to the var/www/ directory. Nothing that I did seemed to be able to fix that issue. I then found that I HAD TO set up my domain in DO (click DNS on the main DO domains screen) as example.com (not www.example.com) and then add a CNAME record for www (see http://www.anupshinde.com/posts/digitalocean-vps-custom-domain-without-nameserver-change/) I am baffled as to why I have to do this but it seems to have fixed the issue of not resolving the non www domain.

  • Gravatar b_d_m_p 11 days

    I set up two virtual hosts with this, but they both resolve to the same site. Can anyone point out my mistake? Here's my Apache config file: http://pastebin.com/1eSX2e0g Site 1 config file: http://pastie.org/private/hfuskxo0siyuz6tjawhtdw Site 2 config file: http://pastie.org/private/0djbgv0jnxkejz4dkippa Any help would be appreciated. Thanks.

  • Gravatar Kamal Nasser 11 days

    @Leon: It doesn't matter who your registrar is. It depends on whose nameservers you are using. You look like you set your domain's nameservers to DigitalOcean's, which is why you had to add the records to DigitalOcean's DNS manager.

  • Gravatar Kamal Nasser 11 days

    @b_d_m_p: Weird. Have you restarted Apache after adding the second virtual host? Also try clearing your browser's cache.

  • Gravatar b_d_m_p 11 days

    @Kamal Nasser, yes, many times and in 3 different browsers. I've been trying to solve this problem for two weeks. There has to be something wrong in the settings.

  • Gravatar jntslvdrt 9 days

    Same issue here @b_d_m_p, files and folders are just like examples here shown. But it ant got to work.

  • Gravatar jntslvdrt 9 days

    It works only if I edit default file as "my domain #1". Yes. This is it. If you rename or move somewhere else "/etc/apache2/sites-available/default" it start to work. It seems like "default" is default no matter how many others "domain files" you do have on "/etc/apache2/sites-available/" It worked fine for me untill that moment. Lets pray...

  • Gravatar Kamal Nasser 8 days

    @b_d_m_p: @jntslvdrt: What version of Apache are you running?

    apache2 -v
    If you're using version 2.4, make sure your virtualhosts' filenames end with ".conf" in /etc/apache2/sites-enabled.

Leave a Comment

Create an account or login: