Deploy a free WordPress on fly.io

Fly.io is a very easy to use SaaS platform like Heroku, which offers a few free allowances for startup.

  • Up to 3 shared-cpu-1x 256mb VMs
  • 3GB persistent volume storage (total)
  • 160GB outbound data transfer

That means we can create up to 3 small apps, each app with 256MB of RAM and using a one shared CPU.

More about free allowances.

Let’s Get Started!

We will create two applications: MySQL and WordPress, also need to create two volumes to store database data and uploaded files. The code for this article is on blackstorm/wordpress-fly

Requirement

I was using Google Cloud Shell for this tutorial which provided a running on browser editor and pre-installed several helpful components like Docker / Kubectl.

Or you can manually install the require components on your local machine.

Our workspace directory like this.

├── LICENSE
├── README.md
├── database
│   └── fly.toml
└── wordpress
    └── fly.toml

Launch MySQL

We are going to use the official MySQL image. There are a few main things done here.

  1. Set the default database name and root user password (You can change it)
  2. Add some configs to support MySQL running on small memory instance.
  3. Mount data volume.
app = "mysql-database"
kill_signal = "SIGINT"
kill_timeout = 5
processes = []
[env]
  MYSQL_DATABASE = "wp"
  MYSQL_ROOT_PASSWORD = "my-secret-pw"
[build]
  image = "mysql:8"
[experimental]
  cmd = [
      "--performance_schema=off",
      "--key_buffer_size=16M",
      "--tmp_table_size=1M",
      "--innodb_buffer_pool_size=1M",
      "--innodb_log_buffer_size=1M",
      "--max_connections=25",
      "--sort_buffer_size=512K",
      "--read_buffer_size=256K",
      "--read_rnd_buffer_size=512K",
      "--join_buffer_size=128K",
      "--thread_stack=196K",
      "--bind-address=::",
      "--character-set-server=utf8mb4", "--collation-server=utf8mb4_unicode_ci", "--default-authentication-plugin", "mysql_native_password", "--datadir", "/data/mysql"]
[mounts]
  destination = "/data"
  source = "mysqldata"

Don’t forget to create a volume before launch MySQL. We can use up to 2GB volume. Here recommend using 1GB for the database.

fly volumes create mysqldata --size 1

Now release MySQL

fly launch

Launch WordPress

app = "wordpress"

[env]
  WORDPRESS_DB_HOST = "mysql-database.internal"
  WORDPRESS_DB_NAME = "wp"
  WORDPRESS_DB_USER = "root"
  WORDPRESS_DB_PASSWORD = "my-secret-pw"
  WORDPRESS_CONFIG_EXTRA = "define(\"MYSQL_CLIENT_FLAGS\", MYSQLI_CLIENT_SSL);"

[mounts]
  destination = "/var/www/html"
  source = "wordpressdata"

[build]
  image = "wordpress:6-php8.0-apache"

[[services]]
  internal_port = 80
  protocol = "tcp"
  [services.concurrency]
    hard_limit = 50
    soft_limit = 25

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.ports]]
    handlers = ["http"]
    port = 80
    force_https = true

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = 5000
    timeout = 2000

Like create MySQL, before launch the WordPress instance we need create a volume for file store first. Here you can use 1GB or 2GB, depending mainly on the free volume left in your account.

fly volumes create wordpressdata --size 1

Launch WordPress

fly launch

After successfully launching, you may need to bind a domain. It is easy to bind a domain and fly.io will obtain and renew SSL for the domain automatically.

Watch your bill

The key to making the plan free is to follow the free allowance.

links

Leave a Reply

Your email address will not be published.