Posted on Saturday, October 26th, 2013 at 3:44 pm
Reload Apache virtualhost configurations with one command instead of four.
On Ubuntu systems in order to reload a virtualhost's configuration in Apache, you have to run four commands:
$ sudo a2dissite hostname.com $ sudo service apache2 reload $ sudo a2ensite hostname.com $ sudo service apache2 reload
Since web developers will have to perform this task quite often, there's clearly a need for a faster way of handling this process. This bash script will allow issue one command to do the same as the above four commands.
#!/bin/sh RESTARTCMD="/usr/bin/sudo service apache2 reload" if [ "$1" != '' ]; then # disable site sudo a2dissite $1 # restart http daemon $RESTARTCMD # enable site sudo a2ensite $1 # restart http daemon $RESTARTCMD echo "reloaded apache site" elif [ "$1" = 'help' ] || [ "$1" = '' ]; then echo "usage:" echo "sudo resite " echo "example: to restart an apache site just run the command 'sudo resite hostname.com'" fi # eof
Place the script into a file and make that file executable:
$ chmod +x resite
You could name the file whatever you want the subsequent command to be, in my case I chose to name the command "resite". So now I can just run one command:
$ sudo resite hostname.com