# โœ… Migration to public/ Directory Structure - COMPLETE ## ๐Ÿ“Š Summary of Changes ### Directory Structure Created ``` posterg-website/ โ”œโ”€โ”€ config/ # โœ… NEW - Configuration files โ”‚ โ””โ”€โ”€ bootstrap.php # Central path management โ”œโ”€โ”€ public/ # โœ… NEW - DocumentRoot (web-accessible) โ”‚ โ”œโ”€โ”€ admin/ # Moved from /admin/ โ”‚ โ”œโ”€โ”€ assets/ # Moved from /assets/ โ”‚ โ”œโ”€โ”€ index.php # Moved from /index.php โ”‚ โ”œโ”€โ”€ search.php # Moved from /search.php โ”‚ โ””โ”€โ”€ memoire.php # Moved from /memoire.php โ”œโ”€โ”€ resources/ # โœ… NEW - Application resources โ”‚ โ””โ”€โ”€ views/ # Moved from /inc/ โ”‚ โ”œโ”€โ”€ header.php โ”‚ โ””โ”€โ”€ footer.php โ”œโ”€โ”€ var/ # โœ… NEW - Runtime files โ”‚ โ”œโ”€โ”€ cache/ โ”‚ โ”œโ”€โ”€ logs/ โ”‚ โ””โ”€โ”€ tmp/ โ”œโ”€โ”€ database/ # โœ… KEPT - Now private โ”œโ”€โ”€ lib/ # โœ… KEPT - Now private โ”œโ”€โ”€ vendor/ # โœ… KEPT - Now private โ””โ”€โ”€ tests/ # โœ… KEPT - Now private ``` ### Files Modified **1. config/bootstrap.php** (NEW) - Central path configuration - Defines APP_ROOT, PUBLIC_ROOT, DATABASE_PATH, etc. - Helper functions: view(), getDatabase() - Environment detection (dev vs production) - Error handling configuration **2. public/*.php** (3 files updated) - index.php: Uses bootstrap, updated require paths - search.php: Uses bootstrap, updated require paths - memoire.php: Uses bootstrap, updated require paths - All now use view() helper for header/footer **3. public/admin/*.php** (7 files updated) - add.php, edit.php, formulaire.php, import.php - index.php, publish.php, thanks.php - All updated to use ../../ paths for lib access - Bootstrap added where needed **4. justfile** (Updated) - Dev server: `php -S 127.0.0.1:8000 -t public/` - Deploy: Now deploys to `/var/www/posterg/` - Database deploy: Updated paths to `/var/www/posterg/` - Nginx deploy: Checks for correct DocumentRoot **5. nginx/posterg.conf** (Updated) - DocumentRoot: `/var/www/html` โ†’ `/var/www/posterg/public` - Admin location: `/formulaire/` โ†’ `/admin/` **6. .gitignore** (Updated) - Added var/ directory patterns - Keeps .gitkeep files, ignores contents ### Security Improvements **Before:** - โŒ All files in DocumentRoot (/var/www/html/) - โŒ Database accessible at /storage/test.db - โŒ Config files accessible - โŒ Dev server exposed everything - โŒ Relied on nginx deny rules **After:** - โœ… Only public/ in DocumentRoot - โœ… Database physically outside web root - โœ… Config files physically private - โœ… Dev server matches production security - โœ… Physical separation = secure by default ## ๐Ÿงช Testing ### Local Development ```bash # Start dev server just serve # Test in browser: # - http://localhost:8000/ โ†’ Should work # - http://localhost:8000/admin/ โ†’ Should work # - http://localhost:8000/storage/test.db โ†’ Should 404 โœ… # - http://localhost:8000/config/ โ†’ Should 404 โœ… # - http://localhost:8000/../storage/test.db โ†’ Should 404 โœ… ``` ### Security Verification ```bash # These should all return 404: curl http://localhost:8000/storage/test.db curl http://localhost:8000/config/bootstrap.php curl http://localhost:8000/vendor/autoload.php curl http://localhost:8000/../storage/test.db curl http://localhost:8000/lib/Database.php ``` ### Production Deployment **BEFORE deploying to production:** 1. **Update nginx config on server:** ```bash # Edit /etc/nginx/sites-available/posterg # Change: root /var/www/html; # To: root /var/www/posterg/public; ``` 2. **Create new directory on server:** ```bash ssh posterg "sudo mkdir -p /var/www/posterg" ``` 3. **Deploy application:** ```bash just deploy ``` 4. **Deploy nginx config:** ```bash just deploy-nginx # Then on server: ssh posterg sudo bash /tmp/deploy-production.sh sudo systemctl reload nginx ``` 5. **Verify:** ```bash just server-status curl -I https://posterg.erg.be/ curl -I https://posterg.erg.be/admin/ curl -I https://posterg.erg.be/storage/test.db # Must 404! ``` ## ๐Ÿ“ Path Reference ### From public/*.php files: ```php 'Title']); // Template ``` ### From public/admin/*.php files: ```php # Or abandon current changes jj abandon @ ``` ## ๐Ÿ“š Documentation See also: - `DIRECTORY_STRUCTURE.md` - Full structure reference - `DEPLOYMENT_MIGRATION.md` - Detailed migration guide - `MIGRATION_CHECKLIST.md` - Quick checklist ## โœจ Benefits Achieved 1. **Security**: Private files physically separated from public 2. **Standards**: Follows PHP-FIG and Standard PHP Package Skeleton 3. **Development**: Dev server matches production security 4. **Maintainability**: Clear separation of concerns 5. **Portability**: Path constants make relocation easy 6. **Best Practices**: Industry-standard directory structure