# Migration Checklist - Public Directory Structure Quick reference for migrating from current flat structure to secure public/ structure. ## ๐Ÿ“‹ Summary of Required Changes ### 1. Dev Server (justfile) โšก **Line 51** - Change from: ```just @php -S 127.0.0.1:8000 ``` To: ```just @php -S 127.0.0.1:8000 -t public/ ``` ### 2. Deployment (justfile) ๐Ÿ“ค **Lines 56-75** - Replace entire `deploy` recipe with two-step deployment: - Deploy app to `/var/www/posterg/` (not `/var/www/html/`) - Nginx serves from `/var/www/posterg/public/` See `DEPLOYMENT_MIGRATION.md` for complete updated recipe. ### 3. Nginx Configuration ๐Ÿ”ง **nginx/posterg.conf line 14** - Change from: ```nginx root /var/www/html; ``` To: ```nginx root /var/www/posterg/public; ``` **Also update admin location** (line 58) - Change from: ```nginx location ^~ /formulaire/ { ``` To: ```nginx location ^~ /admin/ { ``` (Since you're moving admin/ to public/admin/) --- ## ๐Ÿš€ Quick Migration (Local Dev) ```bash # 1. Update justfile serve command sed -i 's/@php -S 127.0.0.1:8000/@php -S 127.0.0.1:8000 -t public\//' justfile # 2. Test new dev server just serve # Visit http://localhost:8000 # Verify http://localhost:8000/storage/test.db returns 404 # 3. If it works, you're ready for production migration ``` --- ## ๐Ÿ“ File Movements (Do This After Testing) ```bash # Create new structure mkdir -p public/{admin,assets} mkdir -p src config var/{cache,logs,tmp} # Move public files mv index.php search.php memoire.php public/ mv admin/* public/admin/ && rmdir admin mv assets/* public/assets/ && rmdir assets # Move private files mv inc/* config/ && rmdir inc # OR if inc/ contains classes: # mv inc/* src/ && rmdir inc # Keep these as-is # database/ (already private) # vendor/ (already private) # tests/ (already private) # lib/ (decide if it goes to src/lib or stays) ``` --- ## โš ๏ธ Critical Changes Required ### In nginx/posterg.conf: 1. **Line 14** - DocumentRoot ```nginx # BEFORE root /var/www/html; # AFTER root /var/www/posterg/public; ``` 2. **Line 58-76** - Admin location (already at `/formulaire/`, might want `/admin/`) ```nginx # BEFORE location ^~ /formulaire/ { auth_basic "Admin Access - Post-ERG"; auth_basic_user_file /etc/nginx/.htpasswd-posterg; # ... rest of config } # AFTER (if renaming to /admin/) location ^~ /admin/ { auth_basic "Admin Access - Post-ERG"; auth_basic_user_file /etc/nginx/.htpasswd-posterg; # ... rest of config } ``` 3. **Remove/update deny rules** (lines 48-60) - These become redundant! ```nginx # BEFORE - needed because everything in DocumentRoot location ^~ /storage/ { deny all; } location ^~ /shared/ { deny all; } location ^~ /data/ { deny all; } # AFTER - can remove! They're already outside public/ # But keep as defense-in-depth: location ^~ /storage/ { deny all; } # Will never match, but safe ``` ### In justfile: **Complete replacement for lines 40-76:** ```just [group('dev')] serve: @echo "๐Ÿš€ Starting Post-ERG development server" @echo "========================================" @echo "" @echo "๐Ÿ“ Public site: http://localhost:8000" @echo "๐Ÿ“ Admin panel: http://localhost:8000/admin/" @echo "" @echo "๐Ÿ”’ Serving from public/ directory (matches production)" @if [ -d "vendor/php-live-reload" ]; then \ echo "โœจ Live reload enabled"; \ else \ echo "๐Ÿ’ก Tip: Run 'just setup' to enable live reload"; \ fi @echo "" @echo "Press Ctrl+C to stop" @echo "" @php -S 127.0.0.1:8000 -t public/ [group('deploy')] deploy: @echo "๐Ÿ“ค Deploying Post-ERG complete site" @echo "====================================" @echo "" @echo "Deploying to /var/www/posterg/..." rsync -vur --progress \ --chown="www-data:posterg" \ --exclude 'vendor' \ --exclude 'tests' \ --exclude 'test.db' \ --exclude '*.md' \ --exclude '.git*' \ --exclude '.jj' \ --exclude '.DS_Store' \ --exclude 'justfile*' \ --exclude 'setup-dev.sh' \ --exclude 'database/backup_*' \ --exclude 'database/fixtures' \ --exclude 'var/cache/*' \ --exclude 'var/logs/*' \ ./ posterg:/var/www/posterg/ @echo "" @echo "Setting up directories and permissions..." ssh posterg "cd /var/www/posterg && \ mkdir -p var/{cache,logs,tmp} && \ chown -R www-data:posterg var/ database/ && \ chmod -R 775 var/ database/ && \ chmod 660 database/*.db" @echo "" @echo "โœ… Deployment complete!" @echo "" @echo "๐Ÿ” Verify:" @echo " โ€ข Public: https://posterg.erg.be/" @echo " โ€ข Admin: https://posterg.erg.be/admin/" [group('deploy')] test-deploy: @echo "โš ๏ธ Deploying test database" ssh posterg "mkdir -p /var/www/posterg/database" rsync -vur --progress ./storage/test.db posterg:/var/www/posterg/storage/ ssh posterg "chown www-data:posterg /var/www/posterg/storage/test.db && \ chmod 660 /var/www/posterg/storage/test.db" @echo "โœ… Test database deployed" ``` --- ## ๐Ÿงช Testing Steps ### 1. Test Local Dev Server ```bash # Start server with new -t public/ flag just serve # In another terminal: curl http://localhost:8000/ # โœ… Should work curl http://localhost:8000/admin/ # โœ… Should work (after moving) curl http://localhost:8000/storage/test.db # โŒ Should 404 curl http://localhost:8000/config/ # โŒ Should 404 curl http://localhost:8000/vendor/ # โŒ Should 404 ``` ### 2. Test After File Migration ```bash # After moving files to public/ just serve # Test again curl http://localhost:8000/ # โœ… index.php serves curl http://localhost:8000/search.php # โœ… works curl http://localhost:8000/admin/ # โœ… works curl http://localhost:8000/assets/css/style.css # โœ… works # Verify old paths don't work curl http://localhost:8000/../storage/test.db # โŒ 404 curl http://localhost:8000/../config/ # โŒ 404 ``` ### 3. Test Production Deployment ```bash # After deploying to server just server-status # Manual checks curl -I https://posterg.erg.be/ curl -I https://posterg.erg.be/admin/ curl -I https://posterg.erg.be/storage/test.db # Must be 404! ``` --- ## ๐Ÿ“ PHP Path Updates Needed After moving to public/, update PHP includes: **Before (from root):** ```php paths-audit.txt # Review paths-audit.txt and update paths cat paths-audit.txt ``` See **DEPLOYMENT_MIGRATION.md** for complete implementation details.