Apacheのインストールと設定

(httpd-2.0.55 + PHP4.3.10 + PostgreSQL 7.0.3 + openssl-0.9.8a)

apacheを導入してwebサーバーを構築します。
やはり趣味的にPostgreSQL導入することにしますので、PHPも導入します。
PHPの導入にはgd-1.8.4が予め導入されていることがひつようです。
SSLもサポートしますので予めOpenSSLの導入が必要です。
コンパイルの手順は以下のようになります。

postgreSQLの導入例を記載します。

#------------------------------------------------
# Make postgreSQL
#------------------------------------------------
# groupadd postgres
# useradd -g postgres -d /home/postgres -m postgres

# mkdir /usr/local/src
# cp postgres.7.0.3.tar.gz /usr/local/src/.
# cd /usr/local/src
# mkdir postgresql-7.0.3
# chown postgres:postgres postgresql-7.0.3

#mkdir /usr/local/pgsql
# chown postgres:postgres /usr/local/pgsql
# su - postgres
$ cd /usr/local/src
$ gunzip -c zxvf postgres.7.0.3.tar.gz | tar -xvf -
$cd /usr/local/src/postgresql-7.0.3/src
./configure --prefix=/usr/local/pgsql 
--enable-multibyte=EUC_JP 
--with-CC=gcc

$ make
$ make install

OpenSSLの導入例を記載します。

#------------------------------------------------
# Make OpenSSL
#------------------------------------------------
rm -rf openssl-0.9.8a
/usr/local/bin/gunzip -c openssl-0.9.8a.tar.gz | tar -xvf -
cd openssl-0.9.8a
./Configure solaris-sparcv8-gcc 
CC=gcc make
CC=gcc make install
cd ..
rm -rf openssl-0.9.8a

apacheの導入例を記載します。

#------------------------------------------------
# Make Apachel
#------------------------------------------------
rm -rf httpd-2.0.55
gunzip -c httpd-2.0.55.tar.gz |tar -xvf -
cd httpd-2.0.55
CC="gcc" CFLAGS="-g -O2" ./configure 
--prefix=/usr/local/apache2 
--enable-modules=most 
--enable-mods-shared=all 
--with-ssl=/usr/local/ssl --enable-ssl 
--enable-usertrack 
--enable-vhost-alias 
--enable-mime-magic 
--enable-distcache 
--enable-dav --enable-dav-fs 
--enable-cgi 
--enable-suexec --with-suexec 
--with-suexec-caller=apache
--with-suexec-docroot=/export/home/www 
--with-suexec-logfile=/export/home/logs/suexec.log 
--with-suexec-bin=%{_prefix}/suexec 
--with-suexec-uidmin=500 --with-suexec-gidmin=10 
--enable-file-cache --enable-disk-cache 
--enable-cache --enable-mem-cache 
--enable-deflate 
--with-ldap --enable-ldap --enable-auth-ldap 
--enable-proxy --enable-proxy-connect 
--enable-proxy-http --enable-proxy-ftp 
--enable-logio 
--with-mpm=prefork 
--with-apr=/usr/local/include/apr-1 
--with-apr-util=/usr/local/include/apr-1
 
CC="gcc" CFLAGS="-g -O2" make 
make install

cd ..
rm -rf httpd-2.0.55
#------------------------------------------------
# Make PHP4
#------------------------------------------------
rm -rf php-4.3.10
gunzip -c php-4.3.10.tar.gz | tar -xvf -
cd php-4.3.10
./configure 
--with-apxs2=/usr/local/apache2/bin/apxs 
--with-pgsql=/usr/local/pgsql 
--with-mysql=/usr/local/mysql 
--enable-mbstring 
--enable-mbstr-enc-trans 
--with-perl=/usr/local/bin/perl 
--with-gd --with-jpeg-dir=/usr/local --with-zlib-dir=/usr/local 
make
make install

cd ..
rm -rf php-4.3.10

Apacheの動作を設定

/usr/local/apache/conf/httpd.confで細かい設定をします。
最低限変更するところは以下のようになると思います。

StartServers 5
MaxClients 50
MinSpareServers 5
MaxSpareServers 10
Port 80
Listen 80
Listen 443
User nobody
Group nobody
ServerAdmin support@hoge.com
ServerName www.hoge.com
DocumentRoot "/export/home/www/html"
Options FollowSymLinks MultiViews
AllowOverride AuthConfig Limit
Order allow,deny
Allow from all

HostnameLookups On
ErrorLog /export/home/logs/error_log
CustomLog /export/home/logs/access_log combined
ServerSignature Off
ScriptAlias /cgi-bin/ "/export/home/www/cgi-bin/"
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all

AddType application/x-httpd-php .php .php3
AddHandler cgi-script .cgi
ErrorDocument 500 /error/interror.html
ErrorDocument 401 /error/unauth.html
ErrorDocument 403 /error/forbidden.html
ErrorDocument 404 /error/missing.html

バーチャルホストを使う場合は以下のようになると思います。
以下はネームバーチャルの例です。

NameVirtualHost *

ServerName www.hoge.com
ServerAdmin info@hoge.com
ErrorLog /home/logs/hoge.com-error_log
CustomLog /home/logs/hoge.com-access_log combined
DocumentRoot "/home/site/hoge.com/html"
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all

ScriptAlias /cgi-bin/ "/home/site/hoge.com/cgi-bin/"
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
# SSL サポート
# General setup for the virtual host
DocumentRoot "/home/ssl/html"
ServerName www.hoge.com
ServerAdmin info@hoge.com
ErrorLog /home/logs/ssl_error_log
TransferLog /home/logs/ssl_access_log

Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all

ScriptAlias /cgi-bin/ "/home/ssl/cgi-bin/"
AllowOverride None
Options ExecCGI FollowSymlinks
Order allow,deny
Allow from all
AllowOverride None
Options ExecCGI FollowSymlinks
Order allow,deny
Allow from all

SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /usr/local/apache/conf/server_cert.pem
SSLCertificateKeyFile /usr/local/apache/conf/securekey.pem
SSLCACertificatePath /usr/local/apache/conf/ca
SSLCACertificateFile /usr/local/apache/conf/ca/cacert.pem
SSLCARevocationFile /usr/local/apache/conf/crl.pem

SSLOptions +StdEnvVars

SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
CustomLog /home/logs/ssl_request_log "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"

自動起動の登録

apache及びpostgreSQLの起動シェルを作って再起動後にも自動的に起動するようにします。

/etc/rc3.d/S88postgres

postgreSQLの起動シェル例

#!/bin/sh
#
# postgres.init.sh - This script is used to start/stop
# the postgreSQL listener process.
#
#
# The following lines should be in this account's .bash_profile
#
case "$1" in
start)
echo "Starting postgres: "
su - postgres -c "/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data start"
echo
;;
stop)
echo "Stopping postgres: "
su - postgres -c "/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data stop"
echo
;;
*) 
echo "Usage: $0 {start|stop}"
exit 1
esac

apacheの起動シェル例

#!/bin/sh
LD_LIBRARY_PATH=/usr/local/pgsql/lib:/usr/local/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
LD_LIBRARY_PATH=/usr/local/ldap/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

case "$1" in
start)
echo "Starting apache: "
/usr/local/apache/bin/apachectl startssl
echo
;;
stop)
echo "Shutting down apache: "
/usr/local/apache/bin/apachectl stop
echo
;;
restart)
$0 stop
sleep 5
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit