How to use a2ensite and a2dissite with rpm based apache systems
One thing this author prefers, it is the Debian (apt-get) style use of a2ensite and a2dissite to enable and disable hosted domains. This guide will show you how to set up a similar system in rpm based (Redhat, Fedora, CentOS, etc) systems.
Set up instructions
To setup a similar system on your rpm based server, simply follow the steps outlined below.
Create the folder structure
As root, run the following commands:
mkdir /etc/httpd/sites-available mkdir /etc/httpd/sites-enabled
Edit httpd.conf
The first step is to include the sites-enabled folder in your httpd.conf file.
nano /etc/httpd/conf/httpd.conf
Now add the following line at the bottom of the file and save the file.
Include sites-enabled/*.*
Restart apache to use the new setting
service httpd restart
Create the a2ensite and a2dissite commands
Create the following files and add the content displayed.
a2ensite
nano /usr/local/bin/a2ensite
#! /bin/bash # bash script to use debian style vhosts # vhost file must be in /etc/httpd/sites-available # script will make a softlink to /etc/httpd/site-enabled # and restart httpd # use a2dissite to remove the link AVAILABLE="/etc/httpd/sites-available" ENABLED="/etc/httpd/sites-enabled" FILE="$1" if [ -f $AVAILABLE/$FILE ] then if [ -s $AVAILABLE/$FILE ] then ln -s $AVAILABLE/$FILE $ENABLED/$FILE service httpd restart else echo "File $FILE is empty. No action taken" fi else echo "File $FILE does not exist. No action taken" fi
a2dissite
nano /usr/local/bin/a2dissite
#! /bin/bash # bash script to use debian style vhosts # vhost file must be in /etc/httpd/sites-available # script will delete a softlink from /etc/httpd/site-enabled # and restart httpd # use a2ensite to restore the link AVAILABLE="/etc/httpd/sites-available" ENABLED="/etc/httpd/sites-enabled" FILE="$1" if [ -f $ENABLED/$FILE ] then rm -f $ENABLED/$FILE service httpd restart else echo "File $FILE does not exist. No action taken" fi
Set the files as executable
chmod 744 /usr/local/bin/a2ensite chmod 744 /usr/local/bin/a2dissite
How to use
The examples below assume you named the domain virtual configuration files after the domain name.
Create the virtual host configuration file
This can be used as a very basic, yet functioning virtual host configuration file:
nano /etc/httpd/sites-available/domain.com
<VirtualHost *:80> ServerAdmin admin@domain.com ServerName domain.com ServerAlias www.domain.com DocumentRoot /var/www/vhosts/domain.com/httpdocs/ ErrorLog /var/www/vhosts/log/error_log TransferLog /var/www/vhosts/log/access_log LogLevel warn </VirtualHost>
Enable a site
a2ensite domain.com
Disable a site
a2dissite domain.com
Comments
So empty here ... leave a comment!