The Filesystem Hierarchy Standard (FHS) is maintained by the Linux Foundation to organize the various components of the file system. This will not be a comprehensive post, but rather, will provide just enough info to understand the basic structure and directories for most web servers.

A manpage is available for the filesystem hierarchy:

man hier

The manpage will list and provide a brief description of the basic directories.

Linux File System Hierarchy


The filesystem is generally referred to as a tree structure and the root (/) is where the whole tree begins. Starting with the root folder, every other file/folder cascades down from here.

In the rest of this post, I will highlight the more important directories that pertain to web servers and web developers.

bin and sbin

Command binaries are stored in these locations. Whenever you use a command such as ls, cat, or cp, a binary is executed from the bin directory. The sbin directory, on the other hand, is used for essential system binaries. That is, binaries that are critical for your system being able to run.

etc

The etc directory is mainly used for configuration files.

For instance, the list of users is in /etc/passwd. And the list of groups is in /etc/group.

There are several other important items to note here for web developers. First, your web server configuration files are usually located here. If you’re using Nginx, the conf files will be located in /etc/nginx. When adding any custom configuration, a convention that has emerged is placing a file in a conf.d folder (/etc/nginx/conf.d in this case). Any file placed in that directory will be imported automatically and loaded after the parent configuration file(s).

When you see a conf.d directory, any files placed in that directory will be loaded into the configuration without having to change it’s parent files (no need to manually import the new file). This allows you can have multiple configuration files for a single configuration. Apache, Nginx, and many other services have adopted this convention.

Environment variables are another important component of this directory. You can set system-wide environment variables in /etc/environment or in /etc/bash.bashrc (for terminal users).

Additional configurations included in /etc may include configuration files for things like SSL.

home

Inside the home folder will be a folder for each user. When you open a terminal window when connecting via SSH, your starting location will be in your home folder. On a desktop computer, there will be a lot of files placed here. For web servers, on the other hand, the home folder for each user may have little use. One common use is storing files and data exported from a database which will get downloaded via scp.

tmp

As the name implies, temporary files get stored here. You can set the TMPTIME environment variable in /etc/default/rcS in days in which this directory will be cleaned out. Some versions of Linux will also clear this folder out after each reboot.

usr

This directory, “Unix System Resources” (1 of several common acronyms for this actually), is commonly used for packages that will be installed locally, documentation, and much more. Generally speaking, the contents of this directory will be read only. This directory will also consist of many subdirectories.

/usr/local is generally used for software that’s installed manually outside of the package manager. In most cases, you would download the source files and create the build yourself.

opt

This is another location used to store downloaded software. Generally, the software being placed here is bundled software that is self-contained. It should not require that assets get placed in multiple directories.

var

When working with web servers, this area may be where you spend the most time. For the other directories, little time may be spent outside the initial setup.

Var is an abbreviation for “variable”. This implies it’s intended for things that vary and change frequently. For many web applications, source code files are stored in /var/www. Another common item developers and sysadmins regularly access are log files. Most of these will be stored in /var/log. Additional directories are placed in /var/log which may include folders for your web server, database server, and other program logs.


Posted in