-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-entrypoint-apache.sh
More file actions
78 lines (68 loc) · 3.64 KB
/
docker-entrypoint-apache.sh
File metadata and controls
78 lines (68 loc) · 3.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
set -e
find /var/www/html/wp-content/cache/* -maxdepth 0 -type d ! -name 'matomo' -exec rm -rf {} + 2>/dev/null || true
rm -rf /var/www/html/wp-content/uploads/cache/* 2>/dev/null || true
if [ "$FLUSH_REDIS_ON_STARTUP" = "true" ] && [ -n "$SERVICE_PASSWORD_REDIS" ]; then
for i in {1..30}; do
if redis-cli -h redis -p 6379 -a "$SERVICE_PASSWORD_REDIS" ping >/dev/null 2>&1; then
redis-cli -h redis -p 6379 -a "$SERVICE_PASSWORD_REDIS" FLUSHDB >/dev/null 2>&1
break
fi
sleep 1
done
fi
if [ -d "/var/www/html/wp-content/plugins/matomo" ]; then
mkdir -p /var/www/html/wp-content/cache/matomo/{assets,logs,tcpdf,templates_c}
mkdir -p /var/www/html/wp-content/plugins/matomo/app/tmp/{assets,cache,climulti,logs,sessions,tcpdf,templates_c}
chown -R www-data:www-data /var/www/html/wp-content/plugins/matomo/app 2>/dev/null || true
chown -R www-data:www-data /var/www/html/wp-content/cache/matomo 2>/dev/null || true
find /var/www/html/wp-content/cache/matomo -type f -exec chmod 644 {} + 2>/dev/null || true
find /var/www/html/wp-content/cache/matomo -type d -exec chmod 755 {} + 2>/dev/null || true
fi
if [ -f "/usr/local/bin/scripts/secure-uploads.sh" ]; then
/usr/local/bin/scripts/secure-uploads.sh
fi
find /tmp -name 'sess_*' -type f -mtime +1 -delete 2>/dev/null || true
# Configure Redis in wp-config.php if object cache drop-in exists
if [ -f "/var/www/html/wp-config.php" ] && [ -f "/var/www/html/wp-content/object-cache.php" ]; then
wp config set WP_REDIS_HOST redis --type=constant --allow-root 2>/dev/null || true
wp config set WP_REDIS_PORT 6379 --type=constant --raw --allow-root 2>/dev/null || true
wp config set WP_REDIS_PASSWORD "${SERVICE_PASSWORD_REDIS}" --type=constant --allow-root 2>/dev/null || true
wp config set WP_REDIS_TIMEOUT 1 --type=constant --raw --allow-root 2>/dev/null || true
wp config set WP_REDIS_READ_TIMEOUT 1 --type=constant --raw --allow-root 2>/dev/null || true
wp config set WP_REDIS_DATABASE 0 --type=constant --raw --allow-root 2>/dev/null || true
wp config set WP_REDIS_IGBINARY true --type=constant --raw --allow-root 2>/dev/null || true
wp config set WP_CACHE true --type=constant --raw --allow-root 2>/dev/null || true
fi
# Add HTTPS detection for reverse proxy environments
if [ -f "/var/www/html/wp-config.php" ]; then
if ! grep -q "HTTP_X_FORWARDED_PROTO" /var/www/html/wp-config.php 2>/dev/null; then
sed -i "/That's all, stop editing/i\\
// HTTPS detection for reverse proxy environments\\
if (isset(\$_SERVER['HTTP_X_FORWARDED_PROTO']) && \$_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https') {\\
\$_SERVER['HTTPS'] = 'on';\\
}\\
if (isset(\$_SERVER['HTTP_CF_VISITOR'])) {\\
\$cf_visitor = json_decode(\$_SERVER['HTTP_CF_VISITOR'], true);\\
if (isset(\$cf_visitor['scheme']) && \$cf_visitor['scheme'] === 'https') {\\
\$_SERVER['HTTPS'] = 'on';\\
}\\
}\\
" /var/www/html/wp-config.php
fi
# Auto-migrate HTTP URLs to HTTPS if site is installed
if wp core is-installed --allow-root 2>/dev/null; then
SITE_URL=$(wp option get siteurl --allow-root 2>/dev/null || echo "")
if [[ "$SITE_URL" == http://* ]]; then
HTTPS_URL=${SITE_URL/http:/https:}
wp option update siteurl "$HTTPS_URL" --allow-root
wp option update home "$HTTPS_URL" --allow-root
fi
fi
fi
# Ensure wp-content permissions are correct
if [ -d "/var/www/html/wp-content" ]; then
find /var/www/html/wp-content -type d -exec chmod 755 {} + 2>/dev/null || true
find /var/www/html/wp-content -type f -exec chmod 644 {} + 2>/dev/null || true
fi
exec docker-entrypoint.sh "$@"