apache2の設定

目次

全部は書かないけど

debianのapache2の設定方法はちょっと違うと言われる。3.1(sarge)の頃からdebianなので他のことはあまり知らない。

debianの中でも変化している。apacheの方針かdebianの流儀かは知らないが、少しずつ分割して書くようになってきた。理解すると楽に扱えるように思うが、前の書き方をコピーしても動くので、昔のまま解説しているものも多い。

今回はwheezy後、jessieをスキップしてstretchなのでちょっと変わったなと感ずる。

今回のハマりどころだけ書いておく。

/srv/wwwがForbidden

まず、/etc/apache2/sites-available/default これを書き換えたり、これを参考に設定ファイルを追加していくのだが、名前が変わって、内部に<Directory /var/www/html>...という部分がなくなっている。実はこうなったのはjessieからだった。

#で始まる注釈を除くと、スッキリしたもの。

root@debian64:~# cat /etc/apache2/sites-available/000-default.conf 
<VirtualHost *:80>
	#ServerName www.example.com
	ServerAdmin webmaster@localhost
	DocumentRoot /var/www/html
	ErrorLog ${APACHE_LOG_DIR}/error.log
	CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

今回はこれをこのままにして、001-debian64.conf としてコピーし内容を書き換えていった。

いつものように DocumentRoot を /srv/www/ と変えると、

Forbidden
You don't have permission to access /index.html on this server.

といわれる。フォルダやファイルのパーミッションはOK。

結局<Directory /var/www/html>...の中に許可を書かなければならないのだろうけれど、もともとの/var/www/htmlについての許可はどこに書いてあるのかという問題になる。

<Directory>がこんなところに

分割されてきたためにほとんど中を見る必要のなかった apache2.conf 内にあった。

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
	Options FollowSymLinks
	AllowOverride None
	Require all denied
</Directory>

<Directory /usr/share>
	AllowOverride None
	Require all granted
</Directory>

<Directory /var/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

#<Directory /srv/>
#	Options Indexes FollowSymLinks
#	AllowOverride None
#	Require all granted
#</Directory>

こんなふうにしました。

<Directory /srv/www/>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

php

phpのパッケージをインストール

Commit Log for Wed Jul 11 16:54:45 2018
以下のパッケージがインストールされました:
libapache2-mod-php7.0 (7.0.30-0+deb9u1)
php (1:7.0+49)
php-common (1:49)
php7.0 (7.0.30-0+deb9u1)
php7.0-cli (7.0.30-0+deb9u1)
php7.0-common (7.0.30-0+deb9u1)
php7.0-json (7.0.30-0+deb9u1)
php7.0-opcache (7.0.30-0+deb9u1)
php7.0-readline (7.0.30-0+deb9u1)

これだけでmodの設定もしてくれた

lrwxrwxrwx 1 root root 29  7月 11 16:55 php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29  7月 11 16:55 php7.0.load -> ../mods-available/php7.0.load

debianの歴史

vercode namedate
3.1sarge2005年6月6日
4.0etch2007年4月8日
5.0lenny2009年2月14日
6.0squeeze2011年2月6日
7.0wheezy2013年5月4日
8.0jessie2015年4月25日
9.0stretch2017年6月17日