Apache2.2.22インストール

Apache2.2.22インストールのメモ。

apr,aprutilインストール

apt-get update
apt-get install libapr1-dev libaprutil1-dev

ユーザ作成

groupadd -g 2004 apache
useradd -u 2004 -g apache -d /home/apache -m -s /bin/bash apache

ソースダウンロード

cd /usr/local/src
wget -c http://ftp.jaist.ac.jp/pub/apache//httpd/httpd-2.2.22.tar.gz

Apacheインストール

tar zxvf httpd-2.2.22.tar.gz
cd httpd-2.2.22
./configure --prefix=/usr/local/apache --with-mpm=prefork --enable-so --enable-ssl --enable-rewrite --enable-proxy
make && make install

ディレクトリ作成

mkdir -p /usr/local/apache/conf/{conf.d,proxy.d}
mkdir -p /usr/local/apache/vhosts

httpd.conf作成

cd /usr/local/apache/conf
mv -i httpd.conf{,.`date +%Y%m%d`}
vi httpd.conf
## Server Settings
ServerRoot "/usr/local/apache"
ServerAdmin webmaster@your.domain
PidFile "/usr/local/apache/logs/httpd.pid"
DirectoryIndex index.py index.wsgi index.pl index.php index.html index.htm

## Security
User apache
Group apache
ServerSignature Off
ServerTokens Prod
TraceEnable off

## Performance
<IfModule prefork.c>
    StartServers 5
    MinSpareServers 5
    MaxSpareServers 10
    MaxClients 100
    MaxRequestsPerChild 250
</IfModule>
<IfModule worker.c>
    ServerLimit 16
    StartServers 2
    MaxClients 150
    MinSpareThreads 25
    MaxSpareThreads 75
    ThreadsPerChild 25
</IfModule>

## Load Module
#LoadModule wsgi_module	modules/mod_wsgi.so
#LoadModule php_module modules/mod_php.so

## Log Settings
ErrorLog "logs/error_log"
LogLevel warn
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common

## MIME Type
DefaultType text/plain
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
#AddType application/x-httpd-php .php 
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml  
AddHandler cgi-script .cgi .py .pl
#AddHandler wsgi-script .wsgi

## Access Control
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

<FilesMatch "^\.ht">
    Order allow,deny
    Deny from all
    Satisfy All
</FilesMatch>

<Location /server-status>
    SetHandler server-status
    Order Deny,Allow
    Deny from all
    Allow from 127.0.0.1
</Location>

## SSL
<IfModule ssl_module>
    Include conf/ssl.conf
</IfModule>

## VirtualHost
Listen xx.xx.xx.xx:80
#Listen xx.xx.xx.xx:443
NameVirtualHost xx.xx.xx.xx:80
#NameVirtualHost xx.xx.xx.xx:443
Include conf/conf.d/*.conf

ssl.conf作成

vi ssl.conf
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
SSLPassPhraseDialog  builtin

AddType application/x-x509-ca-cert .crt
AddType application/x-pkcs7-crl    .crl

SSLSessionCache        "shmcb:/usr/local/apache/logs/ssl_scache(512000)"
SSLSessionCacheTimeout  300
SSLMutex  "file:/usr/local/apache/logs/ssl_mutex"

localhost.conf作成

vi conf.d/localhost.conf
<VirtualHost xx.xx.xx.xx:80>
    ServerName xxx.co.jp
    DocumentRoot /usr/local/apache/htdocs
    ErrorLog /usr/local/apache/logs/error_log
    CustomLog "/usr/local/apache/logs/access_log" combined
</VirtualHost>

<Directory /usr/local/apache/htdocs>
    Options Includes ExecCGI FollowSymLinks
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

起動スクリプト作成

vi /etc/init.d/apache
#!/bin/sh

### BEGIN INIT INFO
# Provides:          apache
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Apache HTTP Server start/stop script.
# Description:       Start and stop Apache HTTP Server.
### END INIT INFO

_APACHE=/usr/local/apache/bin/apachectl
_PID=/usr/local/apache/logs/httpd.pid
_STATUS=0

if [ $# -ne 1 ] ;then
    echo "Usage : apache [start|stop]"
    exit 1
fi

if [ ! -x $_APACHE ] ;then
    echo "$_APACHE : command is not available."
    exit 1
fi

[ -f $_PID ] && _STATUS=1

start(){
    if [ $_STATUS -ne 0 ] ;then
        echo "Already running."
        exit 1
    fi
    $_APACHE start
    test $? -eq 0 && echo "Apache HTTP Server started."
}

stop(){
    if [ $_STATUS -ne 1 ] ;then
        echo "Not running."
        exit 1
    fi
    $_APACHE stop
    test $? -eq 0 && echo "Apache HTTP Server stopped."
}

case $1 in
    start)
        start;;
    stop)
        stop;;
    *)
        echo "Usage : apache [start|stop]"
        exit 1;;
esac

exit 0

Apache起動、自動起動設定

/usr/local/apache/bin/httpd -t
chmod 755 /etc/init.d/apache
/etc/init.d/apache start
ps -ef | grep httpd
tail /usr/local/apache/logs/error_log