Apache Basics

From Initq

Jump to: navigation, search

This is an introduction to the Apache web server. Apache has 68% of the Internet traffic. It is Open Source and runs on all major OS.

Contents

Determining whether Apache is already installed

[root@initq ~]# rpm -q httpd
package httpd is not installed
[root@initq ~]# rpm -q apache
package apache is not installed
[root@initq ~]# rpm -q apache2
package apache2 is not installed

Since none of that worked, it's time to try some drastic measures to find the packages.

[root@initq ~]# rpm -qa | grep apache
apache-mod_cache-2.2.11-10.5mdv2009.1
apache-mod_authenticache-2.0.8-10mdv2009.1
apache-base-2.2.11-10.5mdv2009.1
apache-mod_auth_nds-2.0-11mdv2009.1
apache-mod_authn_imap-0.01-2mdv2009.1
apache-mod_proxy_ajp-2.2.11-10.5mdv2009.1
apache-mod_dav_svn-1.6.4-0.1mdv2009.1
apache-mod_perl-2.0.4-5mdv2009.1
apache-mod_bash-0.1.1-2mdv2009.1
apache-mod_authn_sasl-1.0.2-4mdv2009.1
apache-mod_xmlns-0.97-10mdv2009.1
apache-modules-2.2.11-10.5mdv2009.1
apache-mod_authn_dbd-2.2.11-10.5mdv2009.1
apache-mod_php-5.2.9-1mdv2009.1
apache-mod_cidr-0.04-2mdv2009.1
apache-mod_dbd-2.2.11-10.5mdv2009.1
apache-mod_auth_mysql-3.0.0-17mdv2009.0
apache-mod_proxy_xml-0.1-10mdv2009.1
apache-mod_dav-2.2.11-10.5mdv2009.1
apache-mod_auth_imap-2.2.0-8mdv2009.1
apache-mod_clamav-0.22-4mdv2009.0
apache-mod_proxy-2.2.11-10.5mdv2009.1
apache-conf-2.2.11-5mdv2009.1
apache-mod_proxy_html-3.0.1-0.r123.2mdv2009.1
apache-mod_chroot-0.5-7mdv2009.1
apache-mod_auth_cert-0.3-4mdv2009.1
apache-mod_authnz_external-3.2.3-1mdv2009.1
apache-mod_vhost_mysql-0.10-10mdv2009.1
apache-mpm-prefork-2.2.11-10.5mdv2009.1
apache-mod_authz_unixgroup-1.0.1-2mdv2009.1

To check the version you can try

[root@initq ~]# httpd -v
Server version: Apache/2.2.11 (Mandriva Linux/PREFORK-10.5mdv2009.1)
Server built:   Sep 22 2009 07:39:52

You can get extra information with -V.

[root@initq ~]# httpd -V
Server version: Apache/2.2.11 (Mandriva Linux/PREFORK-10.5mdv2009.1)
Server built:   Sep 22 2009 07:39:52                                
Server's Module Magic Number: 20051115:21                           
Server loaded:  APR 1.3.3, APR-Util 1.3.4                           
Compiled using: APR 1.3.3, APR-Util 1.3.4
Architecture:   64-bit
Server MPM:     Prefork
  threaded:     no
    forked:     yes (variable process count)
Server compiled with....
 -D APACHE_MPM_DIR="server/mpm/prefork"
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_FCNTL_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=128
 -D HTTPD_ROOT="/etc/httpd"
 -D SUEXEC_BIN="/usr/sbin/suexec"
 -D DEFAULT_PIDLOG="/var/run/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_LOCKFILE="/var/run/accept.lock"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"

You can get apache at

SSL

Make sure you have libssl and libssl-dev installed.

Installing Apache

We are not even going to touch Apache 1.3, all our documentation will be on Apache 2.0.

[root@initq local]# wget http://apache.opensourceresources.org/httpd/httpd-2.2.13.tar.gz
[root@initq local]# tar -xvzf httpd-2.2.13.tar.gz
[root@initq local]# cd httpd-2.2.13
[root@initq httpd-2.2.13]# ./configure --prefix=/usr/local/apache --enable-so 
--enable-mods-shared=most --enable-ssl --enable-dav
[root@initq httpd-2.2.13]# make
[root@initq httpd-2.2.13]# make install

--prefix indicates the server path
--enable-shared=max activates loadable modules support

Directories of Apache

[root@initq apache]# ls
bin/    cgi-bin/  error/   icons/    lib/   man/     modules/
build/  conf/     htdocs/  include/  logs/  manual/

Multiple Configuration Files

You can break up the config files by using the below in the main config httpd.conf file. Use the Include directive.

Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-autoindex.conf
Include conf/extra/httpd-languages.conf
Include conf/extra/httpd-vhosts.conf

Starting and Stopping Apache

apachectl -k start
apachectl -k stop
apachectl -k restart
apachectl -k greaceful

The help page looks like this

[root@initq bin]# ./apachectl -h
Usage: /usr/local/apache/bin/httpd [-D name] [-d directory] [-f file]
                                   [-C "directive"] [-c "directive"]
                                   [-k start|restart|graceful|graceful-stop|stop]
                                   [-v] [-V] [-h] [-l] [-L] [-t] [-S]
Options:
  -D name            : define a name for use in <IfDefine name> directives
  -d directory       : specify an alternate initial ServerRoot
  -f file            : specify an alternate ServerConfigFile
  -C "directive"     : process directive before reading config files
  -c "directive"     : process directive after reading config files
  -e level           : show startup errors of level (see LogLevel)
  -E file            : log startup errors to file
  -v                 : show version number
  -V                 : show compile settings
  -h                 : list available command line options (this page)
  -l                 : list compiled in modules
  -L                 : list available configuration directives
  -t -D DUMP_VHOSTS  : show parsed settings (currently only vhost settings)
  -S                 : a synonym for -t -D DUMP_VHOSTS
  -t -D DUMP_MODULES : show all loaded modules
  -M                 : a synonym for -t -D DUMP_MODULES
  -t                 : run syntax check for config files

Changing the Address and Port Apache uses

This setting goes in the httpd.conf file:

Listen 12.34.56.78:80
Listen 8080

Apache will list on port 80 and ip address 12.34.56.78. It will also listen on port 8080 on all available ip addresses.

Changing the User Apache Runs As

User daemon
Group daemon

Specifying a Server Name

ServerName www.example.com:80

Providing an Icon for the Web Page

AliasMatch /favicon.ico /usr/local/apache/icons/site.ico

Server Signature

ServerSignature On | Off | Email

Server Tokens

ServerTokens Full | OS | Minor | Major | Prod

Discovering the Modules Available=

[root@initq bin]# ./httpd -l
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c

You may also use httpd -M to geta full list of modules. httpd -S will test your config file for any errors without running the web server.

Enabling and Disabling Individual Modules

LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_dbm_module modules/mod_authn_dbm.so
LoadModule authn_anon_module modules/mod_authn_anon.so

Below is the conditional Module load.

<IfModule !mpm_winnt_module>
User daemon
Group daemon
</IfModule>

Adding Modules after Compiling Apache

You can use apxs -c mod_usertrack.c to compile modules. For more complex modules like PHP or perl you will need to use the --with-apxs flag with the supplied configuration of the module.

Publishing Content

DocumentRoot "/usr/local/apache/htdocs"
Personal tools