Database design: keys, relationships and normalization
Design tables that avoid duplicated data: primary keys, foreign keys, one-to-many and many-to-many relationships.
A folder layout and a few habits that keep a growing PHP site tidy, secure and easy to maintain.
You do not need a big framework to write clean code. You need a layout and some rules.
project/
├─ public/ <- the only folder the web server exposes
│ ├─ index.php <- front controller
│ └─ assets/ <- css, js, images
├─ app/
│ ├─ Controllers/ <- decide what to do
│ ├─ Models/ <- talk to the database
│ └─ Views/ <- HTML templates
├─ config/ <- settings (never in public/)
├─ storage/ <- logs, cache, private uploads
└─ vendor/ <- Composer packagesPutting config, app and storage outside public/ means a mistake in server settings cannot expose your passwords or code.
Every request enters public/index.php, which loads the config, finds the matching controller and prints a view.
require __DIR__ . '/../app/bootstrap.php';
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
(new Router())->dispatch($_SERVER['REQUEST_METHOD'], $path);echo. No SQL. Escape every value.{ "autoload": { "psr-4": { "App\\": "app/" } } }Then require 'vendor/autoload.php' loads your classes automatically, with no long list of require lines.
h() for every output.storage/, and show visitors a friendly page.declare(strict_types=1); at the top of files.If you keep rebuilding routing, validation, authentication and migrations, a framework such as Laravel or Symfony saves time. Learn the plain version first so you understand what the framework does for you.
Design tables that avoid duplicated data: primary keys, foreign keys, one-to-many and many-to-many relationships.
The layers that turn a basic login page into a hard target: password hashing, session settings, request checks, rate limiting and…