PodmanでLEMP環境を作る

LEMPとは

LEMPとは Linux+Nginx+MariaDB(MySql)+PHP 環境の事

LEMP環境用のポッド作成

ポート指定は使っていないポートで

podman pod create --name lemp-pod -p 39080:80 -p 39081:8080

Nginxのコンテナ作成

ダミーコンテナを作成し設定ファイル取り出し

mkdir -p \
  /srv/podman/lemp-pod/nginx/conf.d \
  /srv/podman/lemp-pod/public
podman run -d --name tmp docker.io/library/nginx:latest
podman cp tmp:/etc/nginx/nginx.conf /srv/podman/lemp-pod/nginx/nginx.conf
podman cp tmp:/etc/nginx/conf.d/default.conf /srv/podman/lemp-pod/nginx/conf.d/default.conf
podman rm -f tmp

Nginxコンテナの作成

podman create --pod lemp-pod --name lemp-nginx \
  -v /srv/podman/lemp-pod/nginx/nginx.conf:/etc/nginx/nginx.conf \
  -v /srv/podman/lemp-pod/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf \
  -v /srv/podman/lemp-pod/public:/usr/share/nginx/html \
  docker.io/library/nginx:latest

PHP-FPMのコンテナ作成

ダミーコンテナを作成し設定ファイル取り出し

mkdir -p /srv/podman/lemp-pod/php/conf.d
podman run -d --name tmp-php php:fpm-alpine
podman cp tmp-php:/usr/local/etc/php/php.ini-production /srv/podman/lemp-pod/php/php.ini
podman rm -f tmp-php

PHP-FPMコンテナの作成

podman create --pod lemp-pod --name lemp-phpfpm \
  -v /srv/podman/lemp-pod/php/php.ini:/usr/local/etc/php/php.ini:ro \
  -v /srv/podman/lemp-pod/public:/usr/share/nginx/html \
  php:fpm-alpine

MariaDBのコンテナ作成

DB用のフォルダ作成

mkdir -p /srv/podman/lemp-pod/mariadb

MariaDBコンテナの作成

podman create --pod lemp-pod --name lemp-db \
  --restart=unless-stopped \
  -e MARIADB_ROOT_PASSWORD="password" \
  -v /srv/podman/lemp-pod/mariadb:/var/lib/mysql \
  docker.io/library/mariadb:latest

phpMyAdminのコンテナ作成

podman create --pod lemp-pod --name lemp-phpmyadmin \
  -e PMA_HOST="127.0.0.1" \
  -e APACHE_PORT=8080 \
  docker.io/library/phpmyadmin:latest

ファイル設定

PHP-FPMの呼び出し設定

server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

仮ページの作成

<?php
    phpinfo();

コンテナの起動

podman pod start lemp-pod

PHP情報ページ(localhost:39080)

phpMyAdmin(localhost:39081)

コンテナ作成用スクリプト

#! /bin/bash

# ポッド、コンテナ名
PodName='lemp'
# webポート
WebPort='39080'
# phpMyAdminポート
PhpMyAdminPort='39081'

# 起動済みのポッド削除
echo ポッド削除
podman pod stop ${PodName}-pod
podman pod rm ${PodName}-pod

# ポッド作成
echo ポッド作成
podman pod create --name ${PodName}-pod -p ${WebPort}:80 -p ${PhpMyAdminPort}:8080
# nginx
podman create --pod ${PodName}-pod --name ${PodName}-nginx \
  -v /srv/podman/${PodName}-pod/nginx/nginx.conf:/etc/nginx/nginx.conf:ro \
  -v /srv/podman/${PodName}-pod/nginx/conf.d/default.conf:/etc/nginx/conf.d/default.conf:ro \
  -v /srv/podman/${PodName}-pod/public:/usr/share/nginx/html \
  docker.io/library/nginx:latest
# php-fpm
podman create --pod ${PodName}-pod --name ${PodName}-phpfpm \
  -v /srv/podman/${PodName}-pod/php/php.ini:/usr/local/etc/php/php.ini:ro \
  -v /srv/podman/${PodName}-pod/public:/usr/share/nginx/html \
  php:fpm-alpine
# mariadb
podman create --pod ${PodName}-pod --name ${PodName}-db \
  --restart=unless-stopped \
  -e MARIADB_ROOT_PASSWORD="password" \
  -v /srv/podman/lemp-pod/mariadb:/var/lib/mysql \
  docker.io/library/mariadb:latest
# phpMyAdmin
podman create --pod ${PodName}-pod --name ${PodName}-phpmyadmin \
  -e PMA_HOST="127.0.0.1" \
  -e APACHE_PORT=8080 \
  docker.io/library/phpmyadmin:latest

# ポッド起動
echo ポッド起動
podman pod start ${PodName}-pod

echo Finish!

コメント

タイトルとURLをコピーしました