Apache-2.2.17とPHP-5.3.5をソースからインストールした時の備忘録です。
■使用OS
CentOS 5.5 64bit
■httpdバージョン
httpd-2.2.17
http://httpd.apache.org/download.cgi#apache22
※最新版は上記URLで確認してください。
■PHPバージョン
php-5.3.5
http://www.php.net/downloads.php
※最新版は上記URLで確認してください。
・Apacheインストール
(1)httpdをダウンロードする。
[root@example ~]# wget http://www.meisei-u.ac.jp/mirror/apache/dist//httpd/httpd-2.2.17.tar.gz
(2)ダウンロードしたhttpdを解凍する。
[root@example ~]# tar zxvf httpd-2.2.17.tar.gz
(3)httpdのインストールをする。
[root@example ~]# cd httpd-2.2.17 [root@example httpd-2.2.17]# ./configure --prefix=/usr/local/httpd --libexecdir=/usr/local/httpd/modules --sbindir=/usr/local/httpd/sbin --bindir=/usr/local/httpd/bin --localstatedir=/var/log/httpd --sysconfdir=/etc/httpd --enable-mods-shared=all --enable-suexec --with-suexec-bin=/usr/local/httpd/sbin/suexec --with-suexec-docroot=/var/www --with-suexec-caller=apache --enable-so --enable-ssl --with-ssl [root@example httpd-2.2.17]# make [root@example httpd-2.2.17]# make install※suexecについて
http://httpd.apache.org/docs/2.0/ja/suexec.html
ここでは、
・suexecを有効にする。
・suexecの実行範囲を「 /var/www」以下にする。
・suexecの実行ユーザを「apache」にする。
※必要なパッケージについて
・zlib-devel
・openssl-devel
・apr-util-devel
(5)起動スクリプトをコピーする。
[root@example httpd-2.2.17]# cp build/rpm/httpd.init /etc/rc.d/init.d/httpd [root@example httpd-2.2.17]# chmod +x /etc/rc.d/init.d/httpd
(6)起動スクリプトを編集する。
[root@example httpd-2.2.17]# vi /etc/rc.d/init.d/httpd #--以下を編集-- httpd=${HTTPD-/usr/sbin/httpd} ↓ # 変更 httpd=${HTTPD-/usr/local/httpd/sbin/httpd} pidfile=${PIDFILE-/var/log/httpd/httpd.pid} ↓ # 変更 pidfile=${PIDFILE-/var/log/httpd/logs/httpd.pid} CONFFILE=/etc/httpd/conf/httpd.conf ↓ # 変更 CONFFILE=/etc/httpd/httpd.conf
(7)apacheユーザを作成する。
[root@example ~]# groupadd -g 48 apache [root@example ~]# useradd -g apache -u 48 -s /sbin/nologin -d /var/www -M apache
(8)httpdの設定ファイルを編集する。
[root@example ~]# vi /etc/httpd/httpd.conf #ServerName www.example.com:80 ↓ # 任意の名前に変更 ServerName www.test.kurobuti.com:80 User daemon ↓ # 変更 User apache Group daemon ↓ # 変更 Group apache DocumentRoot "/usr/local/httpd/htdocs" ↓ # 変更 DocumentRoot "/var/www/html" <Directory /> Options FollowSymLinks AllowOverride None Order deny,allow ↓ # コメントアウト #Order deny,allow Deny from all ↓ # コメントアウト #Deny from allow </Directory>※ここでは、最低限な設定しかしていません。
(9)コンテンツを設置するDocumentRootを作成する。
[root@example ~]# mkdir -p /var/www/html
(10)httpdを起動する。
[root@example ~]# /etc/rc.d/init.d/httpd start httpd を起動中: [ OK ]※httpdが起動すること。
※DocumentRootにテストコンテンツを設置して、外部(又は内部)から見れること。
(11)httpdを自動で起動できるようにする。
[root@example ~]# chkconfig httpd on [root@example ~]# chkconfig --list httpd httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off※run level 2,3,4,5 が on になっていること。
・PHPインストール
(1)PHPをダウンロードする。
[root@example ~]# wget http://jp.php.net/get/php-5.3.5.tar.gz/from/this/mirror
(2)ダウンロードしたPHPを解凍する。
[root@example ~]# tar zxvf php-5.3.5.tar.gz
(3)PHPのインストールをする。
[root@example ~]# cd php-5.3.5 [root@example php-5.3.5]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/sbin/apxs --with-zlib-dir=/usr/lib --with-gd --enable-mbstring --enable-gd-native-ttf --enable-sqlite-utf8 [root@example php-5.3.5]# make [root@example php-5.3.5]# make test Do you want to send this report now? [Yns]: n [root@example php-5.3.5]# make install※ここでの必要なパッケージについて(上記ビルドオプションで必要)
・libxml2
・libxml2-devel
・libpng
・libpng-devel
(4)httpdの設定ファイルを編集する。
[root@example ~]# vi /etc/httpd/httpd.conf <Directory /> Options FollowSymLinks AllowOverride None AddType application/x-httpd-php .php .phtml ← # 追加 #Order deny,allow #Deny from all </Directory>
(5)httpdをリロードする。
[root@example ~]# /etc/rc.d/init.d/httpd reload httpd を再読み込み中: [ OK ]※DocumentRootにphpコンテンツを設置して外部(又は内部)から見れること。