Apache uses configuration files to change its behavior. It usually stores them at
/etc/apache2/ on Unix systems, but the configuration directory can vary, depending on how it was installed and which operating system you’re running it on.
The Usual Places
The primary way of configuring Apache is by modifying the main configuration file, usually located at:
This file can also be named
httpd.conf on older installs. If it’s not there, it’s likely in one of the following places:
/usr/local/apache2/apache2.conf—if you’ve compiled from source, Apache is installed to
/opt/, rather than
If you’ve installed Apache on Windows, you likely installed it to your
C:Program Files directory, under “Apache Software Foundation”:
C:Program FilesApache Software FoundationApache2.4
If you’re using Apache on macOS (for local development), the config folder is at the regular
/etc/apache2/ location, if you’re using the stock version of Apache that comes with macOS. If you’ve installed an up-to-date version from brew, it instead is at:
Regardless of the operating system or the details of your install, within this root configuration folder you’ll find a few files and directories:
httpd.confare the primary configuration files.
ports.confdefine on what ports Apache should listen.
conf.d/is used to store configuration snippets you can include in the primary config.
sites-available/is a directory containing a unique config file for each website your web server hosts. You can host multiple sites from the same IP; Apache splits them by domain name and uses separate config files for each. It’s common practice to name these files according to your domain name, e.g.
sites-available/example.com. A default site already exists that you can copy.
sites-enabled/determines which sites are actually in use. It’s a special folder containing symlinks to the actual configuration files in
sites-available. With this, you can turn sites on and off easily with the
Configuration with .htaccess Files
You can also configure Apache without even touching the root configuration. If the feature is enabled, Apache attempts to read a file named
.htaccess from your site’s document root (the place where you put your HTML and other site content).
It’s particularly useful for shared hosting. Most of the time, if you get cheap website hosting from a service like GoDaddy or SquareSpace, you’re not renting a whole web server just for your site. Your site is bundled with many other smaller sites and ran off one big server, which cuts down on hosting costs significantly. The problem with this setup is that you don’t want people to be able to modify the configuration for other people’s sites running on the same server, so you can’t just give access to the primary config folder.
.htaccess files solve this issue by changing the behavior of Apache based on the folder from which the content is being served. Doing so has a bit of a performance overhead, so it’s not recommended for use unless you’re forced to by a shared hosting provider.
In this case, the location of your config folder is simple—create a new file simply named:
And place it in your document root alongside your
index.php pages. The
.htaccess file will override the root config for the whole directory, and also apply it to any subdirectories.
You can have multiple
.htaccess files in separate directories; for example, if you have a part of your website hosted in the
/admin/ folder, you could place an additional
.htaccess in that folder and add basic HTTP auth to secure it.
How to Find The Configuration Folder Manually
On most distros, you can usually use the
whereis command to locate programs and their associated files:
It outputs the location of the Apache binary, as well as the Apache configuration folder and all related directories:
apache2: /usr/sbin/apache2 /etc/apache2 /usr/lib/apache2 /usr/share/apache2 /usr/share/man/man8/apache2.8.gz
If you don’t have this command or it isn’t working, then use
find to search your whole drive for directories named “
sudo find / -type d -name "apache2"
You can also try searching for “
httpd“, as Apache may be installed under that name. If both of those commands don’t list anything, you likely don’t have Apache installed in the first place.
- › The 5 Biggest Android Myths
- › Vertagear SL5000 Gaming Chair Review: Comfortable, Adjustable, Imperfect
- › What’s the Best TV Viewing Distance?
- › 10 Quest VR Headset Features You Should Be Using
- › Samsung Galaxy Z Flip 4 Has Internal Upgrades, Not Design Changes
- › How to Add Winamp Visualizations to Spotify, YouTube, and More