title: a2ensite 'Site: ___ does not exist' error, even with .conf file
body: <p><strong>System:</strong> Ubuntu 14.04 LAMP running on Parallels VM set up with Vagrant</p>
  
  <p>I'm writing my first non-trivial shell script to add new web projects to a dev VM on my Mac laptop.</p>
  
  <ol>
  <li>Create a default folder structure in /var/www/</li>
  <li>Add a .conf vhost file to /etc/apache2/sites-available with the new domain replacing placeholders via sed</li>
  <li>Enable the new site and restart apache</li>
  </ol>
  
  <p>I've got the folders and files copying over and sed seems happy customizing my index.html and .conf vhost file, but a2ensite doesn't seem to see the .conf file in /etc/apache2/sites-available/ </p>
  
  <p>I test for its existence and even print a debug listing: <code>ls -al /etc/apache2/sites-available/ | grep $CONFFILE</code> before attempting to enable the site.</p>
  
  <p>I've read here and elsewhere about the importance of having the .conf extension since Ubuntu 13 (or 14) which seems to be a very common issue. My vhost file has the .conf extension so this seems like a different issue.</p>
  
  <p>Can anyone point me in the right direction? I haven't been able to find other postings with this particular problem.</p>
  
  <p>My feeling is that I've got an error in my <code>$CONFFILE</code> variable expansion in the <code>a2ensite</code> command because the error does not show the .conf extension even though the directory listing does:</p>
  
  <p><code>ERROR: Site /etc/apache2/sites-available/example-com-80 does not exist!</code></p>
  
  <p><strong>Edit:</strong> </p>
  
  <p>After running a2ensite from the command line per Micheal's suggestion below, it seemed to parse fine, but still doesn't show the extension:</p>
  
  <pre><code>$ sudo a2ensite example-com-80.conf
  Enabling site example-com-80.
  To activate the new configuration, you need to run:
    service apache2 reload
  </code></pre>
  
  <p><strong>End Edit</strong></p>
  
  <p><strong>Edit: Found answer</strong></p>
  
  <p>After searching with broader terms, <code>a2ensite</code> instead of Ubuntu 14.04 Vagrant etc, I found <a href="https://stackoverflow.com/questions/13035385/a2ensite-from-script-path" title="a two year old question">a two year old question</a> where @raina77ow points out that <code>a2ensite</code> just wants the site name, not the whole path. Changing <code>sudo a2ensite /etc/apache2/sites-available/$CONFFILE</code> to <code>sudo a2ensite $CONFFILE</code>
  makes the script work as intended. This also explains why my previous attempts to run <code>a2ensite</code> from the command line failed; I was running it from inside /var/www/templates/ and passing in the whole path to the .conf file. </p>
  
  <p>Now, a stackoverflow question, how best should I indicate this is the solution with the limited reputation that I have? And give credit properly?</p>
  
  <p><strong>See edit above for solution</strong></p>
  
  <p>Console output with example.com:</p>
  
  <pre><code>$ ./newvhost
  New Server Name with Top Level Domain: example.com
  Validating: example.com
  New DocumentRoot created: /var/www/example
  Copying template structure
  Creating: example-com-80.conf
  -rw-r--r--  1 root root  811 Feb 17 15:11 example-com-80.conf
  Enabling site
  ERROR: Site /etc/apache2/sites-available/example-com-80 does not exist!
  </code></pre>
  
  <p>newvhost script:</p>
  
  <pre><code>OLDIFS=$IFS
  IFS="."
  printf "New Server Name with Top Level Domain: "
  read NEW_SUBDOMAIN NEW_TLD
  IFS=$OLDIFS
  
  NEW_FULL_NAME="$NEW_SUBDOMAIN.$NEW_TLD"
  
  echo "Validating: $NEW_FULL_NAME"
  
  if [[ "$NEW_TLD" != "com" &amp;&amp; "$NEW_TLD" != "dev" ]] ; then
    echo -e "\E[31;1mTLD must be com or dev! \033[0m" 
    exit 1
  fi
  
  
  if [ -d "/var/www/$NEW_SUBDOMAIN" ]; then
    echo -e "\E[31;1mRoot directory /var/www/$NEW_SUBDOMAIN already exists!\033[0m"
    exit 1
  fi
  
  mkdir /var/www/$NEW_SUBDOMAIN
  
  if [ -d "/var/www/$NEW_SUBDOMAIN" ]; then
      echo "New DocumentRoot created: /var/www/$NEW_SUBDOMAIN"
  else  
    echo -e "\E[31;1mUnable to make directory\033[0m"
    exit 1
  fi
  
  echo "Copying template structure"
  
  cp /var/www/templates/structure/. /var/www/$NEW_SUBDOMAIN/ -R
  
  sed -i "s/TEMPLATE/$NEW_FULL_NAME/g" /var/www/$NEW_SUBDOMAIN/index.html
  
  CONFFILE="$NEW_SUBDOMAIN-$NEW_TLD-80.conf"
  
  echo "Creating: $CONFFILE"
  
  sudo cp /var/www/templates/vhost_template.conf /etc/apache2/sites-available/$CONFFILE
  
  sudo sed -i "s/FULLNAME/$NEW_FULL_NAME/g" /etc/apache2/sites-available/$CONFFILE
  sudo sed -i "s/DOMAINNAME/$NEW_SUBDOMAIN/g" /etc/apache2/sites-available/$CONFFILE
  
  if [ -e "/etc/apache2/sites-available/$CONFFILE" ]; then
    ls -al /etc/apache2/sites-available/ | grep $CONFFILE # DEGBUG Listing to  doubly confirm $CONFFILE exists
    echo "Enabling site"
    sudo a2ensite /etc/apache2/sites-available/$CONFFILE
    sudo apache2ctl graceful
  fi
  </code></pre>
  
  <p>Thanks,</p>
  
  <p>Any other suggestions for improving the script are very welcome as long as that doesn't run afoul with the terms of StackOverflow.</p>