Created
April 29, 2019 12:26
-
-
Save stepankuzmin/6b7d206f921221f74086c162f9b6ac24 to your computer and use it in GitHub Desktop.
Docker Compose + Joomla + PostgreSQL + Nginx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.7' | |
services: | |
nginx: | |
image: nginx:alpine | |
restart: always | |
ports: | |
- 8080:80 | |
volumes: | |
- ./joomla:/var/www/html | |
- ./nginx.conf:/etc/nginx/nginx.conf | |
depends_on: | |
- joomla | |
joomla: | |
image: joomla:3.9.5-php7.3-fpm-alpine | |
restart: always | |
environment: | |
- JOOMLA_DB_HOST=db | |
- JOOMLA_DB_USER=postgres | |
- JOOMLA_DB_PASSWORD=mysecretpassword | |
- JOOMLA_DB_NAME=db | |
volumes: | |
- ./joomla:/var/www/html | |
- ./makedb.php:/makedb.php | |
depends_on: | |
- db | |
db: | |
image: postgres:11.2-alpine | |
restart: unless-stopped | |
environment: | |
- POSTGRES_DB=db | |
- POSTGRES_USER=postgres | |
- POSTGRES_PASSWORD=mysecretpassword | |
volumes: | |
- ./db:/var/lib/postgresql/data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Args: 0 => makedb.php, 1 => "$JOOMLA_DB_HOST", 2 => "$JOOMLA_DB_USER", 3 => "$JOOMLA_DB_PASSWORD", 4 => "$JOOMLA_DB_NAME" | |
$stderr = fopen('php://stderr', 'w'); | |
fwrite($stderr, "\nEnsuring Joomla database is present\n"); | |
if (strpos($argv[1], ':') !== false) | |
{ | |
list($host, $port) = explode(':', $argv[1], 2); | |
} | |
else | |
{ | |
$host = $argv[1]; | |
$port = 5432; | |
} | |
$user = $argv[2]; | |
$password = $argv[3]; | |
$db = $argv[4]; | |
$connection = "host={$host} port={$port} dbname={$db} user={$user} password={$password}"; | |
fwrite($stderr, $connection); | |
$dbconn = pg_connect($connection) | |
or die('Connection Error: ' . pg_last_error()); | |
fwrite($stderr, "\nDatabase Created\n"); | |
pg_close($dbconn); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user nginx; | |
worker_processes auto; | |
worker_cpu_affinity auto; | |
pid /run/nginx.pid; | |
events { | |
worker_connections 4086; | |
use epoll; | |
multi_accept on; | |
} | |
http { | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
server_tokens off; | |
keepalive_timeout 65; | |
keepalive_requests 1000; | |
types_hash_max_size 2048; | |
include /etc/nginx/mime.types; | |
default_type application/octet-stream; | |
access_log /var/log/nginx/access.log; | |
error_log /var/log/nginx/error.log; | |
gzip on; | |
gzip_vary on; | |
gzip_proxied any; | |
gzip_comp_level 6; | |
gzip_buffers 16 8k; | |
gzip_http_version 1.1; | |
gzip_min_length 256; | |
gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml | |
application/javascript application/json application/x-protobuf; | |
proxy_cache_path /var/cache/nginx/ | |
levels=1:2 | |
max_size=10g | |
inactive=60m | |
use_temp_path=off | |
keys_zone=backend_cache:10m; | |
upstream joomla_upstream { | |
server joomla:9000; | |
keepalive 64; | |
} | |
server { | |
listen 80; | |
server_name localhost; | |
server_name_in_redirect off; | |
access_log /var/log/nginx/localhost.access_log; | |
error_log /var/log/nginx/localhost.error_log info; | |
root /var/www/html; | |
index index.php index.html index.htm default.html default.htm; | |
# Support Clean (aka Search Engine Friendly) URLs | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
# deny running scripts inside writable directories | |
location ~* /(images|cache|media|logs|tmp)/.*\.(php|pl|py|jsp|asp|sh|cgi)$ { | |
return 403; | |
error_page 403 /403_error.html; | |
} | |
location ~ \.php$ { | |
fastcgi_pass joomla_upstream; | |
fastcgi_index index.php; | |
include fastcgi_params; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include /etc/nginx/fastcgi.conf; | |
} | |
# caching of files | |
location ~* \.(ico|pdf|flv)$ { | |
expires 1y; | |
} | |
location ~* \.(js|css|png|jpg|jpeg|gif|swf|xml|txt)$ { | |
expires 14d; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment