2023-11-26 PHPでPostgreSQLを使うメモ
PHPでPostgreSQL接続を扱うメモ。
FROM php:5.6-apache
RUN apt-get update && apt-get install -y libpq-dev && docker-php-ext-install pdo pdo_pgsql
COPY src/ /var/www/html
Docker PHP Image with PostgreSQL Driver
FROM php:5.6-fpm
RUN apt-get update
# Install Postgre PDO
RUN apt-get install -y libpq-dev \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install pdo pdo_pgsql pgsql
ref. Can’t install pdo_psql with docker-php-ext-install · Issue #221 · docker-library/php
Alpine で作ってみた
Dockerfile
:
from php:5.6-alpine
WORKDIR /app
RUN apk update && apk add --no-cache \
postgresql-client \
postgresql-dev
RUN docker-php-ext-install pdo pdo_pgsql
compose.yml
:
services:
app:
build: .
volumes:
- .:/app
links:
- db
db:
image: postgres:9
environment:
POSTGRES_DB: exampledb
POSTGRES_USER: exampleuser
POSTGRES_PASSWORD: examplepass
ports:
- "5432:5432"
volumes:
- pgdata:/var/lib/postgresql/data
volumes:
pgdata: