# Laravel Cache Permission Issue - FIXED

## Problem
After running commands to fix cache directory permissions, some folders were reverting back to incorrect permissions (755 instead of 775). This was causing permission issues when different processes (web server, cron jobs, queue workers) tried to write to the cache.

## Root Cause
The system **umask was set to 0022**, which caused new directories to be created with 755 permissions (drwxr-xr-x) instead of 775 (drwxrwxr-x).

## Solution Implemented

### 1. Set umask to 0002 in Laravel Bootstrap Files
Added `umask(0002);` to three key files that are entry points for all Laravel processes:

- **bootstrap/app.php** - Used by all Laravel processes
- **public/index.php** - Web requests entry point
- **artisan** - CLI commands entry point

With umask set to 0002:
- New directories will be created with **775 permissions** (drwxrwxr-x)
- New files will be created with **664 permissions** (-rw-rw-r--)

### 2. Fixed Current Permissions
```bash
chown -R asterisk:asterisk /var/www/ccsystem/storage
chown -R asterisk:asterisk /var/www/ccsystem/bootstrap/cache
chmod -R 775 /var/www/ccsystem/storage
chmod -R 775 /var/www/ccsystem/bootstrap/cache
```

### 3. Created Helper Script
Created `/var/www/ccsystem/fix-permissions.sh` for future use if needed.

Usage:
```bash
cd /var/www/ccsystem
./fix-permissions.sh
```

## Verification
After the fix:
- ✅ New cache directories are created with **drwxrwxr-x (775)** permissions
- ✅ New cache files are created with **-rw-rw-r-- (664)** permissions
- ✅ All processes (Apache, cron jobs, queue workers) create files with correct permissions
- ✅ No more permission reversion issues

## Why This Works
The umask setting affects all file and directory creation operations. By setting it to 0002 at the application entry points:
- **Web requests** (via public/index.php) → Apache creates cache with 775/664
- **CLI commands** (via artisan) → Cron jobs create cache with 775/664
- **Queue workers** (via artisan queue:work) → Queue creates cache with 775/664
- **All Laravel operations** (via bootstrap/app.php) → Consistent permissions

## Files Modified
1. `/var/www/ccsystem/bootstrap/app.php` - Added umask(0002)
2. `/var/www/ccsystem/public/index.php` - Added umask(0002)
3. `/var/www/ccsystem/artisan` - Added umask(0002)
4. `/var/www/ccsystem/fix-permissions.sh` - Created helper script

## Date Fixed
February 17, 2026
