codeigniterでfile does not existが表示された場合の対処法

CentOSでLAMP環境を構築した後、すでに他のサーバーで動いているcodeigniterで開発した環境を移設した時の話。

新サーバーの環境は下記の通り
CentOS6.9
Apache2
PHP5.6
MySQL

といたって普通の構成。

この環境のパフォーマンスチェックを行うついでに、codeigniterで開発した環境を移設してみたところ、ブラウザでエラーが表示された。
Apacheのエラーログを見たところ、「file does not exist」と記録されていた。

codeigniterの環境はパスとDBへの情報を変更したほか、ルート情報等の変更は行っていない。
そもそも、ルート情報の変更等は既にほかで動いているので変える必要はない。。。

そこで疑ったのはApacheの設定。
解決するまでに数時間かかったが、原因は下記の通り。

.htaccess が有効になっていなかった!!

と言うわけで、「.htaccess」が使えるようにするため、httpd.conf を変更しました。

「httpd.conf 」は「/etc/httpd/conf/httpd.conf 」にあります。
約300行目付近の下記を変更しましょう。

<Directory "/var/www/html" >
#
# Possible values for the Options directive are “None”, “All”,
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that “MultiViews” must be named *explicitly* — “Options All”
# doesn’t give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
<del datetime="2017-07-30T12:52:27+00:00">AllowOverride None</del>
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
</Directory>
service httpd restart

httpd を再起動して正常に起動したらnot foundになっていたページを開いてみてください。

ちゃんと表示されるはずです。