15

I'm logged into a Linux server. I think it's a Red Hat distribution.

The commands a2ensite and a2dissite are not available. In the /etc/httpd directory, I don't see any mention of sites-enabled or sites-available.

I'm pretty sure the site is currently executing the directives of /etc/httpd/conf.d/ssl.conf . I would like to do a a2dissite ssl, then reload the Web Server. How to do achieve this ?

Abhijeet Kasurde
  • 985
  • 9
  • 20
John
  • 7,153
  • 22
  • 61
  • 86

2 Answers2

30

a2ensite etc. are commands available in Debian-based systems and that are not available in RH-based distributions.

What they do is to manage symbolic links from configuration file parts in /etc/apache2/sites-available and mods-available to /etc/apache2/sites-enabled and so on. E.g. if you have a vhost defined in a config file /etc/apache2/sites-avaible/example.com, a2ensite example.com would create a symlink to this file in /etc/apache2/sites-enabled and reload the apache config. The main Apache config file contains lines that include every file in /etc/apache2/sites-enabled and thus, they get incorporated into the runtime config.

It's quite easy to mimic this structure in RHEL. Add two directories in /etc/httpd/ named sites-enabled and sites-available and add your vhosts into files in sites-available. After that, add a line

include ../sites-enabled 

to /etc/httpd/conf/httpd.conf. You can now create symlinks to sites-enabled and then reload the config with service httpd reload or apachectl.

Sven
  • 97,248
  • 13
  • 177
  • 225
  • 1
    Ahh i see. So basically /etc/httpd/conf.d is acting at as the equivalent of sites-enabled. So just removing ssl.conf from that directory and restarting/reloading httpd picked up my changes. That's cool – John Oct 23 '13 at 23:31
3

As an add-on to Sven's excellent answer, two scripts that mimic the behaviour of a2ensite and a2dissite. The original ensite.sh can be found on Github

a2ensite.sh

#!bin/bash
# Enable a site, just like the a2ensite command.

SITES_AVAILABLE_CONFIG_DIR="/etc/httpd/sites-available";
SITES_ENABLED_CONFIG_DIR="/etc/httpd/sites-enabled";

if [ $1 ]; then
  if [ -f "${SITES_ENABLED_CONFIG_DIR}/${1}" ]; then
    echo "Site ${1} was already enabled!";
  elif [ ! -w $SITES_ENABLED_CONFIG_DIR ]; then
    echo "You don't have permission to do this. Try to run the command as root."
  elif [ -f "${SITES_AVAILABLE_CONFIG_DIR}/${1}" ]; then
    echo "Enabling site ${1}...";
    ln -s $SITES_AVAILABLE_CONFIG_DIR/$1 $SITES_ENABLED_CONFIG_DIR/$1
    echo "done!"
 else
   echo "Site not found!"
fi
else
  echo "Please, inform the name of the site to be enabled."
fi


a2dissite.sh

#!bin/bash
# Disable a site, just like a2dissite command, from Apache2.

SITES_AVAILABLE_CONFIG_DIR="/etc/httpd/sites-available";
SITES_ENABLED_CONFIG_DIR="/etc/httpd/sites-enabled";

if [ $1 ]; then
  if [ ! -f "${SITES_ENABLED_CONFIG_DIR}/${1}" ]; then
    echo "Site ${1} was already disabled!";
  elif [ ! -w $SITES_ENABLED_CONFIG_DIR ]; then
    echo "You don't have permission to do this. Try to run the command as root."
  elif [ -f "${SITES_AVAILABLE_CONFIG_DIR}/${1}" ]; then
    echo "Disabling site ${1}...";
    unlink $SITES_ENABLED_CONFIG_DIR/$1
    echo "done!"
  else
    echo "Site not found!"
  fi
else
  echo "Please, inform the name of the site to be enabled."
fi