Skip to main content
FreeThree checks for your projectUptime, accessibility, SEO and cookie checks for your project
All articles

Running a websiteNov 3, 20265 min read

Run your website on your own computer, on the production setup

Eric ZsigmondCo-Founder & Senior Frontend Engineer

A change works on your laptop and fails on the server. Usually the code is the same in both places, and everything around it differs. This article is for developers. It looks at why that gap exists, and at how the Tilizy CLI closes most of it by running your website locally on the setup it has in production, with a copy of the live data that is safe to keep on a laptop.

Why "works on my machine" fails

  • Versions. One PHP version on the laptop and another on the server. A database one major version apart. An extension that is installed here and missing there.
  • Services. Live has a cache and a search service. The laptop has neither, so the code that talks to them never runs before release.
  • Configuration. Web server rules, PHP limits and file permissions that nobody wrote down.
  • Data. Ten tidy records locally, years of real ones on live.
  • Drift. A local setup kept up by hand is a little different on every developer's machine, and none of them matches production.

The answer to all five is the same: stop describing the environment twice.

One project file, used everywhere

On Tilizy Hosting, how a website is built and run is described in the repository, in .tilizy/app.yaml: the PHP version, the build steps, the scheduled jobs, with the services declared beside it. The article What happens between git push and a live website shows a small one. The same file drives live, staging and your computer. The CLI reads it and starts, on your machine, the software that the platform runs for the live site.

Before the first start

You need three things on your computer: the Tilizy CLI, Docker and mkcert. The CLI is included in every Tilizy Hosting plan. You get its install command from your profile in the portal: Install the CLI has the steps. Then sign in and let the CLI look at your machine:

tilizy auth:login
tilizy cli:setup

The first command signs you in through your browser. The second lists what is still missing for your account and this computer. It does not install software for you.

Start the site

If you do not have the code yet, one command clones the project and starts it. Here the project is called my-shop:

tilizy project:setup my-shop

In a checkout you already have, start it directly:

tilizy app:start     # build and start the site
tilizy app:status    # what is running, and at which address
tilizy app:open      # open it in the browser

The start runs the build and deploy steps of your project file, as a release would, so the first one takes a while. After that the site answers at https://my-shop.localhost, over https, with a certificate your browser trusts. You edit files on your computer as usual, and a change to PHP code is live at once.

By default the local PHP image carries development tools. When you want the exact production images, ask for them:

tilizy app:start --lean

Three more commands for everyday use:

tilizy app:restart   # restart and rebuild
tilizy app:stop      # stop the site and keep its local data
tilizy app:doctor    # check the application, Docker, certificates and access

Bring the live data, without the people

A bug that shows only with real content cannot be reproduced on sample data. This command replaces your local database with a copy of the live one:

tilizy db:pull

The fields your project declares as personal data are replaced with made-up values before the copy leaves the server. What arrives on your laptop has the shape and the size of live, without the real names and addresses. Passwords are replaced as well. The live database itself is never changed.

Two things to keep in mind. The replacement covers what the project declares, in .tilizy/security.yml. When you add a field that stores something about a person, declare it in the same commit. And a copy with the real personal data is another matter. It needs a separate permission, and you should have a very good reason before you ask for it.

Uploaded files have a command of their own. Your account needs permission for it:

tilizy files:pull

Before a risky experiment, such as a migration you may have to run five times, save a checkpoint of the local database and return to it:

tilizy snapshot:create before-migration
tilizy snapshot:restore before-migration

Read the logs

When something fails, the log is the first place to look.

tilizy app:logs              # the most recent lines
tilizy app:logs -f           # keep following
tilizy app:logs php -n 300   # one service, more lines

The same command reads a hosted environment. That is useful once you have reproduced a problem locally and want to compare:

tilizy app:logs --staging
tilizy app:logs --prod

Work inside it

tilizy app:shell   # a shell in the PHP container
tilizy db:shell    # an SQL prompt on the local database
tilizy app:mail    # the local mail inbox
tilizy dev:qa      # every check your project is set up for

The tools of your framework run through the same CLI. On a Drupal project that is Drush:

tilizy drush status

Laravel projects have tilizy artisan and WordPress projects have tilizy wp.

One detail surprises people at first. In the running container your code is mounted read-only, as it is in production. A command that has to write into the code tree runs in the build container, which has the tree writable and the build tools on hand:

tilizy app:exec --build composer install

If your code writes to a path that is read-only in production, you find out here, on your own machine.

What it does not prove

Our developer tools page says that what works on your computer is "far more likely to work live". That is the right size for the claim. Your computer runs the same software from the same project file, and it is still a different machine:

  • one visitor, where live has many at once;
  • personal data that has been replaced, so a bug tied to one real record may not appear;
  • local secret values, read from .tilizy/local/.env, where live has its own;
  • your processor, your disk and your network.

So a local run does not replace a staging copy, and neither replaces looking at the live site after a release. What it removes is a whole group of avoidable surprises: the ones that come from an environment that was never the same.

The commands, grouped by area, are on the developer tools page.

Written by

Eric Zsigmond

Co-Founder & Senior Frontend Engineer

Now check your own project.

Add your project and see what it needs. The first three checks are free.