A Safe Location for Apache Includes
Find out where to store your custom Apache configuration files in this Tutorial.
By. Jacob
Edited: 2019-12-07 02:35
So, I have been trying to work out the best place to store my "personal" configuration files for Apache for some time now, and I think I have finally figured it out.
These are typically configurations that are shared among multiple Virtual Hosts which I load via include statements in the main configurations. I use them to edit my VHOSTs in bulk, rather than having to edit every single VHOST file.
Using your own configuration files like this is also a useful way to keep a backup of common configurations, avoiding having to rewrite everything if you later reinstall a server.
I am still not 100% sure it matters for Apache, but I have now moved my .conf files to a location like this:
/usr/local/etc/apache2/my-files/
For several years, I have simply used the default location in Ubuntu:
/etc/apache2/my-files
But there seemed to be little information available on what the preferred location is. So, fearing that an update might delete my custom files, I have now moved them to use a "standard" location, in accordance with the Filesystem Hierarchy Standard. In addition, I also keep backups of these files.
Detailed explanation
After much Googling on the topic, I finally found some information about the /usr/local/ location.
Apparently, in Linux systems, this location is intended for content that should not be overwritten doing system updates.
The only thing I was able to find is, according to the official documentation, the default installation for Apache on UNIX is /usr/local/, which indicated that Apache files should not be overwritten or deleted due to system updates.
...in a default install, Apache httpd resides at /usr/local/apache2 in the Unix filesystem...
If you pay close attention, then you will note that some directories are named the same as in the root "/" location. There is a reason for this simple hierarchy. For example, if you want to replace a system command located in /bin/, you could create a file in /usr/local/bin/ with the same name, and every time that command is typed, your "local" version will be used instead. Pretty cool if you ask me!
The advantage is, when you later update the system, your "local" replacement will be preserved, even in case the original system command is updated.
You really got to appreciate the simplicity of Linux :-)
Where to store custom .conf files for Apache
If you have worked with Apache and Linux for long enough, you will know by now that the location of various Apache files will depend on the distribution you are using.
Ubuntu likes to store configuration files in /etc/apache2/, and while I am not 100% sure, I think this location should also be safe for custom configuration files.
Now, there is also other directories, such as /usr/local/etc/, and we can use this as a safe location for Apache configuration files.
For a long time, I would simply store my own .conf files in a location like /etc/apache2/My-files/, but I was not sure this was safe, so I have now moved my configuration to /usr/local/etc/apache2/My-files.
Another option is to move your home directory, but I do not recommend this, as it will just create "clutter" of files that are rarely accessed. Usually, I prefer to to keep the /home/MyUserName/ location free from clutter, in order to have some "clean" workspaces, similar to how I also limit icons on my Desktop.
Links
- /usr/local : Local hierarchy - linuxfoundation.org
- Filesystem Hierarchy Standard - linuxfoundation.org
Tell us what you think: