からの記事となります。
1.Debianインストール+ウイルス対策
2.NTP
3.FTP
4.SSH
5.Apache2
6.MYSQL5
7.PHP5
8.PHPとMYSQLの連携
この記事は5になります。
いよいよWEBサーバの設定だ。
まずはインストール
# aptitude install apache2
表示の確認
ブラウザで、
http://サーバ名もしくはIPアドレス/
へアクセスし、apacheの初期画面が出てくればOK。
DebianはRedhatと設定ファイル構成が違う
httpd.confファイルは存在するがダミーっぽい。
apache2.confとsites-available/の中のdefaultをコピーしたファイルで設定するようだ。
apache2.confの設定
# vi /etc/apache2/apache2.conf
開いた先頭行に、
ServerName サーバ名
を追加する。
ディレクトリインデックスファイル名にindex.htmと一応index.php3も追加しておく。
#DirectoryIndex index.html index.cgi index.pl index.php index.xhtml
DirectoryIndex index.html index.htm index.cgi index.pl index.php index.php3 index.xhtml
DirectoryIndex index.html index.htm index.cgi index.pl index.php index.php3 index.xhtml
デフォルトキャラセットの設定
#AddDefaultCharset ISO-8859-1
AddDefaultCharset off
AddDefaultCharset off
後でPHPを入れるので
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
この2行のコメントを外す
#AddType application/x-httpd-php-source .phps
この2行のコメントを外す
こんな感じでapache2.confの設定終わり。
sites-available/の下のdefaultを編集
sites-available/の下のdefaultをコピーして好きな名前を付けてそれを編集する。
これはデフォルト設定にいつでも簡単に戻せる為かなぁ。
# cd /etc/apache2/sites-available/
# cp default hogehoge
# vi hogehoge
# cp default hogehoge
# vi hogehoge
コメントを外して自分の設定に。
#ServerAdmin webmaster@localhost
ServerAdmin hoge@localhost
ServerAdmin hoge@localhost
ドキュメントルートを変えたい場合は変更をかける。
#DocumentRoot /var/www/
DocumentRoot /var/www/html/
DocumentRoot /var/www/html/
#<Directory /var/www/>
<Directory /var/www/html/>
<Directory /var/www/html/>
ディレクトリ内にインデックスファイルがない場合中身が丸見えになってしまうので、見えないようにする。
Options Indexes FollowSymLinks MultiViews
のIndexesにハイフンをつけて-Indexesとする
Options -Indexes FollowSymLinks MultiViews
ルートがリダイレクトしないように
RedirectMatch ^/$ /apache2-default/
をコメントアウト
#RedirectMatch ^/$ /apache2-default/
をコメントアウト
#RedirectMatch ^/$ /apache2-default/
こんな感じで設定終了。
サイト定義ファイルの有効化
最初はdefaultファイルを使用するようにリンクが貼られているようなのでまずはそれを破棄する。
# a2dissite default
先程設定したhogehogeファイルにリンクを貼りそれを読み込むように設定する
# a2ensite hogehoge
ドキュメントルートを作成
# mkdir /var/www/html
データなどをUPするユーザを所有者にする
# chown user /var/www/html
apache2を再起動
# /etc/init.d/apache2 restart
これで先程ブラウザで開いたページ
http://サーバ名もしくはIPアドレス/
をもう一度開いてみると
Forbidden
You don't have permission to access / on this server.
apacheのバージョン等
You don't have permission to access / on this server.
apacheのバージョン等
となり、表示されないようになる。
apacheのバージョン等も非表示にしたい場合
apache2.confを開き最終行にでも
ServerTokens ProductOnly
ServerSignature Off
ServerSignature Off
と記述してapache2を再起動すればOK。
Redhatと違うので少し心配だったが設定自体は何の事はなかった。