Skip to content

Commit a7d54e3

Browse files
committed
build(docker): fixed folder permissions issues for logs and cache in docker
1 parent 177c850 commit a7d54e3

File tree

5 files changed

+38
-26
lines changed

5 files changed

+38
-26
lines changed

containers/docker-compose.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ services:
1616
- ./php/php.ini:/usr/local/etc/php/conf.d/custom.ini
1717
- ./php/xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini
1818
- ./nginx/default.conf:/etc/nginx/sites-available/default
19-
- laravel_logs:/var/www/html/storage/logs
20-
- laravel_cache:/var/www/html/bootstrap/cache
2119
ports:
2220
- "8081:80"
2321
- "8001:8001" # xdebug port
@@ -129,7 +127,3 @@ volumes:
129127
driver: local
130128
redis_data:
131129
driver: local
132-
laravel_logs:
133-
driver: local
134-
laravel_cache:
135-
driver: local

containers/fix-permissions.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
3+
echo "🔧 Quick permission fix for Laravel storage directories..."
4+
5+
# This script can be run inside the container to fix permissions
6+
# Usage: docker exec -it laravel_blog_api /usr/local/bin/fix-permissions.sh
7+
8+
# Fix ownership
9+
echo "📁 Fixing ownership..."
10+
chown -R www-data:www-data /var/www/html/storage 2>/dev/null || true
11+
chown -R www-data:www-data /var/www/html/bootstrap/cache 2>/dev/null || true
12+
13+
# Fix permissions
14+
echo "🔐 Fixing permissions..."
15+
chmod -R 775 /var/www/html/storage 2>/dev/null || true
16+
chmod -R 775 /var/www/html/bootstrap/cache 2>/dev/null || true
17+
chmod -R 775 /var/www/html/storage/logs 2>/dev/null || true
18+
chmod -R 775 /var/www/html/storage/framework 2>/dev/null || true
19+
chmod -R 775 /var/www/html/storage/app 2>/dev/null || true
20+
21+
# Make artisan executable
22+
chmod +x /var/www/html/artisan 2>/dev/null || true
23+
24+
echo "✅ Permissions fixed!"
25+
echo "📋 Current storage permissions:"
26+
ls -la /var/www/html/storage/logs/ 2>/dev/null || echo "Logs directory not accessible"

containers/php/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ COPY supervisor/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
6767
COPY start-services.sh /usr/local/bin/start-services.sh
6868
COPY start-main-app.sh /usr/local/bin/start-main-app.sh
6969
COPY start-queue-worker.sh /usr/local/bin/start-queue-worker.sh
70+
COPY fix-permissions.sh /usr/local/bin/fix-permissions.sh
7071
RUN chmod +x /usr/local/bin/start-services.sh
7172
RUN chmod +x /usr/local/bin/start-main-app.sh
7273
RUN chmod +x /usr/local/bin/start-queue-worker.sh
74+
RUN chmod +x /usr/local/bin/fix-permissions.sh
7375

7476
# Create necessary Laravel directories and set proper permissions
7577
RUN mkdir -p /var/www/html/storage/app/public \

containers/start-main-app.sh

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,9 @@ trap shutdown SIGTERM SIGINT
1818
# Remove any existing ready marker
1919
rm -f /var/www/html/storage/laravel_ready
2020

21-
# Universal permission fix for all systems
21+
# Fix permissions at startup
2222
echo "[MAIN] SETUP: Fixing Laravel directory permissions..."
23-
# Ensure www-data user owns all files (www-data is standard across systems)
24-
chown -R www-data:www-data /var/www/html 2>/dev/null || true
25-
# Set proper permissions for storage and cache directories
26-
chmod -R 775 /var/www/html/storage 2>/dev/null || true
27-
chmod -R 775 /var/www/html/bootstrap/cache 2>/dev/null || true
28-
# Ensure specific subdirectories have correct permissions
29-
chmod -R 775 /var/www/html/storage/framework/cache 2>/dev/null || true
30-
chmod -R 775 /var/www/html/storage/framework/sessions 2>/dev/null || true
31-
chmod -R 775 /var/www/html/storage/framework/testing 2>/dev/null || true
32-
chmod -R 775 /var/www/html/storage/framework/views 2>/dev/null || true
33-
chmod -R 775 /var/www/html/storage/logs 2>/dev/null || true
34-
chmod -R 775 /var/www/html/storage/app 2>/dev/null || true
35-
# Make artisan executable
36-
chmod +x /var/www/html/artisan 2>/dev/null || true
23+
/usr/local/bin/fix-permissions.sh
3724

3825
# Wait for database to be ready
3926
echo "[MAIN] WAITING: Database connection..."
@@ -96,12 +83,9 @@ php artisan config:clear
9683
php artisan config:cache
9784
php artisan route:cache
9885

99-
# Universal permission fix after optimization
86+
# Fix permissions after optimization
10087
echo "[MAIN] SETUP: Fixing permissions after optimization..."
101-
chown -R www-data:www-data /var/www/html/storage 2>/dev/null || true
102-
chown -R www-data:www-data /var/www/html/bootstrap/cache 2>/dev/null || true
103-
chmod -R 775 /var/www/html/storage 2>/dev/null || true
104-
chmod -R 775 /var/www/html/bootstrap/cache 2>/dev/null || true
88+
/usr/local/bin/fix-permissions.sh
10589

10690
# Create ready marker to signal that the app is fully set up
10791
echo "[MAIN] SUCCESS: Application setup complete! Creating ready marker..."

containers/start-queue-worker.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/bin/bash
22

3+
echo "[QUEUE] Starting Laravel queue worker..."
4+
5+
# Fix permissions at startup
6+
echo "[QUEUE] SETUP: Fixing Laravel directory permissions..."
7+
/usr/local/bin/fix-permissions.sh
8+
39
echo "[QUEUE] Waiting for main Laravel application to be ready..."
410

511
# Function to check if main application is ready

0 commit comments

Comments
 (0)