TOP >> centos >> Apacheサーバー構築(ソースコンパイル)

Apacheサーバー構築(ソースコンパイル)の概要

Webサーバー(Apache)はInternet Explorer等のブラウザから
Webページをみれるようにするためのサーバー。

ここでは、ホームページスペース提供サービスを行っている
一般的なWebサーバーと同様に以下のことができるようにする。

 ・CGIは任意のディレクトリで実行できるようにする
 ・SSIは拡張子がshtmlのもののみ実行できるようにする
 ・.htaccessを使用できるようにする
 ・PHPを使用できるようにする

Webサーバーインストール

ソース配布元 Apache
インストールディレクトりは/usr/local/としてます

[root@centos ~]# rpm -e --allmatches --nodeps httpd ← RPM版のapacheを削除する
						
[root@centos ~]# cd /usr/local/src/ ← 移動する

[root@centos src]# wget http://www.meisei-u.ac.jp/mirror/apache/httpd/httpd-2.0.59.tar.gz ← ダウンロード

[root@centos src]# tar zxvf httpd-2.0.59.tar.gz ← 解凍

[root@centos httpd-2.0.59]# cd httpd-2.0.59 ← 移動する

[root@centos httpd-2.0.59]# ./configure --enable-so --enable-shared --with-mpm=worker --enable-deflate --enable-headers ← コンパイル

[root@centos httpd-2.0.59]# make

[root@centos httpd-2.0.59]# make install ← インストール

[root@centos httpd-2.0.59]# /usr/local/apache2/bin/apachectl start ← apacheを起動してみる

.htaccessを有効にする

[ .htaccess ] とは Apacheで使用できる、Webサーバの設定をディレクトリ単位で制御するためのファイルになります。
[ .htaccess ] ファイルで設定した内容は、そのファイルを設置したディレクトリと、それ以下の全てのページに有効となります。

例えば、[ public_html ] に [ .htaccess ] ファイルを設置した場合、 [ public_html ] 内の全てのページ及び、
[ public_html ] 以下のディレクトリにある全てのページ(サブディレクトリ全体)が [ .htaccess ] ファイルの影響を受けます。

[root@centos ~]# vi /usr/local/apache2/conf/http.conf ← viコマンドでhttpd.confを編集
設定ファイルを編集する場合は一応コピーしておきましょう

この箇所を探しましょう
</Directory>
Options FollowSymLinks
AllowOverride None
<Directory/>

このように編集します
</Directory>
Options All
AllowOverride All
<Directory/>
[root@centos ~]# vi /var/www/html/index.html ← テストページ作成
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">※システムの文字コードがUTF-8の場合
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">※システムの文字コードがEUCの場合
<title>テスト</title>
<body>
テスト
</body>
</html>
					


(2)CGI確認
CGIで簡単なテストページを表示してみる。

[root@centos ~]# vi /var/www/html/test.cgi ← テスト用CGI作成
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">\n";※システムの文字コードがUTF-8の場合
print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=euc-jp\">\n";※システムの文字コードがEUCの場合
print "<title>テスト</title>\n";
print "</head>\n";
print "<body>\n";
print "CGIテスト\n";
print "</body>\n";
print "</html>\n";

[root@centos ~]# chmod 755 /var/www/html/test.cgi ← テスト用CGIパーミッション変更

				

(4).htaccess確認

[root@centos ~]# vi /var/www/html/.htaccess ← .htaccessファイル作成
DirectoryIndex index.shtml

[root@centos ~]# vi /var/www/html/index.shtml ← .htaccessテスト用ページ作成
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">※システムの文字コードがUTF-8の場合
<meta http-equiv="Content-Type" content="text/html; charset=euc-jp">※システムの文字コードがEUCの場合
<title>テスト</title>
<body>
<p>.htaccessによるWebサーバ設定(例としてDirectoryIndex)の変更テスト</p>
このページのファイル名は<!--#echo var="DOCUMENT_NAME" -->
</body>
</html>