How to Deploy Wordpress on Fly?

Wordpress instance keeps logging out randomly, Sometimes I have to click login button 10 times to actually login, after that, sessions don’t last up to 10seconds, sometimes it lasts for a few minutes, other times, longer. It’s random and hard to reproduce

How many instances do you have in your app? If you have more than one then yes, you would probably get this; the cookie mechanism in PHP uses files by default, and they are not shared between machines. As your requests are handled by different machines, you get a logged-in or logged-out status.

I would expect there is a WP plugin to swap the default cookie system with a database-powered version.

@halfer I only have 1 instance of the Wordpress app

And just one machine in the app, right? The default is two, if memory serves correctly.

Visit https://fly.io/apps/<app-name>/machines to count them.

1 macine

primary_region = ‘ewr’

[build]

image = ‘wordpress’

[http_service]

internal_port = 80 # changed from 8080 to 80

force_https = true

auto_stop_machines = true

auto_start_machines = true

min_machines_running = 0

processes = [‘app’]

[[vm]]

memory = ‘1gb’

cpu_kind = ‘shared’

cpus = 1

fly.toml file

Another thing I noticed is that plugins are getting deactivated at random times. It feels like the files in the wordpress instance gets nuked randomly, database doesn’t change but any file change gets reset.

The Fly.io platform generally isn’t a good choice for single-Machine apps. This is closely related to what @halfer was saying above about multiple Machines.

When your instance auto-stops, you lose the entire contents of the / partition; the discussion upthread about mounts & S3-style storage touches on this overall topic.


And even if you do add a volume, you will lose it someday when the underlying physical host machine dies, :cooking:

Thank you @mayailurus

We have decided to switch from Fly.io

fwiw, it is definitely possible to deploy multiple instances of wordpress. you can install plugins in Dockerfile (just copy them to wp-content/plugins), and use a plugin such as GitHub - humanmade/S3-Uploads: The WordPress Plugin to Store Uploads on Amazon S3 to store uploads instead of the local filesystem. I’ve used such a setup in the past and it works pretty well.

Hmm, OK - that is odd behaviour. In your browser’s network tab, does your cookie supplied from the server remain the same, and is your browser supplying the same cookie once it is set? It may be worth trying another browser, just to rule out privacy plugins / no-track features.

Even though you’re only on a single instance, you could try this anyway: WordPress Native PHP Sessions – WordPress plugin | WordPress.org

You could couple it with the technique from @lillian to bake the plugin into the image. Then, as long as your database settings are available in env vars or secrets, it should be reliable.

(If this works then you may wish to scale your WP installation to more than one instance, budget permitting.)

I already did something like this.
If you want I can share my notes, but spoiler alert: Its going to cost you 12 dls/mo keep the site running
For that price you can a) pay for a droplet in digital ocean, have up to 2 small wordpress sites for 10dls a month b) find vps providers

Sorry, you can definitely deploy a wordperss site on fly but is not your best option + there is some technical nuance