2
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.

lumen開発環境構築めも(php,nginx,mysql)

Posted at

構成

lumen
 |_docker-compose.yml
 |_app.docker
 |_vhost.conf
 |_web.docker
 |_www

docker-compose.yml

version: '2'
services:
    web:
        build:
            context: ./
            dockerfile: web.docker
        volumes:
            - ./www:/var/www
        ports:
            - "8080:80"
        links:
            - app
    app:
        build:
            context: ./
            dockerfile: app.docker
        volumes:
            - ./www:/var/www
        links:
            - database
        environment:
            - "DB_PORT=3306"
            - "DB_HOST=database"
    database:
        image: mysql:latest
        environment:
            - "MYSQL_ROOT_PASSWORD=secret"
            - "MYSQL_DATABASE=dockerApp"
        ports:
            - "3306:3306"

appサーバー

Dockerfile

app.docker
FROM php:7-fpm

RUN apt-get update && apt-get install -y libmcrypt-dev mysql-client \
    && docker-php-ext-install mcrypt pdo_mysql && \

    #zip,unzip
    apt-get install -y zip unzip && \
   
    #vim
    apt-get install -y vim && \

    #composer
    curl -sS https://getcomposer.org/installer | php && \
    mv composer.phar /usr/local/bin/composer && \

    #user追加
    useradd -m -s /bin/bash -u 1000 meidaimae && \

    #www.conf修正
    sed -i 's/user\ \=\ www-data/user\ \=\ meidaimae/g' /usr/local/etc/php-fpm.d/www.conf && \
    sed -i 's/group\ \=\ www-data/group\ \=\ meidaimae/g' /usr/local/etc/php-fpm.d/www.conf
WORKDIR /var/www

共有ディレクトリ作成

mkdir www

webサーバー

Dockerfile

web.docker
FROM nginx:latest

RUN useradd -m -s /bin/bash -u 1000 meidaimae && \
# nginx.conf
sed -i 's/user\ \ nginx\;/user\ \ meidaimae\;/g' /etc/nginx/nginx.conf

ADD ./vhost.conf /etc/nginx/conf.d/default.conf
WORKDIR /var/www

confファイル作成

vhost.conf
server {
    listen 80;
    index index.php index.html;
    root /var/www/lumen/public;

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

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

起動

docker-compose up -d

プロジェクト作成

lumenインストール

# とりま、appサーバーに入る
docker exec -it lumen_app_1 bash

# んで、meidaimaeになってルーメンプロジェクト作成 

chown -R meidaimae:meidaimae /var/www
su meidaimae
composer create-project --prefer-dist laravel/lumen lumen


# /var/www以下ののディレクトリとファイルのアクセス権を変更
find /var/www -type d -exec chmod 770 {} \;
find /var/www -type f -exec chmod 770 {} \; 

続けて.env編集

以下の項目をそれぞれ変更

DB_DATABASE=dockerApp
DB_USERNAME=root

orm

lumenのormを有効にする

/var/www/lumen/bootstrap/app.php
# コメントアウトを外す
$app->withEloquent();

mysql接続確認

テーブルを作成。
test用なので、テキトー。どこかのをコピペしました。。
(後で直す!つもり)

cd /var/www/lumen
php artisan make:migration create_user


# 下記をlumen/www/lumen/database/migrationsに出来たファイルのupに追加
        Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->timestamps();
        });
# んで、
cd /var/www/lumen
php artisan migrate


vi /var/www/lumen/app/Http/routes.php
# んで、routes.phpに下記を追加
$app->get('/testDatabase', function() {
    App\User::create([
        'name' => 'Test User'
    ]);

    return response()->json(App\User::all());
});

ブラウザで確認

json返ってきてたら、まぁOK

課題(ちょくちょく編集予定)

全体的にオリジナルを増やす対応
データベース永続化対応
git対応
Redis対応
ー全然うまくいかず。。predisとかいれたりやったのにdenyされる。
皆どうやってるんやろ。。
UNIXドメインソケット対応
envなどのroot設定等を変更

2
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
2
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?