LoginSignup
0
0

More than 3 years have passed since last update.

DockerでApacheとPHPをとりあえず動かす

Last updated at Posted at 2019-05-13

ディレクトリ構造

app
├── Dockerfile
└── html
    └── index.php

Dockerfile

EXPOSE をしないとYou don't have permission to access / on this server.のエラーによりサイトにアクセスできません。

FROM php:7.2.7-apache
EXPOSE 80

index.php

index.php
<form method="POST" action="index.php">
    <label for="name">名前:</label>
    <input type="text" name="name" size="15" />
    <input type="submit" name="submit" value="送信" />
</form>

<?php
if ($_REQUEST['submit'] !== null) {
    print('こんにちは、'. htmlspecialchars($_POST['name'], ENT_QUOTES | ENT_HTML5, 'UTF-8').'さん!');
}
?>

1. ビルド

appディレクトリ上
docker build ./ -t php_apache_image:ver001

2. 実行

appディレクトリ上
docker run -d -p 80:80 -v {htmlディレクトリまでのabsolute path}:/var/www/html --name php_apache_container php_apache_image:ver001

docker run -d -p 80:80 -v /Users/cassin/MyProjects/app/html:/var/www/html --name php_apache_container php_apache_image:ver001

3. サイトにアクセス

参考

Dockerの開発環境構築 (Mac + Docker + PHP + Apache)
山田祥寛 改訂版JavaScript本格入門

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0