Structure of a PHP Project
Folder and file organization
Even a small PHP project benefits from a clear structure. Typical layout: public/ (index.php, assets), inc/ or src/ (config, db, auth), templates/ (views), storage/ (uploads, cache), vendor/ (Composer packages). The config file holds database credentials; never commit it to Git with real passwords – use a .env example.
Recommended folders
- public/index.php – the only entry point for the web server.
- inc/db.php – PDO connection.
- inc/auth.php – session and login check.
- templates/ – header, footer, form partials.
Naming
Use lowercase and hyphens in URLs (user-profile.php or ?page=profile). PSR-4 autoload maps namespaces to folders when you move to OOP.
project/
public/index.php
inc/config.php
inc/db.php
templates/layout.php
storage/uploads/
vendor/ (composer)Working in the local environment
Create the folder htdocs/php-kurs inside XAMPP htdocs. Practice each new topic in a separate file (e.g. struktura-php-projekta.php) to track your progress easily. Keep Developer Tools (F12) open – the Network and Console tabs speed up learning.
