Publishing this website on Cloudflare
As with all developers, I've created numerous personal websites over the years, but they all ended up in the digital graveyard without ever finished them. It's high time for a change!
My latest attempt was with Statamic, which is a Laravel-based CMS. It doesn't have to rely on a database, instead it can stores data in flat files. And it has the option to generate a static version of your app. Making it perfect for static hosting and fewer expenses since I don't need a server.
I could have gone with established SSG options like Hugo or Astro, but I've been developing mostly with Laravel and needed a reason to dip my toes into Statamic.
Vercel
I started out by following the Statamic guide for deploying to Vercel, which works fine. However, I had to stick to PHP 7.4, which reached its end of life in 2022. With the 8.3 release approaching, I began looking for a different approach.
Domain
I've been searching for a specific domain for years without success, which is probably one of the main reasons I never launched. I've emailed multiple owners without success. A few days ago, I noticed that vanpachtenbeke.com
was available, so I didn't hesitate and went for it. Finally my long-prepared blog found its home on Cloudflare.
Cloudflare Pages and Workers
Cloudflare Pages is a platform for deploying static websites. It offers a generous free tier, which is perfect for this small project. It has excellent performance and an easy-to-use UI with Git integration.
Cloudflare Workers are used to deploy serverless code to Pages. Unfortunately, in the latest version (v2), PHP isn't available anymore, and v1 only supports PHP 7.4. I decided not to use the Git integration and instead opted for my own Github Action for deployment.
For those interested in the deployment file:
name: Deploy on: push: branches: - main jobs: deploy: runs-on: ubuntu-latest name: Deploy steps: - uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.2' coverage: none - name: Install composer dependencies uses: ramsey/composer-install@v2 - name: Run statamic/ssg run: | npm install npm run build php please ssg:generate - name: Deploy to Cloudflare Pages uses: cloudflare/pages-action@v1 with: apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} projectName: ${{ secrets.CLOUDFLARE_PROJECT_NAME }} directory: storage/app/static gitHubToken: ${{ secrets.GITHUB_TOKEN }}
Now each push to Github triggers a new deploy. It's as easy as that! Github's free tier gives you 2 000 CI/CD minutes each month. Each deploy takes around 1 minute, so that should be enough.
Much more to offer
Cloudflare has much more to offer on the free tier.
Probably the most noteworthy is Cloudflare Functions. If I ever need dynamic functionality, I can deploy server-side code without running a dedicated server.
Also pretty useful: Analytics, Email routing, SSL encryption, DDoS protection, Brotli compression (with gzip fallback), Automatic HTTPS Rewrites, Region-based speed tests, and more.
Go check it out!