title: Setting up a subdomain with Apache on Linux
body: <p>I can't believe that I haven't done this before, but I would like a definitive answer so I'm all set going forward.</p>
  
  <p>I have an apache config file at <code>/etc/apache2/sites-available/mysite</code> which looks like this:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      ServerAdmin webmaster@localhost
  
      DocumentRoot /home/sam/public_html
      &lt;Directory /&gt;
              Options FollowSymLinks
              AllowOverride All
      &lt;/Directory&gt;
      &lt;Directory /home/sam/public_html&gt;
              Options Indexes FollowSymLinks MultiViews
              AllowOverride All
              Order allow,deny
              allow from all
      &lt;/Directory&gt;
  
      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
      &lt;Directory "/usr/lib/cgi-bin"&gt;
              Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
              Order allow,deny
              Allow from all
      &lt;/Directory&gt;
  
      ErrorLog ${APACHE_LOG_DIR}/error.log
  
      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel warn
  
      CustomLog ${APACHE_LOG_DIR}/access.log combined
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>So this serves html and php files from <code>~/public_html</code> all fine. But I have multiple projects there so would like to start using subdomains. What I want to do is serve files from <code>~/public_html/myproject/</code> as the root directory for <code>myproject.localhost</code>.</p>
  
  <p>I have tried adding the following to the bottom of my apache file:</p>
  
  <pre><code>&lt;VirtualHost myproject.localhost&gt;
      DocumentRoot ~/public_html/myproject/
      ServerName myproject.localhost
      ServerAdmin admin@myproject.localhost
      &lt;Directory ~/public_html/myproject&gt;
              Options Indexes FollowSymLinks
              AllowOverride FileInfo
              Order allow,deny
              Allow from all
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>but apache complains:</p>
  
  <pre><code>Restarting web server: apache2[Tue Aug 20 11:06:19 2013] [error] (EAI 2)Name or service not known: Could not resolve host name myproject.localhost -- ignoring!
   ... waiting [Tue Aug 20 11:06:20 2013] [error] (EAI 2)Name or service not known: Could not resolve host name myproject.localhost -- ignoring!
  </code></pre>
  
  <p>I know I'm committing a fundamental error, but I'm not sure what it is. </p>
  
  <h2>Edit</h2>
  
  <p>This is my complete file now:</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
      DocumentRoot /home/sam/public_html/ryua1226-magento/
      ServerName mydomain.localhost
      ServerAdmin admin@mydomain.localhost
      &lt;Directory /home/sam/public_html/ryua1226-magento&gt;
              Options Indexes FollowSymLinks
              AllowOverride FileInfo
              Order allow,deny
              Allow from all
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  
  
  &lt;VirtualHost *:80&gt;
      ServerAdmin webmaster@localhost
  
      DocumentRoot /home/sam/public_html
      &lt;Directory /&gt;
              Options FollowSymLinks
              AllowOverride All
      &lt;/Directory&gt;
      &lt;Directory /home/sam/public_html&gt;
              Options Indexes FollowSymLinks MultiViews
              AllowOverride All
              Order allow,deny
              allow from all
      &lt;/Directory&gt;
  
      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
      &lt;Directory "/usr/lib/cgi-bin"&gt;
              Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
              Order allow,deny
              Allow from all
      &lt;/Directory&gt;
  
      ErrorLog ${APACHE_LOG_DIR}/error.log
  
      # Possible values include: debug, info, notice, warn, error, crit,
      # alert, emerg.
      LogLevel warn
  
      CustomLog ${APACHE_LOG_DIR}/access.log combined
  &lt;/VirtualHost&gt; 
  </code></pre>