Zero Scale WordPress
Zero Scale WordPress
概要
【コスト削減】WordPressを賢く運用!Cloud Runで実現する究極のゼロスケール術
WordPress サイト、アクセスがない時もサーバー代がかかっていませんか?個人ブログや小規模サイトだと、データベースの維持費が意外と重荷ですよね…もし、WordPressが使われている時だけ費用が発生する仕組みがあったら…?と思ったことはありませんか?
そんな悩みを抱えるあなたに朗報です!🎉
この記事では、WordPress の運用コストを限りなくゼロに近づける画期的な仕組み、「Zero Scale WordPress」プロジェクトをご紹介します。Google Cloud の最先端技術を駆使し、「使わない時はお金がかからない」 WordPress 環境を実現する方法を、余すところなく解説します!
でも実は、この話、WordPress に限らないんです。Zero Scale Rails や Zero Scale Laravel など、他のフレームワークや CMS にも応用可能な考え方なんです。つまり、サーバーリソースを効率的に使うための新しいアプローチがここにあります。
この手法の技術的なキモは、Cloud Run の「起動プローブ(Startup Probe)」を利用して、必要な要素(例えばデータベース)をオンデマンドで起動し、アクセスがない時は自動的に停止させることです。これにより、WordPress の「データベース」が常時起動している必要がなくなり、コストを大幅に削減できるのです。
実際に、Zero Scale WordPress というデモサイトも公開していますので、ぜひ一度アクセスしてみてください。最初の接続だけ、1分ほど待たされますが、その後はスムーズに動作します。これは、データベースが起動するまでの時間です。
「Zero Scale WordPress」って何がそんなにスゴいの?
一番の魅力は、なんといっても劇的なコスト削減効果です!
通常、WordPress を動かすためには、ウェブサーバーとは別に MySQL などのデータベースサーバーを常時起動させておく必要があり、これが固定費としてのしかかってきます。
しかし、「Zero Scale WordPress」なら、WordPressコンテナ(ウェブサーバー)へのアクセスがない時は、データベースサーバー(Google Compute Engine の VM インスタンス)を自動的に停止させます。再びアクセスがあれば瞬時に起動し、WordPress が正常に動作するという仕組みです。
例えば、2025-05 時点の試算では、常時起動でも月額$3.50程度(T2D Spotインスタンス $3.10 + 標準永続ディスク $0.40 ※バックアップ費用別途)で運用できるデータベースインスタンスを、この仕組みで停止させることに成功すれば、これよりもさらに安く運用できる可能性があるのです。まさに、使った分だけの支払いに近づける夢のような仕組みです。
その他にも…
- 効率的なリソース活用: 必要な時だけリソースを使うので、無駄な電力消費を抑え、お財布にも環境にも優しい!
- 高いスケーラビリティ: Google Cloud Runをベースにしているので、急なアクセス増にも自動でスケールして対応可能
という利点があります。
どうやって実現するの? 「ゼロスケール」の魔法のタネ
この「ゼロスケール」を実現している主要な技術と仕組みは以下の通りです。
WordPress on Cloud Run
まず、WordPress 自体は Google Cloud のサーバーレスコンテナ実行環境である Cloud Run 上で動かします。これにより、アクセスがない時はコンテナが0になり、費用が発生しません。
データベースのオンデマンド起動 (Startup Probe)
Cloud Run の「起動プローブ(Startup Probe)」という仕組みを利用します。
WordPress コンテナが起動する際、まずデータベース(ここでは Google Compute Engine 上の のMySQL サーバー)に接続を試みます。
もし接続できなければ(DB が停止していれば)、スクリプトが Compute Engine インスタンスを自動で起動!
無事 DB が起動し接続できれば、WordPress も正常に動き出します。
ちなみに、Cloud SQL ではなく Compute Engine を採用したのは、インスタンスの起動がより高速だったため、という実践的な理由からです。Cloud SQL でも原理的には同じことが可能ですが、起動時間が長くなる可能性があります。
データベースの自動停止 (Monitoring & Pub/Sub & Cloud Functions)
Cloud Run のコンテナインスタンス数が0になった(つまりアクセスがなくなった)状態を Google Cloud Monitoring が検知します。
アクセスがなくなってから一定時間後(例: 10分後)を検知し、Pub/Sub というメッセージングサービスに通知が送られます。
この通知をトリガーとして、Cloud Functions で用意した小さな関数が実行され、Compute Engine インスタンス(MySQL サーバー)を自動的に停止します。
データはしっかり永続化
WordPress の投稿データや設定は Compute Engine の永続ディスクに保存。
画像などのアップロードファイル (wp-content/uploads
) は、Cloud Storage に保存し、Cloud Run からマウントすることで、コンテナが停止してもデータは安全です。
モダンな構成管理
WordPress 本体のバージョン管理や、テーマ・プラグインの管理は Composer を使用し、モダンで効率的な開発・運用フローを実現しています。
これらの仕組みを連携させることで、「必要な時だけ起動し、不要になったら停止する」という理想的な WordPress 環境が完成します。
以下の構成図を見ていただくと、全体の流れがよりイメージしやすいかと思います。
「Zero Scale WordPress」を体験しよう
「自分も試してみたい!」と思った方、素晴らしいです。この「Zero Scale WordPress」を実現するための詳細な設定ファイル群やスクリプトは、すべて以下のGitHubリポジトリで公開されています。
Zero Scale WordPress - GitHubリポジトリhttps://github.com/takotakot/zeroscale-wp
リポジトリ内の README.md には、さらに詳細な技術情報が記載されています。
必要なもの (ざっくり):
- Google Cloud アカウント
- Docker及びコンテナに関する基本的な知識
- gcloud コマンドラインツール
主な設定ポイント:
- Cloud Storage バケットの構成: WordPress のコアファイルやテーマ・プラグイン、アップロードファイルを格納するバケットの準備
- Cloud Build の構成: Docker イメージのビルドとデプロイを自動化する
cloudbuild.yaml
の設定 - Cloud Run の構成: 環境変数(データベース接続情報など)や、前述の Startup Probe (
startup_gce.php
) の設定 - Cloud Functions の構成: Compute Engine インスタンスを停止させる関数のデプロイ
セットアップにはある程度の技術的な知識が必要となりますが、コストを劇的に削減できる可能性を秘めたこの仕組み、挑戦してみる価値は十分にあると思います。
まとめ:WordPress運用の新しいカタチ
「Zero Scale WordPress」は、従来の常識を覆す、新しい WordPress の運用スタイルを提案します。
- 圧倒的なコストメリット
- リソースの効率的な利用
- サーバーレス技術の活用
個人ブログから小規模なビジネスサイトまで、多くの WordPress ユーザーにとって、このプロジェクトは大きな福音となるかもしれません。
ぜひ、GitHub リポジトリをチェックして、未来の WordPress 運用を体験してみてください。そして、もし試してみた方は、感想や改善点などをコメントや GitHub の Issue でフィードバックいただけると嬉しいです!
あなたの WordPress ライフが、より快適で、より経済的になりますように!
Zero Scale WordPress
Overview
[Cost Savings] Run WordPress Smartly! Achieving Ultimate Zero Scale with Cloud Run
Is your WordPress site racking up server costs even when there's no traffic? For personal blogs or small-scale sites, database maintenance fees can be a surprising burden, right? Have you ever thought, "What if there was a system where I only pay for WordPress when it's actually being used?"
Well, good news for those of you with such concerns! 🎉
In this article, we'll introduce the "Zero Scale WordPress" project, a groundbreaking mechanism to bring your WordPress operational costs as close to zero as possible. Using Google Cloud's cutting-edge technology, we'll thoroughly explain how to realize a WordPress environment where "you don't pay when you don't use it!"
But actually, this isn't just limited to WordPress. It's a concept applicable to other frameworks and CMSs like Zero Scale Rails or Zero Scale Laravel. In other words, what we have here is a new approach to using server resources efficiently.
The technical key to this method is using Cloud Run's "Startup Probe" to launch necessary components (like a database) on-demand and automatically stop them when there's no access. This eliminates the need for the WordPress database to be constantly running, significantly reducing costs.
We have also published a demo site called Zero Scale WordPress, so please feel free to check it out. Please note that the very first connection may take about a minute, but after that, it will work smoothly. This initial delay is due to the time required for the database to start up.
What's So Amazing About "Zero Scale WordPress"?
The biggest appeal, by far, is the dramatic cost-saving effect!
Normally, to run WordPress, you need to keep a database server like MySQL constantly running separately from the web server, and this becomes a fixed cost.
However, with "Zero Scale WordPress," when there's no access to the WordPress container (web server), the database server (a Google Compute Engine VM instance) is automatically stopped. When access resumes, it starts up instantly, allowing WordPress to operate normally.
For example, based on estimates from May 2025, a database instance that would cost around $3.50/month (T2D Spot instance $3.10 + standard persistent disk $0.40, excluding backup costs) even if running continuously, could potentially be operated even more cheaply if successfully stopped using this mechanism. It's truly a dream-like system that gets you closer to pay-as-you-go.
Additionally, there are other benefits:
- Efficient Resource Utilization: Since resources are only used when needed, it suppresses wasteful power consumption, making it gentle on your wallet and the environment!
- High Scalability: Being based on Google Cloud Run, it can automatically scale to handle sudden increases in traffic.
How Is It Achieved? The Magic Behind "Zero Scale"
Here are the main technologies and mechanisms that realize this "zero scale":
WordPress on Cloud Run
First, WordPress itself runs on Google Cloud's serverless container execution environment, Cloud Run. This means that when there's no access, the container count can go to zero, incurring no costs.
On-Demand Database Startup (Startup Probe)
This utilizes a Cloud Run feature called the "Startup Probe."
When the WordPress container starts, it first attempts to connect to the database (in this case, a MySQL server on Google Compute Engine).
If it can't connect (meaning the DB is stopped), a script automatically starts the Compute Engine instance!
Once the DB successfully starts and connects, WordPress also begins to operate normally.
By the way, we chose Compute Engine over Cloud SQL for a practical reason: instance startup was faster. While the same principle could work with Cloud SQL, startup times might be longer.
Automatic Database Shutdown (Monitoring & Pub/Sub & Cloud Functions)
Google Cloud Monitoring detects when the number of Cloud Run container instances becomes zero (meaning there's no more access).
After a certain period of no access (e.g., 10 minutes), a notification is sent to a messaging service called Pub/Sub.
This notification triggers a small function prepared in Cloud Functions, which then automatically stops the Compute Engine instance (MySQL server).
Data is Securely Persisted
WordPress post data and settings are saved on the Compute Engine's persistent disk.
Uploaded files like images (wp-content/uploads
) are stored in Cloud Storage and mounted by Cloud Run, so data is safe even when the container stops.
Modern Configuration Management
WordPress core version control, as well as theme and plugin management, is handled using Composer, realizing a modern and efficient development and operational flow.
By linking these mechanisms, the ideal WordPress environment—one that "starts only when needed and stops when not"—is completed.
Looking at the following architecture diagram should give you a better image of the overall flow.
Experience "Zero Scale WordPress"!
If you're thinking, "I want to try this myself!" that's fantastic. All the detailed configuration files and scripts to realize this "Zero Scale WordPress" are publicly available in the following GitHub repository:
Zero Scale WordPress - GitHub Repositoryhttps://github.com/takotakot/zeroscale-wp
The README.md
file in the repository contains even more detailed technical information.
What you'll need (roughly):
- A Google Cloud account
- Basic knowledge of Docker and containers
- The
gcloud
command-line tool
Main configuration points:
- Cloud Storage Bucket Configuration: Preparing buckets to store WordPress core files, themes, plugins, and uploaded files.
- Cloud Build Configuration: Setting up
cloudbuild.yaml
to automate Docker image building and deployment. - Cloud Run Configuration: Setting environment variables (like database connection info) and the aforementioned Startup Probe (
startup_gce.php
). - Cloud Functions Configuration: Deploying the function that stops the Compute Engine instance.
Setup requires a certain level of technical knowledge, but this mechanism, with its potential for dramatic cost reduction, is well worth the challenge.
Conclusion: A New Form of WordPress Operation
"Zero Scale WordPress" proposes a new style of WordPress operation that overturns conventional wisdom.
- Overwhelming cost benefits
- Efficient use of resources
- Utilization of serverless technology
From personal blogs to small-scale business sites, this project could be a great boon for many WordPress users.
Please check out the GitHub repository and experience the future of WordPress operation. And if you do try it, we'd be delighted if you could provide feedback, impressions, or suggestions for improvement via comments or GitHub Issues!
May your WordPress life become more comfortable and economical!
ディスカッション
コメント一覧
まだ、コメントがありません