LoginSignup
9
9

More than 5 years have passed since last update.

apache + PHP On Docker (ホームページ作成のお供に)

Last updated at Posted at 2017-02-07

デザイナの方にとって、phpも編集できるホームページ作成環境を使われることがあるとおもうんですが、その際、WEBサーバの構築が必須になります。
しかし、敷居も高くなるのでDockerをつかってコマンド一発で準備を整える方法をご紹介します。

埼玉越谷でこんなイベントもあるのでよろしければ

Docker Installation

お持ちのPCに合ったものインストールしてください
* Install On Mac
* Install On Windows
* Install On Linux

プロジェクトルートを作成

mkdir sample
cd sample
touch Dockerfile
touch docker-compose.yml
mkdir public-html
cd public-html
touch index.php

index.php編集

サンプルコードなので、ここはなんでもOK

index.php
<?php
phpinfo();

Dockerfile編集

Dockerfile
FROM centos:latest
RUN yum -y update && \
    yum -y install httpd php
WORKDIR /var/www/html
ADD ./public-html /var/www/html
EXPOSE 80

docker-compose 編集

docker-compose.yml
version: '2'
services:
  web: &app_base
    build:
      context: .
      dockerfile: "Dockerfile"
    command: /usr/sbin/httpd -D FOREGROUND
    volumes:
      - ./public-html:/var/www/html
    ports:
      - "80:80"
    tty: true
    stdin_open: true

イメージ(コンテナの雛形)作成

docker-compose build

コンテナを起動

docker-compose up

localhost :80 にアクセス

スクリーンショット_2017-02-07_1.43.56_PM.jpg

9
9
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
9
9