Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure subdomains for Apache2 on Ubuntu?

I followed these instructions to configure subdomains for apache. I can access the subdomain using http://localhost/test though I cannot access it via http://test.localhost. How can I realize the latter?

# /etc/apache2/sites-available/test.localhost
<VirtualHost *:80>

    # Server name
    ServerName test.localhost

    # Document root
    DocumentRoot /var/www/test/

    # Custom log file locations
    ErrorLog  /var/www/test/logs/error.log
    CustomLog /var/www/test/logs/access.log combined

</VirtualHost>
like image 331
JJD Avatar asked Jul 26 '11 21:07

JJD


2 Answers

As Mark B already answered correctly the problem was a misconfiguration in /etc/hosts. The correct configuration is:

# /etc/hosts
127.0.0.1     test.localhost
like image 95
JJD Avatar answered Oct 27 '22 07:10

JJD


The blog post you linked to (from my blog) instructs to set up a new VirtualHost element with an ip of 127.0.0.2 so you can create multiple subdomains easily.

You're setup using 127.0.0.1 will work great for one subdomain, but if you plan on adding more, I'd suggest setting up the new VirtualHost elements as described in the post.

like image 25
steveklbnf Avatar answered Oct 27 '22 05:10

steveklbnf