1
1

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 5 years have passed since last update.

docker、nginx-proxy、letsencrypt環境でlaravelするまで

Last updated at Posted at 2018-06-27

docker、nginx-proxy、letsencryptでとりあえずredmineするまでで作った環境でlaravelしたい

wordpressしたい場合はこっち
docker、nginx-proxy、letsencrypt環境でwordpressするまで

├── laravel(new)
│   ├──docker-compose.yml
│   ├──php
|   |  └──Dockerfile
│   └──nginx
|      └──default.conf
├── redmine
│   └── docker-compose.yml
└── shared
    └── docker-compose.yml
laravel/docker-compose.yml

version: '2'

services:
  nginx:
    image: nginx
    external_links:
      - mysql
    container_name: "laravel-nginx"
    volumes:
      - ./src:/src
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    environment:
      VIRTUAL_HOST: 〇〇.com
      LETSENCRYPT_HOST: 〇〇.com
      LETSENCRYPT_EMAIL: 〇〇@〇〇.com
    restart: always
  php:
    build: ./php
    container_name: "laravel-php"
    volumes:
      - ./src:/src
    restart: always

networks:
  default:
    external:
      name: shared

laravel/php/Dockerfile.

FROM php:7.2.6-fpm

RUN apt-get update \
  && apt-get install -y zlib1g-dev \
  && docker-php-ext-install zip

RUN php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" \
  && php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" \
  && php composer-setup.php \
  && php -r "unlink('composer-setup.php');" \
  && mv composer.phar /usr/local/bin/composer

ENV COMPOSER_ALLOW_SUPERUSER 1
ENV COMPOSER_HOME /composer
ENV PATH $PATH:/composer/vendor/bin

RUN composer global require "laravel/installer"

RUN apt-get update \
  && apt-get install -y libpq-dev \
  && docker-php-ext-install pdo_mysql

RUN apt-get update \
  && apt-get install -my wget gnupg

RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - \
  && apt-get update \
  && apt-get install -y nodejs

WORKDIR /src

nginx/default.conf

server {
  listen 80;
  server_name localhost;
  index index.php index.html;
  root /src/public/;

  location / {
    try_files $uri $uri/ /index.php?$query_string;
  }

  location ~ \.php$ {
    try_files $uri = 404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass laravel-php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
  }
}

インストールとかする

cd laravel
docker-compose build
docker-compose up -d
cd src
composer install
npm install

.env.exampleをコピーして.envを編集

cp .env.example .env
.env.
DB_CONNECTION=mysql
DB_HOST=mysql
DB_PORT=3306
DB_DATABASE=root
DB_USERNAME=root
DB_PASSWORD=root

migrate
パーミッションを変更しないといけなかったかもしれない(忘れた)

docker-compose exec php php artisan key:generate
docker-compose exec php php artisan migrate
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?