Where does Apache server store its configuration files?

in Categories Apache, FAQ, Linux, UNIX last updated June 28, 2006

Different Linux distributions and/or UNIX operating system, and control panels stores Apache web server configuration file at different locations. There are different ways to locate configuration file.

Apache is, by default, installed in /etc/httpd directory. But this path also depends on how apache has been compiled. Default configuration file name httpd.conf.

Using httpd command

To find the location where apache is installed and to print configuration file location, run the following command:
# httpd -v

Here is the output from my Fedora Core/RedHat (RHEL) Linux server:

Server version: Apache/2.0.54
Server built:   Jan 17 2006 06:36:00
Server's Module Magic Number: 20020903:9
Architecture:   32-bit
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="logs/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

HTTPD_ROOT points to default location /etc/httpd and line SERVER_CONFIG_FILE points to configuration file conf/httpd.conf. So the path is /etc/httpd/conf/httpd.conf

If you are using Debian Linux try apache-perl:

# apache-perl -V

cPanel/Plesk Control Panel

If you are using third party control panel, then you can find out Apache configuration file inside your /home/username/ directory or /var/www/vhosts/ directory.

Using find command

This is an old good (read as geekey) classic way to locate httpd.conf file:
# find / -name 'httpd.conf' -print

You may have to wait for few seconds/minute to search complete. Or try out locate command:
# locate httpd.conf

Poll: Which Webserver do you use?

in Categories Apache, News last updated June 23, 2006

Our last poll asked readers of this blog the question:

Are you going to try or upgrade to enterprise grade Ubuntu Linux (code-named Dapper Drake)?

Thanks to everyone, total 338 people responded to the poll. Results are as follows:

  • 51% said they are happy with current setup/Linux/BSD distribution
  • 33% said they are willing to upgrade
  • 15% said they are not sure or they are not going to upgrade

It looks like people are following old mantra: If It’s Not Broken, Don’t Fix It. Personally I will stick to *BSD or RHEL only.

New poll: Which Webserver do you use?

Again I am using Apache 1.3x and lighttpd (for rails apps). I am interested to see what fellow sys admins are using and why?

Howto: Performance Benchmarks a Webserver

in Categories Apache, FreeBSD, Howto, lighttpd, Linux, Networking, Troubleshooting, UNIX, Windows server last updated June 9, 2006

You can benchmark Apache, IIS and other web server with apache benchmarking tool called ab. Recently I was asked to performance benchmarks for different web servers.

It is true that benchmarking a web server is not an easy task. From how to benchmark a web server:

First, benchmarking a web server is not an easy thing. To benchmark a web server the time it will take to give a page is not important: you don’t care if a user can have his page in 0.1 ms or in 0.05 ms as nobody can have such delays on the Internet.

What is important is the average time it will take when you have a maximum number of users on your site simultaneously. Another important thing is how much more time it will take when there are 2 times more users: a server that take 2 times more for 2 times more users is better than another that take 4 times more for the same amount of users.”

Here are few tips to carry out procedure along with an example:
Continue reading “Howto: Performance Benchmarks a Webserver”

Speed up Apache 2.0 web access or downloads with mod_deflate

in Categories Apache, CentOS, Debian Linux, High performance computing, Howto, Linux, RedHat/Fedora Linux, Tuning, Ubuntu Linux, UNIX last updated May 24, 2006

You can speed up downloads or web page access time with Apache mod_deflate module. The mod_deflate module provides the DEFLATE output filter that allows output from your server to be compressed before being sent to the client over the network.

This decreases the amount of time and data transmitted over the network, resulting in faster web experience or downloads for visitors.

Make sure mod_deflate included with your Apache server (by default it is now installed with all modern distro).

How can I speed up downloads from my Apache 2.0 server?

Open httpd.conf file using a text editor such as vi:
# vi httpd.conf

Append following line:
LoadModule deflate_module modules/mod_deflate.so

Append following configuration <Location /> directive:
<Location />
AddOutputFilterByType DEFLATE text/html text/plain text/xml

Above line only compress html and xml files. Here is the configuration from one of my production box:
<Location />
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/atom_xml
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/x-httpd-php
AddOutputFilterByType DEFLATE application/x-httpd-fastphp
AddOutputFilterByType DEFLATE application/x-httpd-eruby
AddOutputFilterByType DEFLATE text/html

Close and save the file. Next restart apache web server. All of the above extension file should compressed by mod_deflate:
# /etc/init.d/httpd restart

You can also specify specific directory and enabling compression only for the html files. For example /static/help/ directory:
<Directory "/static/help">
AddOutputFilterByType DEFLATE text/html

In real life, there are issues with compressing other types of files such as mp3 or images. If you don’t want to compress images or mp3 files, add following to your configuration:
SetOutputFilter DEFLATE
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.(?:exe|t?gz|zip|bz2|sit|rar)$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.pdf$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.avi$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mov$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp3$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.mp4$ no-gzip dont-vary
SetEnvIfNoCase Request_URI \.rm$ no-gzip dont-vary

Please note that this processing takes additional CPU and memory on your server as well as on the client browser. So you must make decision which document you need to compress (thanks to mdxp).

See also:

Configure an Apache web server for core dump on segmentation faults

in Categories Apache, FreeBSD, Linux, Troubleshooting last updated May 9, 2006

Recently I have noticed that my Apache error log file shows it is generating segmentation faults. After doing little research I came to know that there is not simple solution to find of causes of this problem. I got an error that read as follows:

[Mon May 8 11:20:09 2006] [notice] Apache/2 (WebAppBETA) child pid 1256 exit signal Segmentation fault (11)
[Mon May 8 11:23:12 2006] [notice] Apache/2 (WebAppBETA) child pid 1301 exit signal Segmentation fault (11)

The problem is that our application development team has hacked (aka modified source code) Apache 2.0 source tree for application my company developing. To get rid of this problem I was asked to configure a Linux system so that Apache can dump core files on segmentation faults.

Apache Core Dump

Apache supports CoreDumpDirectory directive. This controls the directory to which Apache attempts to switch before dumping core. So all I need to do is put line as follows in httpd.conf:

Open httpd.conf:
# vi httpd.conf
Add following line main config section:
CoreDumpDirectory /tmp/apache2-gdb-dump
Create a directory /tmp/apache2-gdb-dump:
# mkdir -p /tmp/apache2-gdb-dump
Set permission:
# chown httpd:appserver /tmp/apache2-gdb-dump
# chmod 0777 /tmp/apache2-gdb-dump

Please note that we are using httpd user and group appserver. Please replace it with your actual Apache user:group combination.

And restart the Apache web server:
# /etc/init.d/httpd restart
OR kill Apache PID:
# kill -11 14658
Now you should see core dumps in /tmp/apache2-gdb-dump directory:
# ls /tmp/apache2-gdb-dump

How do I read the core dump files created by Apache on Linux systems?

Well I am not a developer but they are using gdb and other techniques to analyses the core dumps. Read man page of gdb for more information.

I hope that I will get a new patched version of Apache by next week. Another interesting fact I noticed that you need to configure Core Dumps on Linux only. We are also using FreeBSD for testing and it write core dump in the ServerRoot directory.

If Apache starts as root and switches to another user, the Linux kernel disables core dumps even if the directory is writable for the process. Apache (2.0.46 and later) enables core dumps on Linux 2.4 and beyond, but only if you explicitly configure a CoreDumpDirectory. 🙂

Why do I see Apache Test page?

in Categories Apache, Linux, RedHat/Fedora Linux, UNIX last updated May 2, 2006

Everyone must be familiar with “Oklahoma city threatens to call FBI over ‘renegade’ Linux maker” story.

Despite this, many of our new clients/customer and new admin/user does not understand why would a website show an Apache Test page ?

Apache test page means…

The Apache test page, means your server is configured properly and ready to use. Technically speaking this page is the default index page when you install Apache web server first time.

So how can I make the Apache test page go away?

Simple open your /var/www/index.html file and modify it or delete file (though it might trigger new error). Under Red Hat Enterprise Linux/CentOS/Fedora Core, rename or delete a file /etc/httpd/conf.d/welcome.conf to make sure you do not see Apache test page.

You may now add content to the directory /var/www/html/. Note that until you do so, people visiting your website will see default page and not your content. To prevent this page from ever being used, follow the instructions in the file /etc/httpd/conf.d/welcome.conf.

If you do not know much about Apache web server, configuration it is better to take help of seasoned Linux/Unix administrator, IMHO.

Executing Linux / UNIX commands from web page

in Categories Apache, CentOS, Debian Linux, Howto, Linux, RedHat/Fedora Linux, Shell scripting, Suse Linux, Tips, UNIX last updated January 5, 2006

A Web interfaces is almost used by routers and many other sophisticated programs such as webmin. However, why go for a web interface or execute commands from web page? For automation purpose, you need to use a web interfaces. Another advantage is you can access your web-based interface from any computer, running any operating system, anytime in the world 😀

In this first part, you will see how to use simple bash (shell) script from web page. In order to execute commands or shell script from a webpage you need:

  1. CGI support with Apache / lighttpd web server.
  2. I’m assuming that you have a properly configured web server.

You need to store program in cgi-bin directory. If you are using Debian Linux default location for cgi-bin directory is /usr/lib/cgi-bin. Under Red Hat / Fedora it is /var/www/cgi-bin. Use text editor such as vi to create a first.cgi program:

$ cd /usr/lib/cgi-bin
$ vi first.cgi

first.cgi code listing:

echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"

echo "<h1>Hello world</h1>"
echo "Today is $(date)"

echo "</body></html>"

Save and close the file. Setup execute permission on the script:

$ chmod +x first.cgi

Fire up your web browser and test the script, for example type url http://localhost/cgi-bin/first.cgi or http://your-ip/cgi-bin/first.cgi

You need to send headers, first three lines are almost same for all your script:

  • #!/bin/bash : First line tell Linux/UNIX how file first.cgi should be run. So it will use /bin/bash interpreter to execute your rest of program.
  • echo “Content-type: text/html” : Send html headers, you must include this line.
  • echo “” : Send a blank line, you must include this line.

Rest is html code. Take a close look at following echo command:

echo "Today is $(date)"

It use shell feature called command substitution. It allows the output of a command to replace the command name:


Your bash shell performs the expansion by executing command and replacing the command substitution. So date command get executed by replacing the its output.

Real life example

Here is simple script that collects system information. Create script in cgi-bin directory:

echo "Content-type: text/html"
echo ""
echo "<html><head><title>Bash as CGI"
echo "</title></head><body>"

echo "<h1>General system information for host $(hostname -s)</h1>"
echo ""

echo "<h1>Memory Info</h1>"
echo "<pre> $(free -m) </pre>"

echo "<h1>Disk Info:</h1>"
echo "<pre> $(df -h) </pre>"

echo "<h1>Logged in user</h1>"
echo "<pre> $(w) </pre>"

echo "<center>Information generated on $(date)</center>"
echo "</body></html>"

Save and close the file. Setup execute permission on script:

$ chmod +x script.cgi

Fire up web browser and test it (http://localhost/cgi-bin/script.cgi):

Next time you will see:

  • How to use and place form elements (from POSTs and GETs)
  • Cookies in your environment
  • Use of perl scripting
  • And finally use of special tools