The blog on this site is a Doctrine entity. Posts live in a database table, the blog index queries it, the sitemap queries it, and the navigation hides the Blog link until at least one post is published. All of that worked. What didn't exist was a way to actually publish anything short of opening a shell on the production server and editing a row by hand.
I didn't want an admin panel for a blog that gets a post every few weeks, and I didn't want SSH to be part of writing. What I wanted was the workflow I already use for code: write it on a branch, review the pull request, merge it, and the deploy does the rest.
So posts are now Markdown files in the repository, and merging one is what publishes it.
Keep the database, change the source
The obvious alternative is to drop the table and render Markdown straight from
disk. I kept the database on purpose. Everything that reads posts already goes
through a repository method: the index, the article page, the sitemap, the
llms.txt file, and the count that decides whether the nav shows a Blog link.
Each of them filters on publishedAt IS NOT NULL AND publishedAt <= :now.
Rewriting those to scan a directory would have meant re-implementing sorting, filtering and scheduling in PHP for every caller. Treating the files as the source and the table as an index the app already knows how to query meant changing none of them.
The file
One file per post, named after its slug, with YAML front matter:
---
publishedAt: 2026-11-17
title: "Publishing a Symfony blog from Markdown files on deploy"
metaDescription: "…"
excerpt: "…"
---
The body, in Markdown.
The slug is the file name, so a post can't drift away from its own URL. Leaving
publishedAt out keeps the post as a draft. The loader is strict: a missing
title or description throws with the file path in the message, because a post
with an empty meta description is a worse outcome than a failed build.
The sync
A console command, app:blog:sync, walks the directory and matches each file to
a post by slug:
foreach ($this->files->all() as $file) {
$post = $this->posts->findOneBy(['slug' => $file->slug]);
$isNew = null === $post;
$post ??= new Post()->setSlug($file->slug);
$changed = $isNew
|| $post->getTitle() !== $file->title
|| $post->getBodyMarkdown() !== $file->bodyMarkdown
|| $post->getPublishedAt()?->format('c') !== $file->publishedAt?->format('c');
// …and the other fields
if (!$changed) {
continue;
}
// set every field from the file, persist
}
Two properties matter more than the code. It's idempotent: an unchanged file writes nothing, so running it on every boot costs a few queries. And it only touches posts that have a file. Rows that exist only in the database, such as drafts seeded by an older command, are left alone, so introducing the sync didn't mean migrating everything at once.
Run it on boot, not in CI
The command runs from the container entrypoint, right after Doctrine migrations:
php bin/console doctrine:migrations:migrate --no-interaction --all-or-nothing
php bin/console app:blog:sync --no-interaction \
|| echo 'Blog sync failed; posts were not updated.'
The || echo is deliberate. A malformed post file must never stop the
container from starting and take the rest of the site down with it. The gate
for a bad file is CI, not production; by the time an image boots, every file in
it has already been parsed by the test suite.
Two traps that would have published nothing
Both of these fail silently. The pull request merges green and nothing changes on the site.
The Docker build context. The project's .dockerignore excluded
**/*.md, which is a sensible default: READMEs and docs have no business in a
production image. It also excluded every blog post, so the sync would have run
against an empty directory and reported zero changes. The fix is one negation:
**/*.md
!content/blog/*.md
The deploy trigger. The deploy workflow skipped runs where only Markdown
changed, with paths-ignore: ["**/*.md"], so that a README edit wouldn't
rebuild and restart production. A merge that only adds a post is exactly that
kind of change. Narrowing it to root-level *.md (plus docs/**) keeps the
optimisation and lets post-only merges deploy.
If you build something similar, check both before you trust it. Neither is something an application test catches: they live in build and deploy configuration, not in the code.
CI as the editor
The test suite loads every real post file and holds it to a publishing bar: the meta description fits in a search result, the post links to at least one service page, and it doesn't still carry the "Draft" banner my outlines start with. A post that fails any of those can't merge, which is cheaper than noticing it on the live site.
Scheduling came almost free
Because every query already compares publishedAt with the current time,
scheduling needed no cron job: merge a post dated next Tuesday and it appears on
Tuesday without another deploy. I added one rule on top. I don't want posts
going out during working hours, so the loader moves publishedAt to the next
weekday at 18:00 Pacific, and the pages show the date only, never the time.
That rule has a time-zone trap of its own. PHP and the database run in UTC, and 18:00 Pacific is already the next day in UTC, so a post released on Monday evening would show Tuesday's date. Setting Twig's default date time zone fixes the display without touching what's stored:
twig:
date:
timezone: America/Los_Angeles
The trade-offs
This is the right size for one author and one server, and it has edges worth knowing about:
- Deleting a file doesn't unpublish the post. The sync never deletes rows, by design, so removing a post means setting it back to a draft first.
- Edits made directly in the database are overwritten on the next deploy if the post has a file. The file wins, every time, which is the point.
- Several containers booting at once would race on the same rows. With a single application container that doesn't arise; with more, the sync belongs in a one-off release step instead of the entrypoint.
None of that is clever, and that's the appeal. It's a console command, a
negation in .dockerignore and a narrower path filter, and the result is that
publishing works the same way as every other change I make. If you want a
Symfony app's content and deployment set up so that the boring path is also the
safe one, that's the kind of work I do on
Symfony API and backend development.