Skip to content

Quick Start

Arthu Santiago edited this page Nov 30, 2026 · 1 revision

Quick Start

This tutorial gets KeyAnyWhere running on your own computer in about ten minutes, using the web server built into CakePHP. It is the right path to evaluate the application or to start developing. At the end you will have created the administrator account, turned on its second authentication factor and logged in.

Warning

This setup is for a local computer only: it runs in development mode, over plain HTTP, with the secrets in a file inside the project. To install KeyAnyWhere for real use, follow the production installation.

Before you start

You need a Debian 13 (or similar) computer where you can run sudo, and an authenticator app on your phone (any TOTP app, such as Aegis, Google Authenticator or 1Password). The Requirements page lists the versions.

1. Install the system packages

This step installs PHP with the extensions KeyAnyWhere uses, Composer, Git and PostgreSQL.

sudo apt update
sudo apt install -y git unzip composer postgresql php8.4-cli php8.4-intl php8.4-mbstring php8.4-pgsql php8.4-xml php8.4-zip

Check that PHP is version 8.4 or later:

php -v

2. Download the code

This step clones the repository into a keyanywhere folder and installs the PHP dependencies, including the development tools (tests, code analysis).

git clone https://github.com/arthusantiago/KeyAnyWhere.git keyanywhere
cd keyanywhere
composer install

When Composer asks Set Folder Permissions ? (Default to Y), press Enter.

3. Create the databases

KeyAnyWhere needs one database for the application and, if you will run the tests, a second one for them. This step creates a PostgreSQL user with a random password and both databases.

Generate the password and keep it in a shell variable for the next steps:

KAW_DB_PASSWORD=$(php -r 'echo bin2hex(random_bytes(16));')
sudo -u postgres psql -c "CREATE ROLE kaw LOGIN PASSWORD '$KAW_DB_PASSWORD';"
sudo -u postgres createdb --owner=kaw keyanywhere
sudo -u postgres createdb --owner=kaw keyanywhere_test

4. Create the configuration files

In development, KeyAnyWhere reads its settings from config/.env (environment variables) and config/app_local.php (settings that override config/app.php). Both come from versioned examples and are ignored by Git. composer install already created config/app_local.php in step 2. This step creates config/.env and fills in the database access and the three secrets with freshly generated values.

cp config/.env.example config/.env
sed -i \
  -e "s|^export SECURITY_SALT=.*|export SECURITY_SALT=\"$(php -r 'echo bin2hex(random_bytes(32));')\"|" \
  -e "s|^export KEY_CRIPTOGRAFIC=.*|export KEY_CRIPTOGRAFIC=\"$(php -r 'echo sodium_bin2hex(sodium_crypto_secretbox_keygen());')\"|" \
  -e "s|^export CONFIG_INICIAL_TOKEN=.*|export CONFIG_INICIAL_TOKEN=\"$(php -r 'echo bin2hex(random_bytes(32));')\"|" \
  -e "s|^export DB_DEFAULT_USER=.*|export DB_DEFAULT_USER=\"kaw\"|" \
  -e "s|^export DB_DEFAULT_PASSWORD=.*|export DB_DEFAULT_PASSWORD=\"$KAW_DB_PASSWORD\"|" \
  -e "s|^export DB_DEFAULT_NAME=.*|export DB_DEFAULT_NAME=\"keyanywhere\"|" \
  -e "s|^export DB_TEST_USER=.*|export DB_TEST_USER=\"kaw\"|" \
  -e "s|^export DB_TEST_PASSWORD=.*|export DB_TEST_PASSWORD=\"$KAW_DB_PASSWORD\"|" \
  -e "s|^export DB_TEST_NAME=.*|export DB_TEST_NAME=\"keyanywhere_test\"|" \
  config/.env

The Generating Security Keys page explains what each secret protects. Each variable in the file is described in Environment Variables.

5. Create the tables

The migrations create every table KeyAnyWhere uses. This step runs them and, optionally, loads example data.

bin/cake migrations migrate

To get ten example categories with twenty entries each (useful to see the screens with content), run:

bin/cake seeds run CategoriasSeed,EntradasSeed

The insecure password catalog is optional on a local computer. Without it, the warning about common passwords simply never appears.

6. Start the server

CakePHP has a small web server for development. This step starts it on port 8765; leave this terminal open while you use KeyAnyWhere.

bin/cake server

7. Create the administrator account

A fresh installation has no users. The first-run setup creates the first one, who is the administrator (root), and only opens with the CONFIG_INICIAL_TOKEN generated in step 4. In a second terminal, inside the keyanywhere folder, print the setup address:

echo "http://localhost:8765/users/config-inicial?token=$(grep '^export CONFIG_INICIAL_TOKEN=' config/.env | cut -d'"' -f2)"

Open the printed address in your browser and:

  1. Fill in the name, e-mail and password of the administrator and save.
  2. On the next screen, scan the QR code with your authenticator app (or, if you can't scan it, type in the app the key shown below it). Only then click Completar configuração (Complete setup): the QR code and the key are not shown again.

First-Run Setup explains this flow and its error messages.

8. Check that it worked

Open http://localhost:8765/ and log in: your e-mail in Usuário (User), your password in Senha (Password) and the current 6-digit code from your authenticator app in Segundo fator de autenticação (Second authentication factor). You should see the home page, Minha Segurança (My Security).

Next step

Clone this wiki locally