Skip to main content

Developing with Devbox

Jethro is an open source (GPL) project, with collaboration taking place mainly on issues on Github.

Local development with Devbox​

Jethro's system requirements are listed in README.md.

A fast way to get Jethro running from source is with the bundled Devbox, a tool for isolated development environments. Jethro's source distribution comes with a devbox install script and a basic Devbox configuration, requiring just one command to bring up a Nginx web server, MariaDB database and PHP-FPM backend running Jethro.

To get started, run ./devbox services up -b

$ ./devbox services up -b
Starting all services: nginx-access, nginx-error, php-fpm, jethro, jethro_database_setup, mariadb, mariadb_logs, nginx
Process-compose is now running on port 38489
To stop your services, run `devbox services stop`

This will:

  • download the full devbox binary if you don't already have it (./devbox is a stub 1 ).
  • download binaries for php, nginx and mariadb. This will take a few minutes the first time.
  • install Jethro's PHP dependencies (the vendor/ directory) with Composer. Composer is bundled in the devbox environment (via the php package), so no separate install is needed. This includes the dev-only SMS mock server (jethro/smsmockserver), linked into the tree as smsmockserver/ → vendor/jethro/smsmockserver.
  • launch a MariaDB database and Nginx web server in the background (-b).
  • create a jethro database in the Devbox MariaDB

Point your browser at http://localhost:<port>, where <port> is printed by devbox.d/bin/jethro_utils freeport web (stable for this checkout's path), and you should see Jethro's setup wizard.

Devbox overview​

With Devbox, you can:

  • ./devbox shell to enter the Jethro development environment, containing local versions of PHP, Nginx, MariaDB and other dev tools as specified in devbox.json. In this shell, mariadb (or mysql) connects to the devbox's jethro database (see below), other commands from devbox.d/bin are added to your $PATH. Ctrl-C to exit the shell.

  • ./devbox run <script> to run one of the scripts defined in devbox.json. E.g. devbox run lint.

  • ./devbox services [up|up -b|down|ls] to manage the Nginx, MariaDB and other services Devbox provides, preconfigured to run Jethro from source. For example, if you ran ./devbox services up -b earlier to start things, ./devbox services ls will show something like:

$ ./devbox services ls
Services running in process-compose:
PID NAME NAMESPACE STATUS AGE HEALTH RESTARTS EXIT CODE
6908 jethro default Completed 0s - 0 0
6699 nginx default Running 1m48s Ready 0 0
6698 nginx-error default Running 1m48s - 0 0
6697 mariadb default Running 1m48s Ready 0 0
6701 mariadb_logs default Running 1m48s - 0 0
6826 jethro_database_setup default Completed 0s - 0 0
6696 nginx-access default Running 1m48s - 0 0
6700 php-fpm default Running 1m48s - 0 0

Devbox services​

Devbox services are defined in process-compose.yml, augmented with services that devbox plugins provide. Devbox services can be configured by editing:

  • devbox.d/nginx/nginx.template
  • devbox.d/php/php-fpm.conf
  • devbox.d/mariadb/my.cnf

You will see references to environment variables in those config files, and often it's possible to customize Devbox services by setting a relevant environment variable in devbox.json's env rather than tweaking devbox.d/ files. The init hook runs jethro_utils env, which resolves _default_ in NGINX_WEB_PORT and FUNCTEST_WEB_PORT to ports derived from the checkout's physical path. Replace either _default_ entry in devbox.json's env with a literal port to override it; jethro_utils env prints only the variables it resolves from _default_, so a literal port is never re-exported or overwritten. Blank values are rejected. Like other config entries, these take precedence over inherited shell values. Read the configured value with ./devbox run -- printenv NGINX_WEB_PORT.

Devbox (at least, our fork of it) exports DEVBOX_RUNTIME_DIR, DEVBOX_LOG_DIR and DEVBOX_DATA_DIR before expanding env. Project configuration sets MAILPIT_SOCKET_DIR to $DEVBOX_RUNTIME_DIR/mailpit. The runtime namespace matches the plugin socket paths; log/data roots are .devbox/logs and .devbox/data. Keep MariaDB and PHP-FPM on their plugin-specific paths beneath those roots. Custom services must create private runtime subdirectories before using them. The hook locates utilities through $DEVBOX_CONFIG_DIR.

Run devbox info mariadb / devbox info php / devbox info nginx to see what's available.

You will also see a .devbox directory created. This is where Devbox constructs its virtual environment. If deleted it will be recreated on next devbox command. Of interest is:

  • .devbox/logs/process-compose.log for service logs
  • .devbox/logs/nginx/error.log for Jethro stdout/stderr
  • .devbox/virtenv/{mariadb,nginx,php}/process-compose.yaml for definitions of default devbox services, augmenting ./process-compose.yml.

How devbox services run Jethro​

Devbox's Nginx plugin defaults its web root to devbox.d/web/; devbox.json overrides NGINX_WEB_ROOT to point at devbox.d/demo/ instead (the plugin still recreates an unused, gitignored devbox.d/web/index.html). devbox.d/demo/ contains ../.. symlinks to Jethro PHP files, except for devbox.d/demo/conf.php which configures Jethro to connect to the jethro MariaDB database on 127.0.0.1:3307.

We could actually just rely on Devbox's built-in .devbox/virtenv/*/process-compose.yaml services to bring up Jethro. The ./process-compose.yml adds usability tweaks, notably a jethro_database_setup "service" which creates the jethro MariaDB user and database if they do not exist, by invoking devbox.d/bin/mariadb_ensure_db jethro (which you are free to invoke directly). It never touches existing data. devbox.d/bin/ contains other development scripts, and that directory is added to your $PATH in a devbox shell:

  • mariadb_ensure_db DB... — create the database(s) if absent, granting access to the jethro user
  • mariadb_recreate_db DB... — drop and recreate the database(s), empty (destroys data)
  • jethro_load_demodata DB [SYSTEM_NAME] — recreate DB and fill it with the demo/functional-test data
  • mariadb_dump_db DB [AS_NAME] — dump a database to stdout, normalized for reloading elsewhere
  • mariadb_as_root — a mariadb client connected as root over the unix socket
  • jethro_compile [--nouse] [VERSION] — compile the CSS/JS bundles and include/version.txt in the checkout
  • jethro_build [--with-dev] [VERSION] — jethro_compile, composer install into vendor/ (--no-dev unless --with-dev), and (re)create the dist/webroot/ symlink webroot: a production-ready checkout and dist/webroot/

Every devbox database is reachable as user jethro, password jethro, and devbox.d/mariadb/my.cnf makes that the client default — so mariadb jethro_functest -e 'select 1' (no -u/-p) just works, in scripts and tests alike.

Initially http://localhost:<port> (devbox.d/bin/jethro_utils freeport web) will show the Jethro setup wizard, reflecting the empty state of the jethro database. If you'd like to load sample data, run devbox run demodata. To wipe the jethro database again, run devbox run initdb.

Footnotes​

  1. The ./devbox file in the repo root is not the devbox binary itself, but a launcher shell script. On first run it:

    1. Downloads the real devbox binary for this repo's pinned version from the jefft/devbox GitHub releases to ~/.cache/devbox/bin/v0.17-6-jeff_linux_amd64/devbox.
    2. Creates a symlink devbox.d/bin/devbox → that cached binary.
    3. execs the binary with the same arguments you passed.

    On subsequent runs, the script skips the download and re-execs the cached binary directly.

    The devbox.d/bin/devbox symlink exists so that devbox is always findable on $PATH for internal subcommands. ↩