Skip to content

Preparing the Server

Arthu Santiago edited this page Nov 30, 2026 · 3 revisions

Preparing the Server

This page installs everything KeyAnyWhere needs on a fresh Debian 13 server: Apache with PHP 8.4, Composer, Git and PostgreSQL. Then it creates the database and the database user the application will use. At the end, the server is ready to receive the code.

Before you start

You need a Debian 13 server where you can run sudo, and the decisions from the Production Overview made.

1. Install the packages

This step installs the web server, PHP with the extensions KeyAnyWhere uses, the tools to download the code and PostgreSQL.

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

Turn on the Apache modules for URL rewriting, HTTPS and security headers:

sudo a2enmod rewrite ssl headers

2. Check the PHP version and extensions

KeyAnyWhere needs PHP 8.4 or later with the extensions listed in Requirements. This command prints the version and any required extension that is missing:

php -r 'echo PHP_VERSION, PHP_EOL; foreach (["intl","mbstring","pdo_pgsql","sodium","openssl","iconv","json","xml"] as $e) { if (!extension_loaded($e)) echo "MISSING: $e", PHP_EOL; }'

The output should be just the version, for example:

8.4.16

3. Create the database and its user

The application connects to PostgreSQL with its own user, which owns only the KeyAnyWhere database. This step creates both, with a password you type (it is not shown and not saved in your shell history).

sudo -u postgres createuser --pwprompt kaw
sudo -u postgres createdb --owner=kaw --encoding=UTF8 keyanywhere

Keep this password at hand: it goes into the environment file in Environment Variables.

Tip

For more hardening of PostgreSQL in production (listening addresses, pg_hba.conf, backups), the post PostgreSQL em produção (in Portuguese) is a good complement.

4. Check that it worked

Connect to the new database with the new user, over TCP like the application will. Type the password when asked:

psql "host=127.0.0.1 dbname=keyanywhere user=kaw" -c 'SELECT current_user, version();'

The output shows kaw and the PostgreSQL version.

KeyAnyWhere requires an encrypted connection to PostgreSQL (sslmode=require) and refuses a server without SSL. Debian's package turns SSL on by default, with a self-signed certificate. Check it:

psql "host=127.0.0.1 dbname=keyanywhere user=kaw" -tAc 'SHOW ssl;'

The answer must be on. If it is off, see Troubleshooting.

Next step

Installing KeyAnyWhere

Clone this wiki locally