質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

Q&A

解決済

1回答

948閲覧

php:apacheでautoindex_moduleが有効にならない?

FoolHotari

総合スコア79

Apache

Apacheは、Apache HTTP Serverの略で、最も人気の高いWebサーバソフトウェアの一つです。安定性が高いオープンソースソフトウェアとして商用サイトから自宅サーバまで、多くのプラットフォーム向けに開発・配布されています。サーバーソフトウェアの不具合(NCSA httpd)を修正するパッチ(a patch)を集積、一つ独立したソフトウェアとして開発されました。

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

Docker

Dockerは、Docker社が開発したオープンソースのコンテナー管理ソフトウェアの1つです

0グッド

0クリップ

投稿2023/05/28 07:03

実現したいこと

  • php:apacheでドキュメントルート以下の任意のファイルを表示させる
  • index.*がないディレクトリではディレクトリリストを表示させる

前提

いろいろなPHPファイルを簡単に実行して試せる環境を作りたいと思っています。
Dockerでphp:apacheイメージを含むコンテナを作成しました。
index.*がないパスでは403エラーになりました。

autoindexを有効にしてディレクトリリストを表示させるにはどうすればいいのかご教授願います。

発生している問題・エラーメッセージ

http://localhost:8000/

1Forbidden 2You don't have permission to access this resource. 3 4Apache/2.4.56 (Debian) Server at localhost Port 8000

log

1Attaching to name 2name | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message 3name | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message 4name | [Sun May 28 06:45:53.417048 2023] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.56 (Debian) PHP/8.2.6 configured -- resuming normal operations 5name | [Sun May 28 06:45:53.417105 2023] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'

該当のソースコード

docker

1version: '3.8' 2services: 3 php: 4 container_name: name 5 image: php:apache 6 volumes: 7 - ./src:/var/www/html 8 - ./config/apache:/usr/local/apache2/conf 9 ports: 10 - 8000:80

config/apache/httpd.conf

1LoadModule autoindex_module modules/mod_autoindex.so

src/phpinfo.php

1<?php 2 3phpinfo();

http://localhost:8000/phpinfo.php

1PHP logo 2PHP Version 8.2.6 3System Linux b2abb5b31a3e 5.15.90.1-microsoft-standard-WSL2 #1 SMP Fri Jan 27 02:56:13 UTC 2023 x86_64 4Build Date May 23 2023 09:41:46 5Build System Linux d4bc11463019 5.10.0-13-cloud-amd64 #1 SMP Debian 5.10.106-1 (2022-03-17) x86_64 GNU/Linux 6Configure Command './configure' '--build=x86_64-linux-gnu' '--with-config-file-path=/usr/local/etc/php' '--with-config-file-scan-dir=/usr/local/etc/php/conf.d' '--enable-option-checking=fatal' '--with-mhash' '--with-pic' '--enable-ftp' '--enable-mbstring' '--enable-mysqlnd' '--with-password-argon2' '--with-sodium=shared' '--with-pdo-sqlite=/usr' '--with-sqlite3=/usr' '--with-curl' '--with-iconv' '--with-openssl' '--with-readline' '--with-zlib' '--disable-phpdbg' '--with-pear' '--with-libdir=lib/x86_64-linux-gnu' '--disable-cgi' '--with-apxs2' 'build_alias=x86_64-linux-gnu' 7Server API Apache 2.0 Handler 8Virtual Directory Support disabled 9Configuration File (php.ini) Path /usr/local/etc/php 10Loaded Configuration File (none) 11Scan this dir for additional .ini files /usr/local/etc/php/conf.d 12Additional .ini files parsed /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini 13PHP API 20220829 14PHP Extension 20220829 15Zend Extension 420220829 16Zend Extension Build API420220829,NTS 17PHP Extension Build API20220829,NTS 18Debug Build no 19Thread Safety disabled 20Zend Signal Handling enabled 21Zend Memory Manager enabled 22Zend Multibyte Support provided by mbstring 23Zend Max Execution Timers disabled 24IPv6 Support enabled 25DTrace Support disabled 26Registered PHP Streams https, ftps, compress.zlib, php, file, glob, data, http, ftp, phar 27Registered Stream Socket Transports tcp, udp, unix, udg, ssl, tls, tlsv1.0, tlsv1.1, tlsv1.2, tlsv1.3 28Registered Stream Filters zlib.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, convert.*, consumed, dechunk 29Zend logoThis program makes use of the Zend Scripting Language Engine: 30Zend Engine v4.2.6, Copyright (c) Zend Technologies 31Configuration 32apache2handler 33Apache Version Apache/2.4.56 (Debian) 34Apache API Version 20120211 35Server Administrator webmaster@localhost 36Hostname:Port 172.24.0.3:80 37User/Group www-data(33)/33 38Max Requests Per Child: 0 - Keep Alive: on - Max Per Connection: 100 39Timeouts Connection: 300 - Keep-Alive: 5 40Virtual Server Yes 41Server Root /etc/apache2 42Loaded Modules core mod_so mod_watchdog http_core mod_log_config mod_logio mod_version mod_unixd mod_access_compat mod_alias mod_auth_basic mod_authn_core mod_authn_file mod_authz_core mod_authz_host mod_authz_user mod_autoindex mod_deflate mod_dir mod_env mod_filter mod_mime prefork mod_negotiation mod_php mod_reqtimeout mod_setenvif mod_status 43Directive Local Value Master Value 44engine On On 45last_modified Off Off 46xbithack Off Off 47Apache Environment 48Variable Value 49HTTP_HOST localhost:8000 50HTTP_CONNECTION keep-alive 51HTTP_SEC_CH_UA "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24" 52HTTP_SEC_CH_UA_MOBILE ?0 53HTTP_SEC_CH_UA_PLATFORM "Windows" 54HTTP_DNT 1 55HTTP_UPGRADE_INSECURE_REQUESTS 1 56HTTP_USER_AGENT Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 57HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 58HTTP_SEC_FETCH_SITE none 59HTTP_SEC_FETCH_MODE navigate 60HTTP_SEC_FETCH_USER ?1 61HTTP_SEC_FETCH_DEST document 62HTTP_ACCEPT_ENCODING gzip, deflate, br 63HTTP_ACCEPT_LANGUAGE ja,en;q=0.9 64HTTP_COOKIE phpMyAdmin=4d288d3bece7895a9aad25518e619ca7; pma_lang=ja 65PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin 66SERVER_SIGNATURE <address>Apache/2.4.56 (Debian) Server at localhost Port 8000</address> 67SERVER_SOFTWARE Apache/2.4.56 (Debian) 68SERVER_NAME localhost 69SERVER_ADDR 172.24.0.3 70SERVER_PORT 8000 71REMOTE_ADDR 172.24.0.1 72DOCUMENT_ROOT /var/www/html 73REQUEST_SCHEME http 74CONTEXT_PREFIX no value 75CONTEXT_DOCUMENT_ROOT /var/www/html 76SERVER_ADMIN webmaster@localhost 77SCRIPT_FILENAME /var/www/html/phpinfo.php 78REMOTE_PORT 52602 79GATEWAY_INTERFACE CGI/1.1 80SERVER_PROTOCOL HTTP/1.1 81REQUEST_METHOD GET 82QUERY_STRING no value 83REQUEST_URI /phpinfo.php 84SCRIPT_NAME /phpinfo.php 85HTTP Headers Information 86HTTP Request Headers 87HTTP Request GET /phpinfo.php HTTP/1.1 88Host localhost:8000 89Connection keep-alive 90sec-ch-ua "Google Chrome";v="113", "Chromium";v="113", "Not-A.Brand";v="24" 91sec-ch-ua-mobile ?0 92sec-ch-ua-platform "Windows" 93DNT 1 94Upgrade-Insecure-Requests 1 95User-Agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 96Accept text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 97Sec-Fetch-Site none 98Sec-Fetch-Mode navigate 99Sec-Fetch-User ?1 100Sec-Fetch-Dest document 101Accept-Encoding gzip, deflate, br 102Accept-Language ja,en;q=0.9 103Cookie phpMyAdmin=4d288d3bece7895a9aad25518e619ca7; pma_lang=ja 104HTTP Response Headers 105X-Powered-By PHP/8.2.6

試したこと

name

1# ls -la /var/www/html 2total 4 3drwxrwxrwx 1 www-data www-data 512 May 28 06:17 . 4drwxr-xr-x 1 root root 4096 May 23 09:36 .. 5-rwxrwxrwx 1 www-data www-data 17 May 28 04:31 phpinfo.php 6 7# apachectl -M 8AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.26.0.2. Set the 'ServerName' directive globally to suppress this message 9Loaded Modules: 10 core_module (static) 11 so_module (static) 12 watchdog_module (static) 13 http_module (static) 14 log_config_module (static) 15 logio_module (static) 16 version_module (static) 17 unixd_module (static) 18 access_compat_module (shared) 19 alias_module (shared) 20 auth_basic_module (shared) 21 authn_core_module (shared) 22 authn_file_module (shared) 23 authz_core_module (shared) 24 authz_host_module (shared) 25 authz_user_module (shared) 26 autoindex_module (shared) 27 deflate_module (shared) 28 dir_module (shared) 29 env_module (shared) 30 filter_module (shared) 31 mime_module (shared) 32 mpm_prefork_module (shared) 33 negotiation_module (shared) 34 php_module (shared) 35 reqtimeout_module (shared) 36 setenvif_module (shared) 37 status_module (shared)

config/apache/httpd.conf

1LoadModule autoindex_module modules/mod_autoindex.so 2 3<Directory "/var/www/html"> 4 Options Indexes FollowSymLinks 5 AllowOverride All 6 Require all granted 7 DirectoryIndex index.php index.html 8</Directory>

docker

1 command: 2 - apache2-foreground -D FOREGROUND 3 - a2enmod autoindex

補足情報(FW/ツールのバージョンなど)

Windows 11 Home 22H2 22621.1778
Docker 4.19.0 (106363)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

httpd.confが読み込まれていないことが原因でした。

docker

1 volumes: 2 - ./config/apache/httpd.conf:/etc/apache2/mods-enabled/httpd.conf

httpd.conf

1<Directory "/var/www/html"> 2 Options All 3 AllowOverride None 4 Require all granted 5</Directory>

投稿2023/05/31 03:00

FoolHotari

総合スコア79

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問