This little script will allow you to either enable or disable a website running on Apache2 WebServer on debian linux.
Background
In Debian Sarge 3.1, the main configuration file for apache2 is located in /etc/apache2 and is called, surprisingly, apache2.conf . There is also the httpd.conf file for compatibility reasons.
What is interesting however, is that there is a configuration file for each site you make available in apache:
* Configuration files for virtual sites are located in the folder /etc/apache2/sites-available
* To make a site visible to the web server you make a symbolic link of its configuration file in the folder /etc/apache2/sites-enabled
(A similar scheme is also used for enabling modules)
Usage
site
The script when called with on creates the appropriate symbolic link and when called with off deletes it. It also restarts the Apache server so the changes are reflected.
Examples
site wiki on
Will enable site named wiki. The configuration file wiki must exist in /etc/apache2/sites-available
site wiki off
Will disable site named wiki. The configuration file wiki must exist in /etc/apache2/sites-enabled
The script will report whenever it cannot find the appropriate configuration file. It will also report when an attempt is made to enable an already enabled site or disable an already disabled or non-existent site.
site wiki status
This will report whether the site name wiki is enabled or disabled
Script
Save the following script with the name site to an appropriate place, e.g. /sbin or /usr/sbin. Super user rights are required for execution, since the script restarts Apache after an on or off command. (status may be run by normal user). I suggest you run it with sudo and possibly make it available for users that may need to turn on or off their website.
#!/bin/sh
# site name {on | off | status }
# e.g. site mysite on -> activate mysite
# Control any site
# requires sudo or root privelege when used
# with on or off switches (reloads apache)
#
# (C) by CyberToxic pigi apo Manolis Kiagias
#
if [ ! -f /etc/apache2/sites-available/$1 ]; then
echo "Site does not exist!"
exit 1
fi
case "$2" in
on)
echo "Enabling $1 site..."
if [ -f /etc/apache2/sites-enabled/$1 ]; then
echo "Already enabled!"
else
ln -s /etc/apache2/sites-available/$1 /etc/apache2/sites-enabled/$1
/etc/init.d/apache2 restart
echo "done!"
fi
;;
off)
echo "Disabling $1 site..."
if [ -f /etc/apache2/sites-enabled/$1 ]; then
rm /etc/apache2/sites-enabled/$1
/etc/init.d/apache2 restart
echo "done!"
else
echo "Already disabled!"
fi
;;
status)
echo -n "Current status of $1 site: "
if [ -f /etc/apache2/sites-enabled/$1 ]; then
echo "ENABLED"
else
echo "DISABLED"
fi
;;
*)
echo "Usage: /usr/sbin/site name {on|off|status}"
exit 1
;;
esac
exit 0
Assumptions
The script assumes the following:
* Your distribution is using the Apache configuration scheme described above. This is true for Debian 3.1 and may be true for other distros / versions as well.
* You have su privileges. You need to either sudo or su to execute this script (unless using the status option).
* You do really understand what you are doing! (This is a prerequisite for ALL my scripts...)
Retrieved from "http://debian12.dyndns.org/index.php/Debian:Apache_Sites"
Views
* Project page
* Discussion
* View source
* History
Personal tools
* Log in / create account
Debian Content
* Useful scripts
* Tutorials
* Workarounds
* Quick Tips
Navigation
* Main Page
* Community portal
* Current events
* Recent changes
* Random page
* Help
* Donations
Search
Toolbox
* What links here
* Related changes
* Upload file
* Special pages
* Printable version
* Permanent link
Powered by MediaWiki
* This page was last modified 19:50, 25 July 2006.
* This page has been accessed 213 times.
* Privacy policy
* About Debian