Article
Legacy PHP Project Structure Modernization
Separate the public document root from application code and adopt a practical public/src/config/storage/tests layout without forcing a framework.
Many inherited apps place index.php, configuration with database passwords, upload directories, and class files all inside the Apache or nginx document root. That layout worked when “FTP the folder” was the deploy model. It is a liability once scanners request /config/database.php or leftover backup files.
Modern structure is not one framework’s opinion forced onto every codebase. It is a practical separation: only the front controller and static assets are web-reachable; application code, config, and storage live beside or above the document root.
/var/www/html/
index.php
admin/
includes/
config.php ← credentials web-reachable if misconfigured
uploads/
templates/
/var/www/app/
public/ ← document root
index.php
assets/
src/
config/ ← outside docroot
templates/
storage/
logs/
cache/
tests/
vendor/
composer.json
Why document root separation matters
- Reduces accidental exposure of config, composer files, and VCS metadata
- Makes “only public/ is served” an infrastructure rule instead of an .htaccess hope
- Clarifies where uploads and logs belong so they are not executable PHP
Migration without a rewrite
- Create
public/and move the front controller and assets there. - Point the vhost document root at
public/; keep a rollback vhost snippet. - Move config above the docroot and update path constants once.
- Leave legacy class directories in place initially; introduce
src/for new code. - Block execution in upload directories; store user files under
storage/when possible.
Pair with Composer, security modernization, and nginx + PHP-FPM or Apache FPM guides. Compare configs with Config Diff.
Related reading
- Composer Modernization Center Add Composer to legacy PHP projects, migrate includes to autoloading, set platform constraints, and replace a…
- PHP 5 to Modern PHP: Complete Incremental Migration Guide A deep, production-minded path from PHP 5.x codebases to supported PHP 8.x: removed extensions, charset, PDO,…
- PHP Security Modernization for Legacy Applications Upgrade inherited PHP security practices: prepared statements, password hashing, sessions, CSRF, XSS escaping…
- PHP 7 to PHP 8 Migration Guide Deep guide to PHP 8.0 breaking changes that matter for PHP 7 applications, with upgrade tactics through suppo…
- Inheriting a Legacy PHP Application A first-30-days playbook for developers handed an unfamiliar PHP codebase: runtime truth, risk triage, and sa…