Skip to main content

Getting Started

Quick Start

# Install TeensyPHP CLI globally
composer global require daniel-samson/teensyphp

# Create a new project
teensyphp new my-app

# Navigate to project and install dependencies
cd my-app
composer install

# Start the development server
composer dev

Your app is now running:

Add to Existing Project

// 1. Install the package
// composer require daniel-samson/teensyphp

// 2. Create bootstrap.php
require_once __DIR__ . "/vendor/autoload.php";

router(function() {
use_request_uri();

route(method(GET), url_path("/"), function() {
json_out(["hello" => "world"]);
});

route(method(GET), url_path("/users"), function() {
json_out(["users" => ["Alice", "Bob", "Charlie"]]);
});
});

// 3. Create public/index.php
// <?php require_once dirname(__DIR__) . "/bootstrap.php";

What is TeensyPHP?

TeensyPHP is a micro web framework for rapidly creating REST APIs and hypermedia applications. It provides a minimal set of functions for routing, request/response handling, templating, and database operations without the overhead of larger frameworks.

Requirements

RequirementVersion
PHP8.0 or higher
ComposerLatest

CLI Commands

CommandDescription
teensyphp new <project-name>Create a new TeensyPHP project
composer global updateUpdate TeensyPHP CLI to latest version
composer devStart the development server

Configuration

Copy .env.example to .env and configure your settings:

# Logging
LOG_LEVEL=debug

# MySQL Database
DATABASE_ENGINE=mysql
DATABASE_DATABASE=myapp
DATABASE_USERNAME=root
DATABASE_PASSWORD=secret
DATABASE_HOST=127.0.0.1
DATABASE_PORT=3306

# SQLite Database (alternative)
# DATABASE_ENGINE=sqlite
# DATABASE_DATABASE=../teensydb.sqlite