Apache 更新至 2.4 幾個小問題

Debian 更新 Jessie 之後 Apache 也順道升級到 Apache 2.4
不過因為之前的設定不符新版本的規範 要修正幾個地方

a2ensite 啟動錯誤

$ sudo a2ensite blog

ERROR: Site blog does not exist!

這是因為設定檔必須加副檔名 .conf

mv /etc/apache2/sites-available/blog /etc/apache2/sites-available/blog.conf

啟動爆炸

$ sudo service apache2 start
Job for apache2.service failed. See 'systemctl status apache2.service' and 'journalctl -xn' for details.

然後去找一下問題

sudo systemctl status apache2.service                                                  1 ↵
● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2)
   Active: failed (Result: exit-code) since Mon 2015-04-27 14:49:01 CST; 2min 59s ago
  Process: 13061 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS)
  Process: 10368 ExecReload=/etc/init.d/apache2 reload (code=exited, status=0/SUCCESS)
  Process: 13114 ExecStart=/etc/init.d/apache2 start (code=exited, status=1/FAILURE)

Apr 27 14:49:01 de apache2[13114]: Starting web server: apache2 failed!
Apr 27 14:49:01 de apache2[13114]: The apache2 configtest failed. ... (warning).
Apr 27 14:49:01 de apache2[13114]: Output of config test was:
Apr 27 14:49:01 de apache2[13114]: AH00526: Syntax error on line 5 of /etc/apache2/sites-enabled/blog.conf:
Apr 27 14:49:01 de apache2[13114]: Either all Options must start with + or -, or no Option may.
Apr 27 14:49:01 de apache2[13114]: Action 'configtest' failed.
Apr 27 14:49:01 de apache2[13114]: The Apache error log may have more information.
Apr 27 14:49:01 de systemd[1]: apache2.service: control process exited, code=exited status=1
Apr 27 14:49:01 de systemd[1]: Failed to start LSB: Apache2 web server.
Apr 27 14:49:01 de systemd[1]: Unit apache2.service entered failed state.

解決方式 把設定檔裡面的 Option 後面加上 + –

Options +FollowSymLinks -Indexes

權限也爆炸了

終於啟動了 但是怎麼看都是 Forbidden

回頭看一下log

You don't have permission to access / on this server.
[Mon Apr 27 14:40:44.662774 2015] [authz_core:error] [pid 12400] [client 192.168.1.199:50394] 
AH01630: client denied by server configuration: /home/web/htdocs/index.php

因為我 DocumentRoot 沒有放在 /var/www/html 下面
所以爆炸了
解決方式是在 Directory 區段內加入 Require all granted
例如

[code highlight=”3″]
<Directory />
Options +FollowSymLinks -Indexes
Require all granted
</Directory>
[/code]
再重新啟動就好了

apache2.4文件是這麼寫的


2.2 configuration:

Order allow,deny
Allow from all

2.4 configuration:

Require all granted