Configuration Methods
SQLPage supports three ways to set configuration options, listed in order of priority (highest to lowest):- Command-line arguments - Override specific settings when starting SQLPage
- Environment variables - Set via your shell or
.envfile - Configuration file - JSON, JSON5, TOML, or YAML file in
sqlpage/sqlpage.json
Configuration File
Place a configuration file atsqlpage/sqlpage.json (or use .json5, .toml, or .yaml extensions).
Example JSON configuration:
Environment Variables
All configuration parameters can be set via environment variables. Variable names are the same as the JSON configuration keys, but in UPPERCASE. You can optionally prefix variable names withSQLPAGE_.
Example:
.env File Support
SQLPage automatically loads environment variables from a.env file in the current directory or any parent directory.
Example .env file:
Key Configuration Parameters
Server Settings
Interface and port on which the web server should listen. Use
0.0.0.0 to listen on all interfaces.Like
listen_on, but specifies only the port. This option overrides the port in listen_on.Path to a UNIX socket to listen on instead of a TCP port. If specified, SQLPage will accept HTTP connections only on this socket and not on any TCP port. This option is mutually exclusive with
listen_on and port.The web address where your application is accessible (e.g., “myapp.example.com”). Used for login redirects with OIDC.
Base path of the site. If you want to host SQLPage at
https://example.com/sqlpage/, set this to /sqlpage/. When using a reverse proxy, this allows hosting SQLPage together with other applications on the same subdomain.Directory Settings
The root directory of the web server, where the
index.sql file is located. All .sql files served by SQLPage should be in this directory.The directory where the
sqlpage.json file is located. This is used to find the path to templates/, migrations/, and on_connect.sql. This parameter can only be set through environment variables or command-line arguments.Environment Mode
The environment in which SQLPage is running. Can be either
development or production.In production mode:- Error messages and stack traces are hidden from users
- SQL files are cached in memory to avoid reloading from disk
- Cache stale duration defaults to 1 second (vs 0 in development)
The duration in milliseconds that a file can be cached before its freshness is checked against the filesystem. Defaults to 1000ms (1 second) in production and 0ms in development.
Security Settings
Allow usage of the
sqlpage.exec function. Only enable this if all users with write access to SQLPage query files and to the optional sqlpage_files table on the database are trusted.The Content Security Policy to set in the HTTP headers. If you get CSP errors in the browser console, you can set this to an empty string to disable CSP. If you want a custom CSP that contains a nonce, include the
'nonce-{NONCE}' directive and it will be populated with a random value per request.Maximum size of forms and uploaded files in bytes. Defaults to 5 MiB (5,242,880 bytes).
Performance Settings
Maximum number of rendered rows that can be queued up in memory when a client is slow to receive them. This prevents a single request from using up all available memory.
When the client supports it, compress the HTTP response body. This can save bandwidth and speed up page loading on slow connections, but can also increase CPU usage and cause rendering delays on pages that take time to render (because streaming responses are buffered for longer than necessary).
Maximum depth of recursion allowed in the
run_sql function.Markdown Settings
Whether to allow raw HTML in markdown content. Only enable this if the markdown content is fully trusted (not user generated).
Whether to allow dangerous protocols (like
javascript:) in markdown links. Only enable this if the markdown content is fully trusted (not user generated).SSL/TLS Settings
Whether to use the system root CA certificates to validate SSL certificates when making HTTP requests with
sqlpage.fetch. If set to false, SQLPage will use its own set of root CA certificates. If the SSL_CERT_FILE or SSL_CERT_DIR environment variables are set, they will be used instead of the system root CA certificates.Debugging Configuration
To see detailed logs about what SQLPage is doing, set theRUST_LOG environment variable:
- Which configuration file is being loaded
- How configuration values are resolved
- Database connection details
- Request routing information
- And much more
Configuration Directory Structure
The configuration directory (default:./sqlpage/) can contain:
sqlpage.json(or.json5,.toml,.yaml) - Configuration filetemplates/- Custom component templatesmigrations/- Database migration scriptson_connect.sql- SQL to run when opening database connectionson_reset.sql- SQL to run when returning connections to the poolhttps/- HTTPS certificate cache (when using automatic HTTPS)
Related Topics
Database Connections
Configure database connections and connection pooling
HTTPS & SSL
Set up automatic HTTPS with Let’s Encrypt
Environment Variables
Complete reference of all environment variables
Custom Components
Create custom UI components