a2ensite 'Site: ___ does not exist' error, even with .conf file
apache, shell, ubuntu-14.04, vhosts
Solution
The answer, in short, is that `a2ensite` just wants the name of the site.conf and not the whole path to the file.
So `sudo a2ensite example-com-80.conf`
I found this in an earlier answer by @raina77ow.
Problem
System: Ubuntu 14.04 LAMP running on Parallels VM set up with Vagrant I'm writing my first non-trivial shell script to add new web projects to a dev VM on my Mac laptop. - Create a default folder structure in /var/www/ - Add a .conf vhost file to /etc/apache2/sites-available with the new domain replacing placeholders via sed - Enable the new site and restart apache 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/ I test for its existence and even print a debug listing: `ls -al /etc/apache2/sites-available/ | grep $CONFFILE` before attempting to enable the site. 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. Can anyone point me in the right direction? I haven't been able to find other postings with this particular problem. My feeling is that I've got an error in my `$CONFFILE` variable expansion in the `a2ensite` command because the error does not show the .conf extension even though the directory listing does: `ERROR: Site /etc/apache2/sites-available/example-com-80 does not exist!` Edit: After running a2ensite from the command line per Micheal's suggestion below, it seemed to parse fine, but still doesn't show the extension: ``` $ sudo a2ensite example-com-80.conf Enabling site example-com-80. To activate the new configuration, you need to run: service apache2 reload ``` End Edit Edit: Found answer After searching with broader terms, `a2ensite` instead of Ubuntu 14.04 Vagrant etc, I found a two year old question where @raina77ow points out that `a2ensite` just wants the site name, not the whole path. Changing `sudo a2ensite /etc/apache2/sites-available/$CONFFILE` to `sudo a2ensite $CONFFILE` makes the script work as intended. This also explains why my previous attempts to run `a2ensite` from the command line failed; I was running it from inside /var/www/templates/ and passing in the whole path to the .conf file. Now, a stackoverflow question, how best should I indicate this is the solution with the limited reputation that I have? And give credit properly? See edit above for solution Console output with example.com: ``` $ ./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! ``` newvhost script: ``` 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" && "$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 ``` Thanks, Any other suggestions for improving the script are very welcome as long as that doesn't run afoul with the terms of StackOverflow.