Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

here is an issue there related to my dev server configuration (Ubuntu Server with LAMP installed)

I have a subdomain which is pointing to my server something like http://sudomain.domain.com.

Now I need to make some subdomains on my server each domain to point to a separate folder on the server /var/www/proj1 should be loaded by accessing http://proj1.subdomain.domain.com, http://proj2.subdomain.domain.com

Can anyone help me fix this issue? Any help will be appreciate.

share|improve this question
add comment

migrated from stackoverflow.com May 13 '11 at 1:02

This question came from our site for professional and enthusiast programmers.

1 Answer

What you'll need is the Apache VirtualHost directive. See the Apache Documentation and some Examples.

Basically what you want to do in Ubuntu is to make sure, that the port you want to use (usually :80) is enabled in /etc/apache2/ports.conf like this:

NameVirtualHost *:80
Listen 80

Next you'll have to create a new conf-file in /etc/apache2/sites-available. I'd suggest to name it proj1.conf or proj1.mydomain.conf.

There you can configure the VirtualHost as follows:

<VirtualHost *:80>
  ServerName proj1.subdomain.domain.com
  DocumentRoot /var/www/proj1
  ServerAdmin name@domain.com

  # Write a seperate log per Virtualhost
  CustomLog /var/log/apache2/proj1.subdomain.access_log combined
  ErrorLog /var/log/apache2/proj1.subdomain.error_log

  # Maybe you want to put some restrictions on the directory
  <Directory /var/www/proj1>
    Options -Indexes +FollowSymLinks + Includes
    AllowOverride All
    # Restrict Access to certain IP's
    Order Deny,Allow
    Deny from All
    Allow from 127.0.0.1 IP IP IP
    Satisfy ALL
  </Directory>
</VirtualHost>

Consult the Apache Manual to see what you could do with the Directive.

To enable this Site, link it to /etc/apache2/sites-enabled

ln -s /etc/apache2/sites-available/proj1.conf /etc/apache2/sites-enabled/proj1

Now all you have to do is make sure your config is valid and then restart Apache:

apache2ctl configtest && /etc/init.d/apache2 restart

Naturally you will have to set up the subdomain in your DNS in a way that it points to this server.

share|improve this answer
add comment

Your Answer

 
discard

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