updated_at: 2025-05-31 04:06

php-fpm, mariadb, nginx and laravel 하기 2

laravel을 띄우기위해서는 composer 및 npm을 설치하여야 합니다.
이전장에서 php:8.2-fpm 의 이미지를 바로 불러서 php서버를 구성하였지만 compoer 및 mysqlnd를 위해 Dockerfile을 이용해 이미지를 만들어 사용하는 방식을 설명드리도록 하겠습니다.

Dockerfile

FROM php:8.2-fpm


# 필요한 시스템 패키지 설치
RUN apt-get update && apt-get install -y \
    default-mysql-client \
    libpng-dev \
    libjpeg-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip \
    vim \
    && docker-php-ext-install mysqli pdo pdo_mysql

# Get Composer
COPY --from=composer:2.7 /usr/bin/composer /usr/bin/composer

# Get NodeJS
COPY --from=node:20-slim /usr/local/bin /usr/local/bin

# Get npm
COPY --from=node:20-slim /usr/local/lib/node_modules /usr/local/lib/node_modules

nginx-conf.yaml

nginx-conf는 라라벨이 작동할 수 있도록 적절하게 변경하였습니다.

apiVersion: v1
kind: ConfigMap
metadata:
  name: nginx-config
data:
  default.conf: | #키명 = 파일명, |은 밸류가 멀티라인이라는 뜻
    server {
      listen       80;
      listen  [::]:80;
      server_name  localhost;

      access_log  /var/log/nginx/host.access.log;
      error_log  /var/log/nginx/host.error.log;

      root   /usr/share/nginx/html/example-app/public;
      index   index.php index.html index.htm;

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

      location ~ \.php$ {
        
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_param REQUEST_METHOD $request_method;
        # fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
      }
    }

pod.yaml

# Create a pod containing the PHP-FPM application (my-php-app)
# and nginx, each mounting the `shared-files` volume to their
# respective /var/www/html directories.

kind: Pod
apiVersion: v1
metadata:
  name: nginx-phpfpm
spec:
  volumes:
    # Create the shared files volume to be used in both pods
    - name: shared-files
      emptyDir: {}
    
    - name: nginx-config-volume
      configMap:
        name: nginx-config
    # Add the ConfigMap we declared above as a volume for the pod
    # - name: nginx-config-volume
    
  containers:
    # Our PHP-FPM application
    - image: php-8-2-fpm:1.0.0
      name: phpfpm82
      imagePullPolicy: Never
      volumeMounts:
        - name: shared-files
          mountPath: /usr/share/nginx/html
    # Our nginx container, which uses the configuration declared above,
    # along with the files shared with the PHP-FPM app.
    - image: nginx:1.27.5
      name: nginx
      volumeMounts:
        - name: shared-files
          mountPath: /usr/share/nginx/html
        - name: nginx-config-volume
          mountPath: /etc/nginx/conf.d

Mariadb

마리아 db는 이전과 별 차이가 없으므로 별도로 말씀드리지 않겠습니다.

docker build . -t php-8-2-fpm:1.0.0
kubectl apply -f .\nginx-conf.yaml
kubectl apply -f .\pod.yaml
kubectl port-forward nginx-phpfpm 8888:80

laravel setting

콘솔로 들어가서 라라벨을 프로젝트를 생성해 보겠습니다.

kubectl exec --stdin --tty nginx-phpfpm --container phpfpm82 -- /bin/bash
# cd /usr/share/nginx/html/
# composer create-project "laravel/laravel:^10.0" example-app
# chmod 757 $(find //usr/share/nginx/html/example-app/storage -type d)

브라우저에서 http://localhost:8888/ 을 확인하시면 laravel이 페이지로 접근 가능하신 것을 확인 하실 수 있습니다.

평점을 남겨주세요
평점 : 2.5
총 투표수 : 1

질문 및 답글