0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

dockerを使ったPHPの環境構築

Last updated at Posted at 2022-11-27

ただの覚書です。

docker-compose.yml

version: '3'
services:
  #MySQL用コンテナ
  mysql:
    container_name: db
    image: mariadb:10.4
    volumes:
#./dataフォルダに作成してる
      - ./data:/var/lib/mysql
    environment:
        - MYSQL_ROOT_PASSWORD=root
        - MYSQL_DATABASE=todo
        - MYSQL_USER=todo
        - MYSQL_PASSWORD=todo  
    ports:
        - 3306:3306
  #php用コンテナ
  php:
    container_name: php-apache
#./phpフォルダに作成してる
    build: ./php
    volumes:
#./sourceフォルダに作成
      - ./source:/var/www/html
      - .php/vhosts.conf:/etc/apache2/conf-enabled/vhosts.conf
    ports:
      - 8000:80
    depends_on:
      - mysql

Dockerfile

FROM php:8.1.12-apache
#php install
RUN apt update
RUN apt install -y wget git unzip libpq-dev
RUN apt install -y zlib1g-dev mariadb-client libzip-dev libonig-dev \
    && docker-php-ext-install zip pdo_mysql

#composerインストール
RUN curl -sS https://getcomposer.org/installer | php \
  && mv composer.phar /usr/local/bin/composer \
  && chmod +x /usr/local/bin/composer

#ワーキングディレクトリ(ここで動く)
WORKDIR /var/www/html

#基本的には変わらない↓
ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /composer
ENV PATH $PATH:/composer/vendor/bin
# タイムゾーン設定
ENV TZ=Asia/Tokyo
vhosts.conf
NameVirturalHost *:80
<VirtualHost *:80>
    ServerAdmin todo@localhost
    ServerName localhost
    DocumentRoot /var/www/html/public
    <Directory "/var/www/html/public">
        Options Indexes FollowSymLinks
         DirectoryIndex index.php
         AllowOverride All
         Require all granted
         Order allow,deny
         Allow from all
    </Directory>
</VirtualHost>
0
0
1

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?