← All posts

Building a flat-file CMS with PHP and JSON

April 22, 2026 · Dervic

The whole idea

A flat-file CMS stores everything in JSON files instead of a database. It runs anywhere PHP runs - shared hosting, a VPS, even a Raspberry Pi.

Reading posts

<?php
function posts() {
    return json_decode(file_get_contents(__DIR__ . '/data/posts.json'), true);
}

Rendering safely

Always escape output:

echo htmlspecialchars($post['title'], ENT_QUOTES, 'UTF-8');

Why it scales

For a personal site or a small shop, JSON is fast enough and has zero setup. Read the tutorial, then [get the blog template](/scripts) and run it on your own server.

php