Enable / disable Apache config file-basic config / module config / site config

In Apache of Ubunut, there is a command to enable / disable the configuration file by a command.

The location of the Apache configuration file is "/ etc / apache2".

See the directory structure of Apache's configuration files. Only the ones related to the configuration file are displayed.

-rw-r--r-- 1 root root 7224 Mar 13 21:26 apache2.conf
drwxr-xr-x 2 root root 4096 Jun 8 15:37 conf-available
drwxr-xr-x 2 root root 4096 Jun 8 15:37 conf-enabled
drwxr-xr-x 2 root root 12288 Jun 8 15:21 mods-available
drwxr-xr-x 2 root root 4096 Jun 8 16:07 mods-enabled
-rw-r--r-- 1 root root 320 Jul 17 2019 ports.conf
drwxr-xr-x 2 root root 4096 May 26 14:59 sites-available
drwxr-xr-x 2 root root 4096 May 26 14:59 sites-enabled

Those that start with conf are general settings, those that start with mods are Apache module settings, and those that start with sites are virtual host settings for running multiple sites.

Apache configuration file to enable

The following are valid as Apache configuration files. One of the following must be true for the setting to take effect: The configuration file stored in available will not be valid as it is.

# / etc / apache2 /
# |-apache2.conf
# | `--ports.conf
# |-mods-enabled
# | |-*. Load
# | `-* .Conf
# |-conf-enabled
# | `-* .Conf
# `--sites-enabled
# `-* .Conf

General configuration file

First of all, you'll want to write your new config file in apache2.conf, but it's a good idea to leave this as the default.

Create the new configuration file you create in "conf-available". Let's place it with the name "myapache2.conf". Create a new one with the vi command.

sudo vi conf-available/myapache2.conf

Please save and exit.

Enable common Apache config files in a2enconf

Then enable this configuration file with the a2enconf command.

sudo a2enconf myapache2

Take a look inside "conf-enabled" with the ls command.

ls -l conf-enabled

Then symbolic link is created for "conf-available / myapache2.conf" I understand.

myapache2.conf->../conf-available/myapache2.conf

The Apache configuration file you created is now valid.

After enabling it, you need to restart Apache for Apache to reflect your settings.

Disable common Apache config files with a2disconf

To disable it, use the a2disconf command.

sudo a2disconf myapache2

After disabling it, you will need to restart Apache for the settings to take effect.

Module configuration file

Some Apache modules are available but not enabled. The settings for such modules are in "mods-available".

Enable Apache module configuration file with a2enmod

Use the a2enmod command to enable the Apache module configuration file. Try enabling the ssl module (mod_ssl).

sudo a2enmod ssl

A symbolic link will be created in "mods-enabled". Apache needs to be restarted for the settings to take effect.

Disable Apache module configuration file with a2dismod

To disable the Apache module configuration file, use the a2dismod command.

sudo a2dismod ssl

After disabling it, you need to restart Apache for the settings to take effect.

Virtual host configuration file for running multiple sites

Ubuntu provides a "sites-available" directory for running multiple sites on a virtual host.

First, when writing a new virtual host setting, store the setting file in "sites-available".

Make the domain name of the site the name of the configuration file. The extension is ".conf".

vi www.mysite.example.conf

Let's write the virtual host settings in this.

Enable virtual host config file on a2ensite

Use the a2ensite command to enable the virtual host configuration file. Try enabling the ssl module (mod_ssl).

sudo a2ensite www.mysite.example

A symbolic link will be created in "sites-enabled". Apache needs to be restarted for the settings to take effect.

Disable virtual host config file with a2dissite

To disable the virtual host configuration file, use the a2dissite command.

sudo a2dissite www.mysite.example

After disabling it, you need to restart Apache for the settings to take effect.

Associated Information