LoginSignup
3
5

More than 5 years have passed since last update.

Alpine Linux3.5で php-fpm7 (socket) + nginx

Last updated at Posted at 2016-12-29
docker run --rm -it -v `pwd`/www/:/var/www/loaclhost/htdocs/ -p 8080:80 tukiyo3/alpine-nginx-php7

今回用意するファイル

ファイル 説明
Dockerfile nginx, php-fpm7 のインストール
docker-compose.yml nginx, php-fpm7 の起動
conf/php-fpm7.conf php-fpm7 の sock 生成
conf/nginx.conf nginx で php-fpm7 の sock 指定
conf/php.ini timezoneなど設定
www/ /var/www/localhost/htdocs/

設定

Dockerfile
FROM alpine:3.5

RUN apk update
RUN apk add --no-cache nginx php7-fpm certbot
RUN mkdir /run/nginx/
docker-compose.yml
http:
  #image: alpine:3.5
  image: 8b66a33e6a8d
  restart: always
  ports:
   - "80:80"
   #- "443:443"
  volumes:
   - /etc/localtime:/etc/localtime:ro
   - ./www/:/var/www/localhost/htdocs/:ro

   - ./conf/nginx.conf:/etc/nginx/conf.d/nginx.conf:ro
   - ./conf/php-fpm7.conf:/etc/php7/php-fpm.d/www.conf:ro
   - ./conf/php.ini:/etc/php7/conf.d/php.ini:ro

   #- ./cron/:/var/spool/cron/crontabs/
  command: sh -c "cd /usr/sbin; nginx; php-fpm7; crond -f -l 2"
conf/nginx.conf
server {
    listen 80 default_server;

    root /var/www/localhost/htdocs;
    index index.php index.html index.htm;

    server_name localhost;

    location / {
        if (-f $request_filename) {
            expires 30d;
            break;
        }
    }

    location ~ [^/]\.php(/|$) {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        if (!-f $document_root$fastcgi_script_name) {
            return 404;
        }
        fastcgi_pass unix:/var/run/php7-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
    }
}
  • listen = 127.0.0.1:9000 をやめて sock にする。
conf/php-fpm7.conf
[www]
user = nginx
group = nginx

listen = /var/run/php7-fpm.sock
listen.owner = nginx  
listen.group = nginx

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
conf/php.ini
[Date]
date.timezone = Asia/Tokyo

起動

docker-compose up -d
shellを起動する場合
docker-compose exec http sh
3
5
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
3
5