See http://wiki.apache.org/httpd/DistrosDefaultLayout for discussion of where you might find Apache httpd configuration files on various platforms, since this can vary from release to release and platform to platform. The most common answer, however, is either /etc/apache/conf or /etc/httpd/conf
Generically, you can determine the answer by running the command:
httpd -V
(That’s a capital V). Or, on systems where httpd is renamed, perhaps apache2ctl -V
This will return various details about how httpd is built and configured, including the default location of the main configuration file.
One of the lines of output should look like:
-D SERVER_CONFIG_FILE=”conf/httpd.conf”
which, combined with the line:
-D HTTPD_ROOT=”/etc/httpd”
will give you a full path to the default location of the configuration file
ПоделитьсяНашли опечатку?Пожалуйста, сообщите об этом – просто выделите ошибочное слово или фразу и нажмите Shift Enter.
|
Добавить комментарий |
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:
/etc/apache2/apache2.conf
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:
/etc/httpd/httpd.conf
/etc/httpd/conf/httpd.conf
/usr/local/apache2/apache2.conf
—if you’ve compiled from source, Apache is installed to/usr/local/
or/opt/
, rather than/etc/.
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:
/usr/local/etc/httpd/httpd.conf
Regardless of the operating system or the details of your install, within this root configuration folder you’ll find a few files and directories:
apache2.conf
orhttpd.conf
are the primary configuration files.ports.conf
define 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 insites-available
. With this, you can turn sites on and off easily with thea2ensite
command.
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:
.htaccess
And place it in your document root alongside your index.html
or 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:
whereis apache2
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 “apache2
“:
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.
READ NEXT
- › Grab an Ecobee Premium Smart Thermostat on Sale Today
- › How to Skip “Hey Google” with Google Assistant
- › Roku’s New TVs Are up to $200 Off Right Now
- › Future AMD CPUs Will Have Hybrid Cores, Just Like Intel
- › How to Add and Remove Users on Ubuntu
- › Disney Is Pulling Its Own Shows and Movies From Disney+ and Hulu
I have installed Ubuntu 14.04 on a laptop and installed apache 2 (version 2.4.7) and PHP 5.
I cannot find httpd.conf
. I need to change it because when I try to open a .php page I see a download box.
How should I proceed?
A.B.
88.4k21 gold badges244 silver badges320 bronze badges
asked Jul 24, 2015 at 8:00
1
Ubuntu doesn’t use httpd.conf
as standard, instead global configuration stuff for apache is found in /etc/apache2/apache2.conf
. You can create a httpd.conf
in the apache2 directory, and load any further configuration from it by including the following line in /etc/apache2/apache2.conf.
Include /etc/apache2/httpd.conf
You don’t need that file to configure apache, but you can create it if other software relies on it being there.
answered Jul 24, 2015 at 8:09
ArronicalArronical
19.6k17 gold badges71 silver badges128 bronze badges
3
httpd.conf
will be in /etc/apache2/
.
/etc/apache2$ ls
apache2.conf envvars mods-available ports.conf sites-enabled
conf.d httpd.conf mods-enabled sites-available
:/etc/apache2$ more httpd.conf
:/etc/apache2$
I need to change it
No, you do not. The documentation states:
httpd.conf: historically the main Apache2 configuration file, named after the httpd daemon. Now the file does not exist. In older versions of Ubuntu the file might be present, but empty, as all configuration options have been moved to the below referenced directories.
because when I try to open a .php page I see a download box
How would changing httpd.conf
fix that?
If you need config settings changed I would assume you need to alter apache2.conf
or the virtual host in /etc/apache2/sites-enabled/
.
answered Jul 24, 2015 at 8:09
RinzwindRinzwind
291k39 gold badges564 silver badges704 bronze badges
1
How can I reliably find the location of httpd.conf?
I am looking for a solution, or if necessary a combination of things that will find the location of httpd.conf quickly and reliably on as many Operating Systems as possible.
Thanks!
asked Nov 18, 2015 at 1:09
mareoraftmareoraft
5901 gold badge5 silver badges14 bronze badges
7
For me,
apachectl -V
works on both OSX and FreeBSD.
If anybody has a better answer or a continuation of this answer for other operating systems, feel free to share.
answered Nov 19, 2015 at 22:19
mareoraftmareoraft
5901 gold badge5 silver badges14 bronze badges