System Documentation

Lighttp v1.0

Lightweight PHP CMS — Fast, Secure, Elegant

Version: 1.0 Release: June 2026 License: MIT Developer: Dr.liehuo

Table of Contents

1. Introduction

Welcome to Lighttp — the lightweight content management system.

Lighttp is a high-performance, secure, and elegant CMS built with PHP, MySQL, and Redis. It is designed for developers and content creators who value speed, code quality, and simplicity.

Key Features

Quick Start: Deploy Lighttp in under 5 minutes with the Composer installer.

2. System Requirements

Minimum Requirements

Component Version
Web ServerNginx 1.18+ / Apache 2.4+
PHP7.4, 8.0, 8.1, 8.2, 8.3
MySQL5.7+ / MariaDB 10.3+
Redis5.0+
Memory512MB minimum, 1GB recommended
Disk Space100MB minimum

Required PHP Extensions

Verify PHP Extensions

# Check installed PHP extensions
php -m | grep -E "mysql|redis|mbstring|json|curl"

3. Installation Guide

Quick Installation (Recommended)

# Step 1: Create project via Composer
composer create-project lighttp/cms my-site

# Step 2: Navigate to project directory
cd my-site

# Step 3: Run installation script
php lighttp install

# Step 4: Follow interactive prompts
# - Enter database credentials
# - Set admin username and password
# - Configure Redis settings

# Step 5: Start development server
php -S localhost:8080 -t public

Manual Installation

# Step 1: Clone the source code
git clone https://github.com/Drliehuo/inetpub.github.io/tree/main/lighttp/src my-site
cd my-site

# Step 2: Install dependencies
composer install --no-dev

# Step 3: Configure environment
cp .env.example .env
nano .env  # Edit database and Redis settings

# Step 4: Run database migration
php lighttp migrate

# Step 5: Create admin user
php lighttp user:create admin admin@example.com password123

# Step 6: Set file permissions
chmod -R 755 var/
chmod -R 755 public/uploads/

Web Server Configuration

Nginx

server {
    listen 80;
    server_name your-domain.com;
    root /var/www/lighttp/public;
    index index.php;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Apache

<VirtualHost *:80>
    ServerName your-domain.com
    DocumentRoot /var/www/lighttp/public
    <Directory /var/www/lighttp/public>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>
Important: For production environments, always set APP_DEBUG=false in your .env file.

4. Directory Structure

Lighttp follows a clean and organized directory structure:

/
├── app/
│   ├── core/           # Core framework classes
│   │   ├── Application.php
│   │   ├── Database.php
│   │   └── RedisCache.php
│   ├── controllers/    # Application controllers
│   │   ├── HomeController.php
│   │   ├── AdminController.php
│   │   └── AuthController.php
│   ├── models/         # Data models
│   │   ├── Article.php
│   │   ├── Category.php
│   │   └── User.php
│   ├── config/         # Configuration files
│   │   └── config.php
│   └── routes.php      # Route definitions
├── public/             # Web root directory
│   ├── index.php       # Entry point
│   ├── .htaccess       # Apache rewrite rules
│   ├── css/            # Stylesheets
│   ├── js/             # JavaScript files
│   └── uploads/        # User uploaded files
├── var/                # Runtime data
│   ├── cache/          # Cache storage
│   ├── logs/           # Application logs
│   └── sessions/       # Session storage
├── .env                # Environment configuration
└── composer.json       # Composer dependencies

5. Configuration

All configuration is managed through the .env file and app/config/config.php.

Environment Variables (.env)

# Database Configuration
DB_HOST=localhost
DB_PORT=3306
DB_NAME=lighttp
DB_USER=root
DB_PASS=your_password

# Redis Configuration
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_PASSWORD=
REDIS_DATABASE=0

# Application Settings
APP_NAME=Lighttp
APP_DEBUG=true
APP_TIMEZONE=Asia/Shanghai
APP_PER_PAGE=10

Application Config (config.php)

return [
    'database' => [
        'host' => env('DB_HOST', 'localhost'),
        'port' => env('DB_PORT', 3306),
        'database' => env('DB_NAME', 'lighttp'),
        'username' => env('DB_USER', 'root'),
        'password' => env('DB_PASS', ''),
        'charset' => 'utf8mb4',
    ],
    'cache' => [
        'enabled' => true,
        'host' => env('REDIS_HOST', '127.0.0.1'),
        'port' => env('REDIS_PORT', 6379),
        'prefix' => 'lighttp:',
        'default_ttl' => 3600,
    ],
    'app' => [
        'name' => env('APP_NAME', 'Lighttp'),
        'debug' => env('APP_DEBUG', false),
        'timezone' => env('APP_TIMEZONE', 'UTC'),
        'per_page' => env('APP_PER_PAGE', 10),
    ],
];
Tip: Use the env() helper function to access environment variables throughout your application.

6. Database Setup

Lighttp uses MySQL/MariaDB with PDO for database operations. The system includes 12 core tables:

Table Description
articlesContent articles and posts
categoriesContent categories
usersUser accounts
commentsUser comments
pagesStatic pages
linksFriend links
settingsSystem settings
cacheDatabase cache (fallback)
logsAudit logs
sessionsUser sessions
tagsContent tags
article_tagsArticle-tag relationships

Run Migrations

# Run all migrations
php lighttp migrate

# Rollback last migration
php lighttp migrate:rollback

# Check migration status
php lighttp migrate:status
Warning: Always backup your database before running migrations in production.

7. Admin Dashboard

The admin dashboard provides a comprehensive interface for managing your content and system settings.

Accessing the Dashboard

https://your-domain.com/admin

Default Admin Credentials

Field Value
Usernameadmin
Passwordadmin123
Critical: Change the default password immediately after first login!

Dashboard Sections

8. Content Management

8.1 Articles

Articles are the primary content type in Lighttp. Each article includes:

Creating an Article

# Via command line
php lighttp article:create "My First Article" --content="Full content here" --category=1

# Via web interface
# Navigate to /admin/article/create

8.2 Categories

Categories help organize articles. Features include:

8.3 Pages

Static pages for content like About, Contact, and Privacy Policy.

9. User Management

Lighttp includes a complete user management system with role-based permissions.

User Roles

Role Permissions
adminFull system access, user management, settings
editorCreate and manage all content
authorCreate and manage own content
subscriberRead-only access

User Commands

# Create a new user
php lighttp user:create username email password

# Change user password
php lighttp user:password username newpassword

# List all users
php lighttp user:list

# Delete a user
php lighttp user:delete username

10. Cache System

Lighttp uses Redis for powerful multi-level caching.

Cache Levels

Cache Commands

# Clear all cache
php lighttp cache:clear

# Clear page cache only
php lighttp cache:clear --type=page

# Clear data cache only
php lighttp cache:clear --type=data

# Check cache status
php lighttp cache:status

Cache Configuration

return [
    'cache' => [
        'enabled' => true,
        'host' => '127.0.0.1',
        'port' => 6379,
        'prefix' => 'lighttp:',
        'default_ttl' => 3600,  // 1 hour
    ],
];
Performance Tip: Redis caching can reduce database queries by up to 90% and improve response times by 10x.

11. Security Features

Lighttp implements multiple security layers to protect your content and users.

Security Measures

Security Best Practices

# Always set APP_DEBUG=false in production
APP_DEBUG=false

# Use strong passwords (min 12 characters, mixed case)
# Keep system and PHP updated
# Use HTTPS/SSL in production
# Regularly backup database
# Monitor access logs
Security Warning: Never expose sensitive configuration files (.env, config.php) to the public web.

12. API Reference

Lighttp provides a RESTful API for content management and integration.

API Endpoints

Method Endpoint Description
GET/api/articlesList all articles
GET/api/articles/{id}Get article by ID
POST/api/articlesCreate new article
PUT/api/articles/{id}Update article
DELETE/api/articles/{id}Delete article
GET/api/categoriesList all categories
GET/api/usersList users (admin only)

Authentication

API uses Bearer token authentication:

# Example request
curl -X GET https://your-domain.com/api/articles \
    -H "Authorization: Bearer your_api_token"

Response Format

{
    "status": "success",
    "data": {
        "id": 1,
        "title": "Sample Article",
        "content": "Full article content...",
        "created_at": "2026-06-22 10:00:00"
    }
}

13. Troubleshooting

Common Issues

Error: Database connection failed

Error: Redis connection failed

Error: 404 Not Found

Error: Permission denied

Error: Class not found

Logs: Check var/logs/ directory for detailed error information.

14. Support & Contact

Getting Help

Developer Information

Item Details
DeveloperDr.liehuo (烈火帝君)
Emailwebmaster@inetpub.cn
LicenseMIT Open Source
Repositoryhttps://github.com/Drliehuo/inetpub.github.io/tree/main/lighttp/src

Contributing

We welcome contributions from the community! Please read our contributing guidelines before submitting pull requests.

Thank You! Lighttp is built with passion and dedication. We appreciate your support and feedback.