Hello, ZealPHP
Build a web server in three lines of PHP. No Apache. No Nginx. Just PHP.
You will learn
- What ZealPHP is and the problem it solves
- Why OpenSwoole changes what PHP can do
- The mental model: PHP IS the server
- What you'll build across 13 lessons
The three-line web server
Here is a complete web server in PHP:
<?php
require 'vendor/autoload.php';
ZealPHP\App::init('0.0.0.0', 8080)->run();
Run php app.php. Open http://localhost:8080. You have a web server.
No Apache configuration. No Nginx. No php-fpm. No .htaccess. Just PHP, running
its own HTTP server.
Why does this matter?
In traditional PHP — what you might know as the LAMP stack (Linux/Apache/MySQL/PHP) or its modern PHP-FPM cousin — you need a web server (Apache or Nginx) that listens for HTTP requests, then hands them off to PHP via FastCGI. Each request spawns a fresh process, shares nothing with other requests, and dies when done.
That architecture worked for 25 years. But it can't do WebSocket. It can't stream AI responses token-by-token. It can't share state between requests without Redis. It can't run background tasks without a queue worker. Every "modern" feature requires bolting on another service.
Traditional PHP
graph TD
B[Browser] --> N[Nginx]
N --> F[php-fpm]
F --> C[Your Code]
C --> R[(Redis)]
C --> Q[Queue Worker]
C --> WS[Node.js WebSocket]
C --> S[Supervisor]
style R fill:#fef2f2,stroke:#f87171
style Q fill:#fef2f2,stroke:#f87171
style WS fill:#fef2f2,stroke:#f87171
style S fill:#fef2f2,stroke:#f87171
6 processes · 4 config files · 3 languages
ZealPHP
graph TD
B[Browser] --> Z["php app.php"]
Z --> C[Your Code]
Z --> H[HTTP + SSE]
Z --> W[WebSocket]
Z --> SE[Sessions]
Z --> SM[Shared Memory]
Z --> T[Task Workers]
style Z fill:#fffbeb,stroke:#f59e0b,stroke-width:2px
style H fill:#ecfdf5,stroke:#059669
style W fill:#ecfdf5,stroke:#059669
style SE fill:#ecfdf5,stroke:#059669
style SM fill:#ecfdf5,stroke:#059669
style T fill:#ecfdf5,stroke:#059669
1 process · 0 config files · 1 language
The mental model
Think of traditional PHP like a restaurant with a waiter. The waiter (Nginx) takes your order, walks to the kitchen (php-fpm), waits for the chef to finish, walks back, and delivers the plate. Every customer gets this roundtrip.
ZealPHP is the chef standing at the counter. No waiter, no trip. The chef hears your order and hands you the plate directly. One process handles everything: HTTP, WebSocket, sessions, timers, shared memory.
This is possible because of OpenSwoole — a PHP extension that gives PHP an event loop, coroutines, and its own HTTP server. ZealPHP wraps OpenSwoole with a developer-friendly API: routes, templates, sessions, middleware — everything you know from traditional PHP, but running inside a persistent process.
What you'll build
ZealPHP is frontend and backend agnostic. It can serve a JSON API for a React SPA, stream HTML for htmx, or run an unmodified WordPress or Laravel app. It's a runtime, not a framework religion.
This tutorial is not a reference manual. It's a working app. Over 14 lessons, you'll build a Personal Notes app with an AI chat assistant:
- Lessons 1–4: Install ZealPHP, create pages, build layouts
- Lessons 5–8: React vs PHP, htmx, sessions, user accounts
- Lessons 9–11: Build the full app — notes CRUD, AI chat, real-time sync
- Lessons 12–14: Deep dive into routing, coroutines, deployment
Every lesson you scroll through is also a page in the real app. The code that renders
this lesson is the same code that powers the interactive demos. Register an account in Lesson 7,
save notes in Lesson 8, and chat with an AI agent in Lesson 9 — all served from one
php app.php process.
Key Takeaways
- ZealPHP is a PHP framework built on OpenSwoole — PHP runs its own HTTP server
- One process handles HTTP, WebSocket, SSE, sessions, and shared memory
- No Apache, Nginx, Redis, or queue workers needed for most apps
- ZealPHP modernizes the Apache/FPM half of the LAMP stack — keep your DB, swap the request model
- This tutorial builds a real Notes + AI Chat app across 13 lessons