mirror of
https://codeberg.org/PostERG/xamxam.git
synced 2026-05-07 11:39:18 +02:00
More semantically accurate: contains SQLite files, schema, fixtures, test data. Updated all references in code, scripts, docs.
6.4 KiB
6.4 KiB
✅ 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
# 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
# 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:
-
Update nginx config on server:
# Edit /etc/nginx/sites-available/posterg # Change: root /var/www/html; # To: root /var/www/posterg/public; -
Create new directory on server:
ssh posterg "sudo mkdir -p /var/www/posterg" -
Deploy application:
just deploy -
Deploy nginx config:
just deploy-nginx # Then on server: ssh posterg sudo bash /tmp/deploy-production.sh sudo systemctl reload nginx -
Verify:
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
require_once __DIR__ . '/../config/bootstrap.php'; // Bootstrap
require_once LIB_ROOT . '/Database.php'; // Library
$db = getDatabase(); // Database
view('header.php', ['pageTitle' => 'Title']); // Template
From public/admin/*.php files:
<?php
require_once __DIR__ . '/../../config/bootstrap.php'; // Bootstrap
require_once LIB_ROOT . '/Database.php'; // Library
Available Constants (from bootstrap):
APP_ROOT- /path/to/posterg-websitePUBLIC_ROOT- /path/to/posterg-website/publicCONFIG_ROOT- /path/to/posterg-website/configDATABASE_ROOT- /path/to/posterg-website/databaseDATABASE_PATH- /path/to/posterg-website/storage/test.dbRESOURCES_ROOT- /path/to/posterg-website/resourcesLIB_ROOT- /path/to/posterg-website/libVAR_ROOT- /path/to/posterg-website/varCACHE_ROOT- /path/to/posterg-website/var/cacheLOGS_ROOT- /path/to/posterg-website/var/logsVIEWS_ROOT- /path/to/posterg-website/resources/views
🎯 Next Steps
- ✅ Migration complete - verify locally
- ⏭️ Test dev server:
just serve - ⏭️ Test all pages work correctly
- ⏭️ Update nginx config on production server
- ⏭️ Deploy to production:
just deploy - ⏭️ Deploy nginx config:
just deploy-nginx - ⏭️ Verify production deployment
🔄 Rollback (if needed)
If something goes wrong, jj makes it easy:
# View history
jj log
# Go back to previous state
jj edit <previous-change-id>
# Or abandon current changes
jj abandon @
📚 Documentation
See also:
DIRECTORY_STRUCTURE.md- Full structure referenceDEPLOYMENT_MIGRATION.md- Detailed migration guideMIGRATION_CHECKLIST.md- Quick checklist
✨ Benefits Achieved
- Security: Private files physically separated from public
- Standards: Follows PHP-FIG and Standard PHP Package Skeleton
- Development: Dev server matches production security
- Maintainability: Clear separation of concerns
- Portability: Path constants make relocation easy
- Best Practices: Industry-standard directory structure