Cloud9でhtaccessが効かない

なぜだか効かない

 

Apacheでhtaccessが効かない対処法【有効化手順】 | PisukeCode - Web開発まとめ

 

.htaccess】Options / DirectoryIndex ディレクティブ | Hazu Labo

 

$ httpd -V
Server version: Apache/2.4.54 (Amazon)
Server built: Jun 30 2022 11:28:47
Server's Module Magic Number: 20120211:124
Server loaded: APR 1.6.3, APR-UTIL 1.5.4, PCRE 8.21 2011-12-12
Compiled using: APR 1.6.3, APR-UTIL 1.5.4, PCRE 8.21 2011-12-12
Architecture: 64-bit
Server MPM: prefork
threaded: no
forked: yes (variable process count)
Server compiled with....
-D APR_HAS_SENDFILE
-D APR_HAS_MMAP
-D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
-D APR_USE_SYSVSEM_SERIALIZE
-D APR_USE_PTHREAD_SERIALIZE
-D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
-D APR_HAS_OTHER_CHILD
-D AP_HAVE_RELIABLE_PIPED_LOGS
-D DYNAMIC_MODULE_LIMIT=256
-D HTTPD_ROOT=\"/etc/httpd\"
-D SUEXEC_BIN=\"/usr/sbin/suexec\"
-D DEFAULT_PIDLOG=\"/var/run/httpd/httpd.pid\"
-D DEFAULT_SCOREBOARD=\"logs/apache_runtime_status\"
-D DEFAULT_ERRORLOG=\"logs/error_log\"
-D AP_TYPES_CONFIG_FILE=\"conf/mime.types\"
-D SERVER_CONFIG_FILE=\"conf/httpd.conf\"
$ ll /etc/httpd/conf/httpd.conf
-rw-r--r-- 1 root root 11753 Aug 6 14:42 /etc/httpd/conf/httpd.conf
$ tail -2 /etc/httpd/conf/httpd.conf
# Load config files in the \"/etc/httpd/conf.d\" directory, if any.
IncludeOptional conf.d/*.conf
$ cat /etc/httpd/conf.d/custom_httpd.conf

DocumentRoot \"/home/ec2-user/environment/xxxxxx/public\"

<Directory /home/ec2-user/environment/xxxxxx/public>
AllowOverride All
Options -Indexes
</Directory>
$

 

 

AWSに問い合わせたが、apacheの話になるのでエンタープライズプランでないと調査できないと回答があった。

 

自分で改めて調べたが、やはり解決できない。

本番環境(ec2)と、テスト環境(ec2)はhtaccessが効く。

開発環境(cloud9)で効かない。htaccessを使って、末尾にスラッシュがある場合はリダイレクトさせたいんだが。

 

 

$ httpd -V

httpd.conの場所を確認。

-D HTTPD_ROOT="/etc/httpd"

-D SERVER_CONFIG_FILE="conf/httpd.conf"

 

httpd.confをcatして、本番との差分を確認。

$ ll /etc/httpd/conf/httpd.conf

 

差分は3箇所。

追加設定はdevも本番も以下で実施してる。

$ ll /etc/httpd/conf.d/custom_httpd.conf 

 

devも本番も以下の設定をcustom_httpd.conf に入れているが、

cloud9のdev環境でのみ効かない。

DocumentRoot "/home/ec2-user/environment/xxxxxx/public"

<Directory /home/ec2-user/environment/xxxxxx/public>
  AllowOverride All
  Options -Indexes
</Directory>

 

再起動

$ sudo service httpd restart

$ php artisan config:cache

https://qiita.com/qwe001/items/5922027fe50aacae10ad#%E8%BF%BD%E8%A8%9820200730

 

差分確認

$ diff /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org 

$ diff /etc/httpd/conf.d/custom_httpd.conf /etc/httpd/conf.d/custom_httpd.conf.orgYYYY 

 

 

恐らく、cloud9でLaravelを使ってるから、httpdの設定は関係ないんだと思う。

以下でサーバを擬似的に起動してるから。

$ php artisan serve --port=8080

 

custom_httpd.conf をすべてコメントアウトして、

/etc/httpd/conf/httpd.confのドキュメントルートを以下のままにしても、

問題なく接続可能だからな。

DocumentRoot "/var/www/html"

 

dev環境のドキュメントルートは、

/home/ec2-user/environment/xxxxxx/public

なのに。

 

 

というわけで、

$ php artisan serve 

のオプション設定か、

.env

の設定で実施してやる必要がありそう。

 

 

たぶん無理そうだな。

php - Laravel 5.4 artisan serve htaccess / and Routes::get for existing folders at /public - Stack Overflow

PHP has a basic web server feature. this server feature is what is used when you run php artisan serve.

.htaccess is an Apache server feature not a PHP feature.

PHP is not built to be a full blown web server so it doesn't have all the configuration options you would find on say Apache or Nginx

 

htaccessはApacheの機能だから、PHPの機能であるphp artisan serverでは使えないよということみたい。 

しかし、使えないとなると、htaccessの変更確認をdev環境では行えないということだな。

うーむ不便だ。