System: Ubuntu 14.04 LAMP running on Parallels VM configured with Vagrant
I am writing my first non-trivial shell script to add new web projects to a virtual machine on my Mac laptop.
- Create default folder structure in / var / www /
- Add a .conf vhost file to / etc / apache 2 / sites - available with a new domain replacing placeholders with sed
- Turn on the new site and restart apache
I have folders and files, and sed seems happy by setting up my index.html and .conf vhost files, but a2ensite doesn't seem to see the .conf file in / etc / apache 2 / sites-available /
I test its existence and even print out a debug list: ls -al /etc/apache2/sites-available/ | grep $CONFFILE ls -al /etc/apache2/sites-available/ | grep $CONFFILE before trying to enable the site.
I read here and elsewhere about the importance of the .conf extension with Ubuntu 13 (or 14), which seems to be a very common problem. My vhost file has a .conf extension, so this seems like another problem.
Can someone point me in the right direction? I could not find other posts with this particular problem.
I feel like I have an error in my $CONFFILE variable $CONFFILE in the a2ensite command, because the error does not show the .conf extension, even if the directory listing is:
ERROR: Site /etc/apache2/sites-available/example-com-80 does not exist!
Edit:
After running a2ensite from the command line at the suggestion of Micheal below, he seemed to be well versed, but still didn'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
Edit end
Edit: found answer
After searching with broader terms a2ensite instead of Ubuntu 14.04 Vagrant, etc., I found a two-year question where @ raina77ow indicates that a2ensite just wants the site name, not the whole path. Changing sudo a2ensite /etc/apache2/sites-available/$CONFFILE to sudo a2ensite $CONFFILE does the script work as intended. This also explains why my previous attempts to start a2ensite from the command line failed; I ran it from within / var / www / templates / and passed the entire path to the .conf file.
Now, the stackoverflow question, what is the best way to point out this limited reputation solution that I have? And give a loan properly?
See edit above for solution.
Console output with .com example:
$ ./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
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
Thanks,
Any other suggestions for improving the script are very welcome if it does not contradict the conditions of StackOverflow.