Added init script + update Readme with its details.

This commit is contained in:
2026-05-31 07:47:45 +02:00
parent 181128d13f
commit 448228e3ad
2 changed files with 138 additions and 71 deletions
+77 -67
View File
@@ -1,21 +1,29 @@
# miniPHP
A tiny PHP starter project for small websites and personal projects.
A tiny PHP project template for small websites, internal tools, APIs, and personal projects.
miniPHP is not a framework.
There is no Composer requirement, no dependency injection container, no ORM, no service providers, and no framework lifecycle to learn.
Just plain PHP with a simple router, helper functions, optional SQLite support, and a project structure that stays out of your way.
## Philosophy
The goal is simple:
* Clone
* Change git remote
* Start building
1. Clone the repository
2. Run `init_miniphp.sh`
3. Start building
No framework.
No Composer.
No external dependencies.
No ORM.
No dependency injection.
No magic.
If a feature can be implemented with a few lines of plain PHP, prefer that approach.
Just PHP.
miniPHP exists for developers who want:
* A clean starting point
* Full control over their code
* Zero framework lock-in
* Zero external dependencies
---
@@ -25,20 +33,54 @@ Just PHP.
* No Composer required
* Simple config-based router
* Page and API endpoints
* Route prefix support
* SQLite support via PDO
* Shared partials
* Secure path traversal protection
* Shared view partials
* Helper functions
* Path traversal protection
* Development server script
* Project initialization script
---
## Quick Start
Clone the repository:
```bash
git clone <repository-url> my-project
cd my-project
```
Initialize the project:
```bash
./init_miniphp.sh
```
The initializer will:
* Remove the template git remote
* Generate a new README
* Prepare the project for a new repository
Then create your own repository and connect it:
```bash
git remote add origin <your-repository-url>
git push -u origin main
```
Start building.
---
## Requirements
* PHP 8.1+
* SQLite extension (optional)
* PDO SQLite extension (optional)
Check installed extensions:
View installed extensions:
```bash
php -m
@@ -57,7 +99,7 @@ public/
├── css/
│ └── app.css
└── js/
└── app.js
└── app.js
src/
├── api/
@@ -74,6 +116,7 @@ storage/
index.php
server.sh
init_miniphp.sh
```
---
@@ -94,7 +137,7 @@ http://127.0.0.1:3333
---
## Routes
## Routing
Routes are defined in:
@@ -114,19 +157,15 @@ return [
];
```
## Route Prefixes
### Route Prefixes
Routes can be mapped to different source directories using prefixes.
By default:
By default page routes resolve to:
```text
src/views/pages/
```
is used for normal pages.
The router also supports configurable route prefixes:
Additional route prefixes can be registered:
```php
$route_bases = [
@@ -158,7 +197,7 @@ loads:
src/views/pages/about.php
```
### Adding A New Route Type
### Creating New Route Types
Create a new directory:
@@ -166,7 +205,7 @@ Create a new directory:
src/docs/
```
Then add a prefix:
Register it:
```php
$route_bases = [
@@ -181,19 +220,17 @@ Now:
'/docs/getting-started' => 'docs/getting-started.php',
```
will load:
resolves to:
```text
src/docs/getting-started.php
```
No router changes required.
No router modifications required.
---
## Adding A New Page
### 1. Create the page
## Pages
Create:
@@ -210,20 +247,10 @@ Example:
<p>Get in touch.</p>
<?php
partial('footer');
<?php partial('footer'); ?>
```
### 2. Add the route
Edit:
```php
config/routes.php
```
Add:
Register the route:
```php
'GET' => [
@@ -239,9 +266,7 @@ http://localhost:3333/contact
---
## Adding An API Endpoint
### 1. Create the endpoint
## API Endpoints
Create:
@@ -258,10 +283,10 @@ declare(strict_types=1);
header('Content-Type: application/json');
echo json_encode(['success' => true]);
echo json_encode([ 'success' => true, ]);
```
### 2. Add the route
Register the route:
```php
'GET' => [
@@ -269,17 +294,11 @@ echo json_encode(['success' => true]);
],
```
Visit:
```text
http://localhost:8000/api/contact
```
---
## SQLite
## Database
Database configuration:
Configuration:
```php
config/database.php
@@ -297,7 +316,7 @@ $rows = $db->query('SELECT * FROM users')->fetchAll();
## Helpers
Available helpers:
Included helpers:
```php
escape_string()
@@ -309,16 +328,7 @@ 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
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
set -e
echo "================================="
echo " MiniPHP Initializer"
echo "================================="
echo
# Remove git remote if it exists
if git remote get-url origin >/dev/null 2>&1; then
git remote remove origin
echo "[✓] Removed existing git remote 'origin'"
else
echo "[i] No git remote 'origin' found"
fi
echo
# Gather README information
read -rp "Project title: " PROJECT_TITLE
read -rp "Project description: " PROJECT_DESCRIPTION
# Create README
cat > README.md << EOF
# ${PROJECT_TITLE}
${PROJECT_DESCRIPTION}
EOF
echo "[✓] Generated README.md"
echo
echo "================================="
echo " Next Steps"
echo "================================="
echo
echo "Create a new repository and add it as the remote:"
echo
echo " git remote add origin <your-repo-url>"
echo " git branch -M main"
echo " git push -u origin main"
echo
# Optional self-delete
read -rp "Delete init_miniphp.sh? [y/N]: " DELETE_SCRIPT
case "$DELETE_SCRIPT" in
[yY]|[yY][eE][sS])
SCRIPT_PATH="$(realpath "$0")"
echo "[✓] Removing $SCRIPT_PATH"
rm -f "$SCRIPT_PATH"
;;
*)
echo "[i] Keeping init_miniphp.sh"
;;
esac
echo
echo "[✓] Initialization complete"