Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I just updated from Ubuntu 8.04 to the newest version and all of a sudden my virtual hosts don't work anymore. I'm not sure what changed, but I know when I type in localhost it doesn't go to the directory that I would expect (probably the default /var/www/ but that's not where I keep my projects) and typing in the name of one of my virtual hosts takes me to the same place. How do I get it working again?

share|improve this question
add comment

4 Answers

Turns out the update sort of reset things back to default. Here's what I did to get it to work (This worked for me on Ubuntu 9.10 Karmic Koala):

  1. The localhost directory was set to /var/www so to change that you will need to edit the default virtual host config file in /etc/apache2/sites-available. Make sure to change both the DocumentRoot and <Directory > values.

    sudo nano /etc/apache2/sites-available/default
    
  2. To create a virtual host, create a file in /etc/apache2/sites-available

    sudo nano /etc/apache2/sites-available/mysite
    

    Here's an example of what you should put in the virtual host file:

    <VirtualHost *:80>
        ServerName myvirtualhostname
        ErrorLog /var/log/apache2/myvirtualhostname-error.log
        CustomLog /var/log/apache2/myvirtualhostname-access.log combined
        DocumentRoot /home/name/Projects/myvirtualhostname/public
        <Directory /home/name/Projects/myvirtualhostname/public>
            Options FollowSymLinks
         AllowOverride All
        </Directory>
    </VirtualHost>
    
  3. Next you will want to enable your virtual host. You can do so by running the "Apache 2 Enable Site" command with the name of the file you created in sites-available:

    sudo a2ensite mysite
    
  4. You may also need to add your virtual host name to your /etc/hosts file.

  5. Now restart Apache for it to take affect:

    sudo /etc/init.d/apache2 restart
    

Bonus! If you want to get rid of that message that says "Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName" you can create a config file in /etc/apache2/conf.d/ called fqdn with the value of ServerName localhost. You can do this in a single command like this:

echo "ServerName localhost" | sudo tee /etc/apache2/conf.d/fqdn

For more information, check out setting up Apache, PHP, and MySQL on Ubuntu.

share|improve this answer
add comment

You may have added your virtual hosts to /etc/apache2/httpd.conf or something like this, and the file was overwritten on update (you were prompted!). Check if you still have your virtual hosts in /etc/apache2/sites-available (one host per file) and that have valid resolvable symlinks in /etc/apache2/sites-enabled: this is the right way to add them in Ubuntu (I believe, in all Unix systems that's common: a great idea to have them separate rather than piling in a single file!).

share|improve this answer
add comment

This could be DNS related as well.

So what does it say when you say specifically http://localhost%3A//

share|improve this answer
add comment

I don't have an Ubuntu-specific answer for you, but you just need to check your httpd.conf for the DocumentRoot and set it as needed. Unless your vhost configs got wiped, then you'd need to recreate them.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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