Apache web server allows you to host multiple websites & domains on a single server instance. However, sometimes you may need to temporarily disable one or more of the sites, in case it develops problems. In this article, we will look at how to disable configuration file in Apache.
How to Disable Configuration File in Apache
The configuration file for all websites & domains hosted on your Apache server are located at /etc/apache2/sites-available, one configuration file for each site. On the other hand, global configuration files applicable for all virtual hosts are located at /etc/apache2/conf-enabled. Here is an example of site-available folder that hosts 3 domains example1.com, example2.com and example3.com
/etc/apache2/sites-available example1.com.conf example2.com.conf example3.com.conf
You can easily disable a configuration file by disabling the site it is configured for, using a2dissite command. Here is its syntax
a2dissite <sitename>
Here is an example to disable configuration file for example1.com. You need to mention the configuration file name without the .conf extension
$ sudo a2dissite example1.com
If the above command doesn’t work for you, or gives errors, then try mentioning the full file name of your configuration file.
$ sudo a2dissite example1.com.conf
In both the above commands, Apache will only disable the virtual host for example1.com.
If you want to disable the default virtual host, run the following command.
$ sudo a2dissite 000-default.conf
Restart Apache server to apply changes
$ sudo service apache2 restart OR $ sudo systemctl restart apache2
On the other hand, if you want to enable configuration file, you need to use a2enmod command.
a2ensite <sitename>
Example,
$ sudo a2ensite example2.com
Please note, all the above commands are applicable for specific virtual hosts only. Apart from these, there are global configuration file in /etc/apache2/conf-enabled whose configuration settings are applicable for all virtual hosts. If you want to disable any configuration file in this folder, then you need to use a2disconf command. Let us say you have test.conf file in /etc/apache2/conf-enabled/test.conf, then here is the command to disable it.
$ sudo a2disconf test.conf
Similarly, if you want to enable a global configuration file, you need to run a2enconf command.
$ sudo a2enconf test.conf
That’s it. In this article, we have learnt how to disable configuration file for specific virtual host using a2dissite command and how to disable global config files using a2disconf command.
Also read:
How to Read Command Line Arguments in NodeJS
How to Generate & Verify MD5 Checksum in Linux
How to Install NVM on Mac with Brew
Shell Script to Start & Restart Tomcat Server
Shell Script to Backup MySQL Database
Related posts:
Sreeram has more than 10 years of experience in web development, Python, Linux, SQL and database programming.