Difference between httpd.conf, php.ini and .htaccess - apache

I am about to start learning Apache. All resources I am looking into, mention either php.ini, or .htaccess or httpd.conf files for setting configurations and stuff. But none of them are clear on the difference between these 3 files. Can anyone explain the difference and their usage?

httpd.conf (it can actually be named differently on some platforms, but that's the default) is the master configuration file for Apache. You can use Include statements to pull in external configuration files. httpd.conf is read in when Apache starts or if you run a 'reload'.
.htaccss is a per-directory configuration file for Apache. You can enable or disable the use of .htaccess files in your httpd.conf file. Where possible its been recommended to me to turn .htaccess use off, as Apache will check the file every time a request causes it to read the directory.
PHP is, as you probably know, separate from Apache, although often used with it. php.ini is the configuration file for the PHP engine.

Every daemon or application has it's own configuration files. On linux these are often located in the /etc directory. You will have to learn to edit each one according to the program. the /etc/php5/php.ini is different from the /etc/apache2/httpd.conf and so on.
Think of them like different types of files. a Word document is not the same as a JPEG Image or a AVI video.
The PHP.ini controls PHP's settings
The .htaccess controls apache settings for a given folder (and all child folders)
The httpd.conf controls apache's settings.

php.ini is a configuration file where you specify options for things
related specifically to php, for instance CURL
.htaccess is where you specify options for URI routing and folders
options on your server
httpd.conf is a configuration file where you specify options for
things related specifically to apache

Related

Where to put Apache vhost configuration (httpd-vhosts.conf or httpd.conf)?

I just to ask a simple question. I am studying the vhost configuration but I am confused where should I properly put my vhosts configuration?
I have a file that has a name httpd-vhosts.conf and httpd.conf
I try to put my configuration in these 2 files but different web projects. And after I restarted my Wampserver I can access them. Is it fine if I place all my vhost entries in the file httpd-vhosts.conf ? Or should I place it in httpd.conf
There is no right or wrong. Apache has one global config file, which typically is the default or specified in the startup script.
This file then uses one or more secondary config files and directories. Different Linux distributions use different default include directories.
On CentOS I think for example you would put a file (named like your domain but can be anything) in /etc/httpd/conf.d/example-com.conf: http://wiki.centos.org/TipsAndTricks/ApacheVhostDir

Is there a way for Apache to silently ignore unrecognized .htaccess directives?

I'm in the unfortunate position of having an Apache staging server combined with a Zeus web server. (Not my choice).
I'd like to be able to include a Zeus-specific directive in the .htaccess file (e.g. ContentCompressionEnabled) and, if possible, include the Apache equivalent (AddOutputFilterByType DEFLATE) in the same file too.
Is there a way of doing this which doesn't involve separate .htaccess files for Zeus and Apache?
Only in 2.4, where there is an Nonfatal option to AllowOverride.
If I understood correctly, you can use httpd.conf file do this configuration for all requests. .htaccess file configurations effect only requests to where the file located.
You could put any Apache only directives into either Apache's main httpd.conf file, or the sites vhost config file - along with AllowOverride None.
This would mean that Apache would get all it's config info from there and ignore any .htaccess files completely.
You could then place anything you wanted in the .htaccess files, including all the Zeus config you need - and Zeus would be configured only from there - thus separating the two configs.

Change php.ini settings without modifying the original php.ini file or using the htaccess

The default php.ini value on my server for file uploading(upload_max_filesize, post_max_size) is 10M. I wanted to increase it to 40M. How do I do that?
Method 1: I can't use. This method doesn't work in this specific case.
ini_set("upload_max_filesize", "40M");
ini_set("post_max_size", "40M");
Method 2: I can't do it using the htaccess either. Because when I do so my server changes my .htaccess file with the following error
# For security reasons, mod_php is not used on this server. Use a php.ini file for php directives
Method 3: And I don't want to make changes to the default php.ini file because that will change the settings throughout the whole server.
Method 4: I have heard that I can create a php.ini file in my site and define the settings there but it didn't work either. My code for that file. (I kind of have a feeling that I applied this method in a wrong way)
[PHP]
upload_max_filesize =40M
post_max_size =40M
Well, method 4 worked for me as I thought. I just had to do it the right way. Adding this specific line to my .htaccess file reads the newly created php.ini file in that folder.
AddHandler application/x-httpd-php5 .php
On Bluehost cpanel PHP Configuration I selected PHP 5.2
"All files with the extension .php will be handled by the PHP 5.2 engine.
Legacy PHP with security updates. Compatible with most environments. "
To eliminate the "#For security reasons, mod_php is not used on this server. Use a php.ini..." message.

My httpd.conf is empty

I recently installed apache2 on ubuntu but I have a problem, my httpd.conf is empty. Can someone give me a clean copy of httpd.conf for apache2 on ubuntu?
Thanks!
Edit: I saw your answers but on wampserver httpd.conf is not empty and as you mentioned it is for user options. SO what should I do?
Edit2 : That's what I got on my apache2.conf, how I add modules, enable gzip and all of that?
[Deleted the contents, as they render the question unreadable and are useless, because that were the default Apache2 configuration under Ubuntu.]
The /etc/apache2/httpd.conf is empty in Ubuntu, because the Apache configuration resides in /etc/apache2/apache2.conf!
“httpd.conf is for user options.” No it isn't, it's there for historic reasons.
Using Apache server, all user options should go into a new *.conf-file inside /etc/apache2/conf.d/. This method should be "update-safe", as httpd.conf or apache2.conf may get overwritten on the next server update.
Inside /etc/apache2/apache2.conf, you will find the following line, which includes those files:
# Include generic snippets of statements
Include conf.d/
As of Apache 2.4+ the user configuration directory is /etc/apache2/conf-available/. Use a2enconf FILENAME_WITHOUT_SUFFIX to enable the new configuration file or manually create a symlink in /etc/apache2/conf-enabled/. Be aware that as of Apache 2.4 the configuration files must have the suffix .conf (e.g. conf-available/my-settings.conf);
It's empty by default. You'll find a bunch of settings in /etc/apache2/apache2.conf.
In there it does this:
# Include all the user configurations:
Include httpd.conf
OK - what you're missing is that its designed to be more industrial and serve many sites, so the config you want is probably:
/etc/apache2/sites-available/default
which on my system is linked to from /etc/apache2/sites-enabled/
if you want to have different sites with different options, copy the file and then change those...
It seems to me, that it is by design that this file is empty.
A similar question has been asked here:
https://stackoverflow.com/questions/2567432/ubuntu-apache-httpd-conf-or-apache2-conf
So, you should have a look for /etc/apache2/apache2.conf

Apache 2.2 on XP: How configuration files are managed? Where should they be located?

New to Apache, and suffering...
Seems to be true:
the default configuration is in Apache directory Apache2.2/conf/httpd.conf
Unsure of that:
it can be elsewhere
to create some separation between test/production, it seems that the best option is
to store all test files, including configuration and logs, in the same directory, with subdirectories conf, log, htdocs, and all production files in another directory using a similar structure.
if my upper directory is d:mywww, then the server needs to be started with the associated configuration file, e.g. httpd -f "d:mywww/conf/httpd.conf"
What will happen to the default configuration file if the -f option is used. Will it be ignored?
If instead of the -f option, you use httpd -d "d:mywww/htdocs" to indicate the directory to serve, but not any configuration file, will the default config file be used and the one under d:mywww/conf ignored?
Can someone confirm or deny?
Is there a well known site with a good introduction on setting up Apache, if possible on Windows. I found the Apache documentation a little bit difficult, and Apache Definitive Guide not clear about this kind of questions.
I was new to Apache 2 months ago, and still suffering. Since you got no replies from pros yet, I'll chip in my 2 cents: (all for Ubuntu 10.10)
httpd.conf is used for your personal configurations, so I'd say that it is not the default configuration file as you specify. The default would be, in my case at least, in /etc/apache2/apache2.conf
you can have a bunch of other conf files. In my case, I can place any file with an extension .conf inside /etc/apache2/conf.d/ and it will be picked up by Apache on restart.
Don't know about the rest. Hope it helps you