Skip to content

Commit f3e4664

Browse files
authored
Merge pull request #30 from psaux-it/phpmyadmin
Phpmyadmin
2 parents 6b5bd0f + 5064859 commit f3e4664

File tree

6 files changed

+191
-69
lines changed

6 files changed

+191
-69
lines changed

.env

+7-4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ export WORDPRESS_ADMIN_USER_=npp
3434
export WORDPRESS_ADMIN_PASSWORD_=npp
3535
export WORDPRESS_ADMIN_EMAIL_=[email protected]
3636

37+
# phpMyAdmin Settings
38+
export PMA_ABSOLUTE_URI_=${WORDPRESS_SITE_URL_}/phpmyadmin/
39+
3740
# FPM Settings
3841
export NPP_FPM_CONF=./fpm/www.conf
3942
export FPM_DOCKER_CONF=./fpm/zz-docker.conf
@@ -45,6 +48,7 @@ export NPP_PHP_CONF=./php/npp.ini
4548
export NGINX_SSL_CERTS=./ssl
4649

4750
# NPP Specific Settings
51+
export NPP_HACK_HOST_=1
4852
export NGINX_WEB_USER_=nginx
4953
export NPP_NGINX_CACHE_PATH_=/var/cache/nginx
5054
export MOUNT_DIR_=${NPP_NGINX_CACHE_PATH_}-npp
@@ -53,9 +57,8 @@ export NPP_USER_=npp
5357
export NPP_UID_=18978
5458
export NPP_GID_=33749
5559

56-
# NPP Development environment
57-
export NPP_DEV_ENABLED_=1
58-
export NPP_HACK_HOST_=1
60+
# NPP EDGE
61+
export NPP_EDGE_=1
5962
export NPP_DEV_PLUGIN_NAME_=fastcgi-cache-purge-and-preload-nginx
6063
export NPP_DEV_PLUGIN_DIR_="${NPP_WEB_ROOT_}/wp-content/plugins/${NPP_DEV_PLUGIN_NAME_}"
6164
export NPP_DEV_TMP_CLONE_DIR_="/tmp/${NPP_DEV_PLUGIN_NAME_}"
@@ -66,4 +69,4 @@ export NPP_DEV_GITHUB_REPO_="https://github.com/psaux-it/nginx-fastcgi-cache-pur
6669
export NPP_PLUGINS_="${NPP_DEV_PLUGIN_NAME_}"
6770

6871
# Themes to auto Install (comma seperated)
69-
export NPP_THEMES_="blue-note"
72+
export NPP_THEMES_=""

docker-compose.yml

+21-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ services:
4040
- NPP_PLUGINS=${NPP_PLUGINS_}
4141
- NPP_THEMES=${NPP_THEMES_}
4242
- NPP_HACK_HOST=${NPP_HACK_HOST_}
43-
- NPP_DEV_ENABLED=${NPP_DEV_ENABLED_}
43+
- NPP_EDGE=${NPP_EDGE_}
4444
- NPP_DEV_PLUGIN_NAME=${NPP_DEV_PLUGIN_NAME_}
4545
- NPP_DEV_PLUGIN_DIR=${NPP_DEV_PLUGIN_DIR_}
4646
- NPP_DEV_TMP_CLONE_DIR=${NPP_DEV_TMP_CLONE_DIR_}
@@ -119,6 +119,26 @@ services:
119119
cpus: "0.5"
120120
memory: "1GB"
121121

122+
phpmyadmin:
123+
build:
124+
context: .
125+
dockerfile: phpmyadmin/Dockerfile
126+
image: ghcr.io/psaux-it/wordpress-nginx-cache-docker/phpmyadmin:latest
127+
container_name: phpmyadmin
128+
env_file:
129+
- .env
130+
environment:
131+
- PMA_HOST=db
132+
- PMA_PORT=3306
133+
- PMA_ABSOLUTE_URI=${PMA_ABSOLUTE_URI_}
134+
- WORDPRESS_DB_USER=${WORDPRESS_DB_USER}
135+
- WORDPRESS_DB_PASSWORD=${WORDPRESS_DB_PASSWORD}
136+
- WORDPRESS_DB_NAME=${WORDPRESS_DB_NAME}
137+
networks:
138+
- npp_network
139+
depends_on:
140+
- db
141+
122142
nginx:
123143
build:
124144
context: .

nginx/default.conf

+60-41
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,54 @@
66
# ---------------------------------------------------------------------------- #
77

88
# FastCGI Cache Path
9-
####################
9+
#####################
1010
fastcgi_cache_path /var/cache/nginx levels=1:2 keys_zone=NPP:100m max_size=400m inactive=30d;
11-
####################
11+
#####################
1212

1313
server {
1414
# Listen HTTP
15-
##################################
15+
#################
1616
listen 80;
1717
server_name localhost;
1818

1919
# HTTPS Redirect
20-
##################################
20+
#################
2121
location / {
2222
rewrite ^ https://$host$request_uri? permanent;
2323
}
2424
}
2525

2626
server {
2727
# Listen HTTPS
28-
##################################
28+
#################
2929
listen 443 ssl;
30+
http2 on;
3031
server_name localhost;
3132

32-
# Document root
33-
###############
33+
# phpMyAdmin Reverse Proxy
34+
#################
35+
location = /phpmyadmin {
36+
return 301 $scheme://$host/phpmyadmin/;
37+
}
38+
39+
location ~ \/phpmyadmin {
40+
rewrite ^/phpmyadmin(/.*)$ $1 break;
41+
proxy_set_header Host $host;
42+
proxy_set_header X-Forwarded-Scheme $scheme;
43+
proxy_set_header X-Forwarded-Proto $scheme;
44+
proxy_set_header X-Forwarded-For $remote_addr;
45+
proxy_set_header X-Real-IP $remote_addr;
46+
proxy_pass http://phpmyadmin:80;
47+
}
48+
# End
49+
#####
50+
51+
# WP Document root
52+
#################
3453
root /var/www/html;
3554
index index.php index.html index.htm;
3655

37-
# Cache Settings
56+
# FCGI Cache Settings
3857
#################
3958
set $skip_cache 0;
4059

@@ -61,7 +80,7 @@ server {
6180
#####
6281

6382
# Stop Nginx from logging
64-
#########################
83+
#################
6584
location = /favicon.ico {
6685
log_not_found off;
6786
access_log off;
@@ -75,16 +94,16 @@ server {
7594
# End
7695
#####
7796

78-
# Serve content
79-
##################
97+
# Serve WP content
98+
#################
8099
location / {
81100
try_files $uri $uri/ /index.php$is_args$args;
82101
}
83102
# End
84103
#####
85104

86-
# PHP-FPM Configuration
87-
################
105+
# WP PHP-FPM PASS
106+
#################
88107
location ~ \.php$ {
89108
# Use NPP "Cache Key Regex" option for non-default structers
90109
# This structer supported in default by NPP
@@ -107,47 +126,47 @@ server {
107126
# End
108127
#####
109128

110-
# WP Security Settings
111-
#######################
129+
# WP Security Settings (Enable on Production)
130+
#################
112131
# Deny access to hidden files and directories (except .well-known)
113-
location ~ /\.(?!well-known/) {
114-
deny all;
115-
}
132+
# location ~ /\.(?!well-known/) {
133+
# deny all;
134+
# }
116135

117136
# Deny access to wp-config files and other critical files
118-
location ~* ^/(?:wp-config\.php|wp-config-sample\.php|readme\.html|license\.txt)$ {
119-
deny all;
120-
}
137+
# location ~* ^/(?:wp-config\.php|wp-config-sample\.php|readme\.html|license\.txt)$ {
138+
# deny all;
139+
# }
121140

122141
# Deny access to PHP files in uploads, files, plugins, themes
123-
location ~* /(?:uploads|files|wp-content|wp-includes)/.*\.php$ {
124-
deny all;
125-
}
142+
# location ~* /(?:uploads|files|wp-content|wp-includes)/.*\.php$ {
143+
# deny all;
144+
# }
126145

127146
# Deny access to script file types
128-
location ~* .(pl|cgi|py|sh|lua|asp)$ {
129-
deny all;
130-
}
147+
# location ~* .(pl|cgi|py|sh|lua|asp)$ {
148+
# deny all;
149+
# }
131150

132151
# Block access to wp-content plugin/theme log files
133-
location ~* ^/wp-content/(plugins|themes)/.*\.(txt|log|md)$ {
134-
deny all;
135-
}
152+
# location ~* ^/wp-content/(plugins|themes)/.*\.(txt|log|md)$ {
153+
# deny all;
154+
# }
136155

137156
# Block common attack patterns
138-
location ~* "(eval\(.*\)|base64_encode\(.*\)|\{0\}|phpinfo|self/environ)" {
139-
deny all;
140-
}
157+
# location ~* "(eval\(.*\)|base64_encode\(.*\)|\{0\}|phpinfo|self/environ)" {
158+
# deny all;
159+
# }
141160

142161
# Block dangerous file access
143-
location ~* "/(thumb|timthumb|config|settings|sqlpatch|webshell|phpinfo)\.php" {
144-
deny all;
145-
}
162+
# location ~* "/(thumb|timthumb|config|settings|sqlpatch|webshell|phpinfo)\.php" {
163+
# deny all;
164+
# }
146165
# End
147166
#####
148167

149168
# Browser Cache (Enable on Production)
150-
###############
169+
#################
151170
# location ~*.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
152171
# expires max;
153172
# log_not_found off;
@@ -165,7 +184,7 @@ server {
165184
#####
166185

167186
# SSL Settings (Enable on Production)
168-
##############
187+
#################
169188
# ssl_protocols TLSv1.2 TLSv1.3;
170189
# ssl_prefer_server_ciphers on;
171190
# ssl_ciphers ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS;
@@ -178,7 +197,7 @@ server {
178197
#####
179198

180199
# Security Headers (Enable on Production)
181-
##################
200+
#################
182201
# add_header Content-Security-Policy upgrade-insecure-requests;
183202
# add_header Permissions-Policy "microphone=(), camera=(), interest-cohort=(), browsing-topics=()";
184203
# add_header Referrer-Policy no-referrer-when-downgrade;
@@ -190,7 +209,7 @@ server {
190209
#####
191210

192211
# FastCGI Cache Status Header
193-
#############################
212+
#################
194213
add_header NPP-FastCGI-Cache $upstream_cache_status;
195-
#############################
214+
#################
196215
}

phpmyadmin/Dockerfile

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Dockerfile for NPP-Optimized WordPress Setup #
2+
# ---------------------------------------------------------------------------- #
3+
# Author: [Hasan ÇALIŞIR] #
4+
# Purpose: Full-stack Dockerized environment for NPP WordPress plugin, including #
5+
# WordPress, PHP-FPM, Nginx, MySQL, WP-CLI, and necessary PHP extensions. #
6+
# ---------------------------------------------------------------------------- #
7+
8+
# Here the magic, the rest of it is ordinary
9+
FROM phpmyadmin:5.2.2-apache
10+
11+
# Install necessary packages
12+
RUN apt-get update && apt-get install -y \
13+
procps \
14+
mariadb-client
15+
16+
# Copy the entrypoint script into the container
17+
COPY phpmyadmin/entrypoint-pma.sh /entrypoint-pma.sh
18+
19+
# Make sure the entrypoint script is executable
20+
RUN chmod +x /entrypoint-pma.sh
21+
22+
# CMD
23+
CMD ["/entrypoint-pma.sh", "apache2-foreground"]

phpmyadmin/entrypoint-pma.sh

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (C) 2024 Hasan CALISIR <[email protected]>
4+
# Distributed under the GNU General Public License, version 2.0.
5+
#
6+
# This program is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU General Public License as published by
8+
# the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
# SCRIPT DESCRIPTION:
20+
# -------------------
21+
# NPP (Nginx Cache Purge & Preload for WordPress) Dockerized entrypoint
22+
# https://github.com/psaux-it/nginx-fastcgi-cache-purge-and-preload
23+
# https://wordpress.org/plugins/fastcgi-cache-purge-and-preload-nginx/
24+
25+
set -Eeuo pipefail
26+
27+
# Define color codes
28+
COLOR_RESET='\033[0m'
29+
COLOR_GREEN='\033[0;32m'
30+
COLOR_YELLOW='\033[0;33m'
31+
COLOR_RED='\033[0;31m'
32+
COLOR_CYAN='\033[0;36m'
33+
COLOR_BOLD='\033[1m'
34+
COLOR_WHITE='\033[0;97m'
35+
COLOR_BLACK='\033[0;30m'
36+
COLOR_LIGHT_CYAN='\033[0;96m'
37+
38+
# Check if required environment variables are set
39+
for var in \
40+
WORDPRESS_DB_USER \
41+
WORDPRESS_DB_PASSWORD \
42+
WORDPRESS_DB_NAME; do
43+
if [[ -z "${!var:-}" ]]; then
44+
echo -e "${COLOR_RED}${COLOR_BOLD}NPP-WP-FATAL:${COLOR_RESET} Missing required environment variable(s): ${COLOR_LIGHT_CYAN}${var}${COLOR_RESET} - ${COLOR_RED}Exiting...${COLOR_RESET}"
45+
exit 1
46+
fi
47+
done
48+
49+
# Wait for the 'wordpress-db' to be ready
50+
until mysql -h wordpress-db -u"${WORDPRESS_DB_USER}" -p"${WORDPRESS_DB_PASSWORD}" "${WORDPRESS_DB_NAME}" -e "SELECT 1" > /dev/null 2>&1; do
51+
echo -e "${COLOR_YELLOW}${COLOR_BOLD}NPP-ADM:${COLOR_RESET} The ${COLOR_LIGHT_CYAN}MySQL database${COLOR_RESET} is not available yet. Retrying..."
52+
sleep 6
53+
done
54+
echo -e "${COLOR_GREEN}${COLOR_BOLD}NPP-ADM:${COLOR_RESET} The ${COLOR_LIGHT_CYAN}MySQL database${COLOR_RESET} is ready! Proceeding..."
55+
56+
# Start Apache
57+
exec /docker-entrypoint.sh "$@"

0 commit comments

Comments
 (0)