# miniPHP A tiny PHP starter project for small websites and personal projects. The goal is simple: * Clone * Change git remote * Start building No framework. No Composer. No external dependencies. No ORM. No dependency injection. No magic. Just PHP. --- ## Features * Zero dependencies * No Composer required * Simple config-based router * Page and API endpoints * SQLite support via PDO * Shared partials * Secure path traversal protection * Helper functions * Development server script --- ## Requirements * PHP 8.1+ * SQLite extension (optional) Check installed extensions: ```bash php -m ``` --- ## Project Structure ```text config/ ├── database.php └── routes.php public/ ├── css/ │ └── app.css └── js/ └── app.js src/ ├── api/ ├── views/ │ ├── pages/ │ └── partials/ ├── bootstrap.php ├── database.php ├── helpers.php └── router.php storage/ └── database.sqlite index.php server.sh ``` --- ## Running Start the development server: ```bash ./server.sh ``` Default URL: ```text http://127.0.0.1:3333 ``` --- ## Routes Routes are defined in: ```php config/routes.php ``` Example: ```php return [ 'GET' => [ '/' => 'home.php', '/about' => 'about.php', '/api/test' => 'api/example.php', ], ]; ``` ## Route Prefixes Routes can be mapped to different source directories using prefixes. By default: ```text src/views/pages/ ``` is used for normal pages. The router also supports configurable route prefixes: ```php $route_bases = [ 'api/' => ROOT . '/src/api', ]; ``` Example: ```php '/api/users' => 'api/users.php', ``` loads: ```text src/api/users.php ``` while: ```php '/about' => 'about.php', ``` loads: ```text src/views/pages/about.php ``` ### Adding A New Route Type Create a new directory: ```text src/docs/ ``` Then add a prefix: ```php $route_bases = [ 'api/' => ROOT . '/src/api', 'docs/' => ROOT . '/src/docs', ]; ``` Now: ```php '/docs/getting-started' => 'docs/getting-started.php', ``` will load: ```text src/docs/getting-started.php ``` No router changes required. --- ## Adding A New Page ### 1. Create the page Create: ```text src/views/pages/contact.php ``` Example: ```php 'Contact']); ?>

Contact

Get in touch.

[ '/contact' => 'contact.php', ], ``` Visit: ```text http://localhost:3333/contact ``` --- ## Adding An API Endpoint ### 1. Create the endpoint Create: ```text src/api/contact.php ``` Example: ```php true]); ``` ### 2. Add the route ```php 'GET' => [ '/api/contact' => 'api/contact.php', ], ``` Visit: ```text http://localhost:8000/api/contact ``` --- ## SQLite Database configuration: ```php config/database.php ``` Usage: ```php $db = db(); $rows = $db->query('SELECT * FROM users')->fetchAll(); ``` --- ## Helpers Available helpers: ```php escape_string() debug() debugx() get_config() partial() ``` --- ## Philosophy miniPHP intentionally avoids framework features. If a feature can be implemented with plain PHP and a few lines of code, prefer that approach. The goal is to remain small, understandable, and easy to clone for future projects. --- ## License MIT