Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save azappella/b13c1fea112937a84a097b072a7d95f0 to your computer and use it in GitHub Desktop.
Save azappella/b13c1fea112937a84a097b072a7d95f0 to your computer and use it in GitHub Desktop.
Docker Compose files for PHP development

Docker Compose files for PHP development

Apache + PostgreSQL + MySQL

docker-compose -f docker-compose.apache.yml up

nginx + Apache + PostgreSQL + MySQL

docker-compose -f docker-compose.nginx+apache.yml up

nginx + PHP-FPM + PostgreSQL + MySQL

docker-compose -f docker-compose.nginx+php-fpm.yml up

How to connect to PostgreSQL

$db = new PDO('pgsql:host=postgres;dbname=postgres;user=postgres');

How to connect to MySQL

$db = new PDO('mysql:host=mysql;dbname=mysql', 'root');
{
"version": "2",
"volumes": {
"postgres_data": {},
"mysql_data": {}
},
"services": {
"postgres": {
"image": "postgres:alpine",
"volumes": [
"postgres_data:/var/lib/postgresql/data"
]
},
"mysql": {
"image": "mysql",
"environment": {
"MYSQL_ALLOW_EMPTY_PASSWORD": "true"
},
"volumes": [
"mysql_data:/var/lib/mysql"
]
},
"apache": {
"build": {
"context": ".",
"dockerfile": "Dockerfile-apache"
},
"volumes": [
"./:/var/www/html"
],
"ports": [
"80:80"
],
"depends_on": [
"postgres",
"mysql"
]
}
}
}
{
"version": "2",
"volumes": {
"postgres_data": {},
"mysql_data": {}
},
"services": {
"postgres": {
"image": "postgres:alpine",
"volumes": [
"postgres_data:/var/lib/postgresql/data"
]
},
"mysql": {
"image": "mysql",
"environment": {
"MYSQL_ALLOW_EMPTY_PASSWORD": "true"
},
"volumes": [
"mysql_data:/var/lib/mysql"
]
},
"apache": {
"build": {
"context": ".",
"dockerfile": "Dockerfile-apache"
},
"volumes": [
"./:/var/www/html"
],
"depends_on": [
"postgres",
"mysql"
]
},
"nginx": {
"image": "nginx:alpine",
"volumes": [
"./:/var/www",
"./nginx.apache.conf:/etc/nginx/nginx.conf:ro"
],
"ports": [
"80:80"
],
"depends_on": [
"apache"
]
}
}
}
{
"version": "2",
"volumes": {
"postgres_data": {},
"mysql_data": {}
},
"services": {
"postgres": {
"image": "postgres:alpine",
"volumes": [
"postgres_data:/var/lib/postgresql/data"
]
},
"mysql": {
"image": "mysql",
"environment": {
"MYSQL_ALLOW_EMPTY_PASSWORD": "true"
},
"volumes": [
"mysql_data:/var/lib/mysql"
]
},
"php-fpm": {
"build": {
"context": ".",
"dockerfile": "Dockerfile-php-fpm"
},
"volumes": [
"./:/var/www/html"
],
"depends_on": [
"postgres",
"mysql"
]
},
"nginx": {
"image": "nginx:alpine",
"volumes": [
"./:/var/www",
"./nginx.php-fpm.conf:/etc/nginx/nginx.conf:ro"
],
"ports": [
"80:80"
],
"depends_on": [
"php-fpm"
]
}
}
}
FROM php:apache
RUN apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev \
&& docker-php-ext-install pdo_pgsql pdo_mysql
FROM php:fpm
RUN apt-get update \
&& apt-get install -y --no-install-recommends libpq-dev \
&& docker-php-ext-install pdo_pgsql pdo_mysql
<?php
phpinfo();
events {}
http {
include mime.types;
default_type application/octet-stream;
# Update charset_types to match updated mime.types.
# text/html is always included by charset module.
charset_types
text/css
text/plain
text/vnd.wap.wml
application/javascript
application/json
application/rss+xml
application/xml;
charset utf-8;
server {
listen [::]:80;
listen 80;
location / {
root /var/www;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
proxy_pass http://apache;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
}
events {}
http {
include mime.types;
default_type application/octet-stream;
# Update charset_types to match updated mime.types.
# text/html is always included by charset module.
charset_types
text/css
text/plain
text/vnd.wap.wml
application/javascript
application/json
application/rss+xml
application/xml;
charset utf-8;
server {
listen [::]:80;
listen 80;
location / {
root /var/www;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
root /var/www/html;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php-fpm:9000;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment