Activate, deactivate and remove Apache websites and configurations. This is how it works.
Display the configurations
Let’s start by displaying the virtual hosts, or the configurations, which are set up. These are located in the folder “
/etc/apache2/sites-available/“. These configurations are available, but not necessarily active.
The active configurations are located in the folder “
/etc/apache2/sites-enabled/“, whereby “located” is the wrong word. Here, links are created in the file system to the configuration in the folder “
sites-available“. Thus, virtual hosts can be activated or deactivated without removing the actual configuration.
Enable site / Enable configuration
The activation of a configuration is done with the command “
a2ensite“. It is possible that there are multiple configurations for a virtual host. In our example, there are two files, one with the normal “http” configuration and one with “https”.
First we change to the configuration folder with “
a2ensite server.andydunkel.net.conf a2ensite server.andydunkel.net-le-ssl.conf
After executing the command, with sudo rights, the configuration is activated.
Disable site / disable configuration
For deactivation, there is the command “
a2dissite” The operation is analogous.
a2dissite server.andydunkel.net.conf a2dissite server.andydunkel.net-le-ssl.conf
The configuration is not immediately active, as the output of the command already suggests. To do this, we use one of the following commands to re-read the configuration and restart the web server.
sudo systemctl reload apache2 sudo systemctl restart apache2 sudo service apache2 restart
To completely remove a configuration, we first disable it. Then we delete the configuration file.
cd /etc/apache2/sites-available rm server.andydunkel.net.conf rm server.andydunkel.net-le-ssl.conf