4 Installation Guide
STAPLE is available as a hosted service at https://app.staple.science, which is the simplest way to get started.
This guide is for individuals or organizations who would like to host their own instance of STAPLE. Running your own version gives you full control over your data, configuration, and integration with your existing infrastructure.
4.1 Assumptions
This guide assumes you meet the following prerequisites:
- You are working on a Linux server. We use Ubuntu 20.04 in this guide, but the steps should be consistent for most Linux distributions.
- You have shell/terminal access to the server.
- You have worked with the command line before.
- You have
sudo
privileges to install packages and manage services. - You understand what hidden files are (and how to view them).
- You have a basic understanding of SQL and databases (familiarity with PostgreSQL is not required).
- You know what Apache and/or Nginx servers are and how to edit their configuration files.
- You can imagine yourself using git (even if you’re new to it).
4.2 Local Development or Hosting
You can also run STAPLE locally on your own computer, with a few limitations.
- If you are using a Linux system, you can follow the same instructions described in this guide from Blitz/JS Installation through Starting the App – Production.
- On Windows, you can run STAPLE as well, but you’ll need to use a shell environment (such as PowerShell, Git Bash, or WSL2) to follow the same command-line instructions.
- On macOS, the setup is nearly identical to Linux, and you can use the standard Terminal application to run the commands.
When running locally, you will be the only user able to enter data. The application is not hosted on the web, so others will not be able to connect.
Despite this limitation, you will still have access to the full functionality of project management and metadata entry/output. This makes local installation useful for:
- Testing the system before deploying to a server
- Exploring functionality on your own
- Managing personal projects without a shared server
4.3 Installation Steps
4.3.1 Web Server Installation
STAPLE requires a web server to handle requests. You can choose between Apache or Nginx:
Apache – Installation Instructions
Nginx – Installation Instructions
⚠️ Important: Only install one. Apache and Nginx don’t play nicely together if they’re both running on the same server.
We recommend using Nginx, and our production server is configured with Nginx. This step is only required for people who want to host the software online. You do not need it for local development or use.
4.3.2 Blitz/JS Installation
STAPLE is built with Blitz.js, which runs on Node.js. To install the required tools:
- Install Node.js and npm
- Follow the official installation instructions: Node.js Downloads
- Required versions:
- Node.js: v18+
- npm: v9+
- Verify installation with:
node -v
npm -v
- (Optional) Yarn: You may use Yarn if you prefer, but this guide assumes npm.
- Install Blitz.js
- Run:
npm install -g blitz
- Verify installation (version v2+ required):
blitz -v
ℹ️ Note: Depending on your server setup, you may need to prepend commands with
sudo
.
4.3.3 Clone the Repository
Next, you’ll need to copy the STAPLE source code onto your server.
- Install Git (if not already installed):
sudo apt-get update
sudo apt-get install git
- Navigate to your web directory (commonly
/var/www/html/
or/var/www/
): - Note: you can use any folder on your computer if you are not hosting the software online or want to do local development.
cd /var/www/html/
- Clone the repository:
- Follow the GitHub guide on cloning repositories.
- Or simply run:
- Follow the GitHub guide on cloning repositories.
git clone https://github.com/STAPLE-verse/STAPLE.git
- This will create a new folder named STAPLE containing all the files you need.
- Move into the project folder:
cd STAPLE
4.3.4 Database Installation
STAPLE requires a PostgreSQL database.
- Install PostgreSQL
- Ensure that you have a local PostgreSQL service running.
- Follow this guide for installation: Postgres Setup Instructions.
- During installation:
- Write down the superuser credentials (important on non-Linux systems).
- Other databases may work, but you would need to modify the STAPLE codebase to support them.
- Create Databases
- Open a terminal and run:
# Switch into PostgreSQL as the postgres superuser
sudo -u postgres psql
# Create databases for STAPLE
CREATE DATABASE staple;
CREATE DATABASE staple_test;
- Create a User
- It’s best not to use the default postgres user for STAPLE. Instead, create a new user:
- Replace username and password with your desired values (keep the quotes).
CREATE USER username WITH PASSWORD 'password';
ALTER ROLE username CREATEDB;
- Check Databases
- Inside the PostgreSQL prompt, you can verify:
\l -- lists databases
\c staple -- connect to the STAPLE database
\dn -- lists schemas
- You should see something like the following using those commands:
postgres=# \c staple
You are now connected to database "staple" as user "postgres".
staple=#
staple=# \dn
List of schemas
Name | Owner
--------+--------
public | staple
(1 row)
staple=#
postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-------------+----------+----------+-------------+-------------+---------------------------
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
staple | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres +
| | | | | staple=CTc/postgres +
| | | | | staple_admin=CTc/postgres
staple_test | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
- Grant Privileges
- Finally, grant permissions for your new user to manage the staple schema:
GRANT ALL ON SCHEMA public TO username;
- Exit PostgreSQL using
\q
4.3.5 Connect Database to STAPLE App
- Now we’ll connect the PostgreSQL database you created to the STAPLE application.
- Navigate to your STAPLE project folder
cd /var/www/html/STAPLE
ls -al
- You should see a file named
.env
along with other project files. - You may need to enable hidden files to see .env files.
- Example:
erin@staple:/var/www/html/STAPLE$ ls -al
total 764
drwxr-xr-x 13 root root 4096 Oct 24 06:17 .
drwxr-xr-x 6 root root 4096 Oct 24 05:02 ..
drwxr-xr-x 3 root root 4096 Oct 24 04:27 db
-rw-r--r-- 1 root root 175 Oct 24 04:27 .editorconfig
-rw-r--r-- 1 root root 494 Oct 24 06:17 .env
- Create a local environment file
- Copy the .env file and rename it to .env.local:
cp .env .env.local
- Open it for editing:
nano .env.local
- Add required environment variables
- At minimum, your .env.local file needs these:
# This env file should NOT be checked into source control
# Use this file for local overrides
# Replace username:password with your Postgres user and password
DATABASE_URL=postgresql://username:password@localhost:5432/staple
# Generate a random session key
SESSION_SECRET_KEY=your_generated_session_key
# Where the app will live
APP_ORIGIN="http://localhost:3000/"
- To generate a SESSION_SECRET_KEY:
- Copy the output and paste it in place of your_generated_session_key.
openssl rand -hex 16
- Set up a test environment
- Copy .env.test to .env.test.local:
cp .env.test .env.test.local
- Edit it to point to your test database:
DATABASE_URL=postgresql://username:password@localhost:5432/staple_test
4.3.6 Configure Email
STAPLE requires an email provider to send system emails (e.g., password resets, project invitations). You can use other options here, but we’ve configured three of them in our current code.
4.3.6.1 Secret Keys
You must configure at least one of the following options:
Gmail (App Passwords)
- Create a Gmail App Password: Google Guide
- Add to .env.local:
EMAIL_PASS="your_app_password"
- Amazon SES
- Set up Amazon Simple Email Service (SES): Amazon SES Docs
- Add to .env.local:
ACCESS_KEY="amazonACCESS"
SECRET_ACCESS_KEY="amazonSECRET"
- Resend
- Get an API key from Resend.
- Add to .env.local:
RESEND_API_KEY="resendAPI"
4.3.6.2 Edit the Mailer Configuration
In addition to adding one of the above environment variables, you’ll need to edit the mailer configuration file so STAPLE knows which provider to use.
- Open the mailer configuration file:
nano integrations/mailer.js
Delete non-used mailers: there are three chunks of code in this file - one for each type of email. You should delete the types you are not using to ensure the app runs. You can also insert your own mail options in this section.
Edit the forgot password mailer:
nano mailers/forgotPasswordMailer.ts
- Change these sections to the mailer you want to use:
// import { Mailer } from "integrations/mailer"
import { createForgotPasswordMsg } from "integrations/emails"
// import { Amazon } from "integrations/mailer"
import { ResendMsg } from "integrations/mailer"
//send the email
await ResendMsg(createForgotPasswordMsg(to, resetUrl))
// await Amazon(createForgotPasswordMsg(to, resetUrl)) # or amazon
// await Mailer(createForgotPasswordMsg(to, resetUrl)) # or gmail
- Edit the emails.tsx file if you want to customize the emails that are sent with your own email address and logos.
nano integrations/emails.tsx
4.3.7 Install STAPLE Requirements
- Make sure you are in the STAPLE main folder before running these commands.
- Use the following (not the
#
line, these are notes) to install packages, tailwind, and daisyui.
# Install all project dependencies
npm install
# Install Tailwind CSS
blitz install tailwind
# Install DaisyUI
npm i -D daisyui@latest
- Set up the database schema:
# Generate Prisma client
blitz prisma generate
# Run migrations to create database structure
blitz prisma migrate dev
4.3.8 Starting the App - Local Testing
- Open a terminal window and navigate to the STAPLE folder you cloned:
cd /var/www/html/STAPLE
- Start the development server:
blitz dev
- Once the server is running, open your browser and go to: http://localhost:3000 (or whatever address is shown in your terminal output).
4.3.9 Starting the App - Production
- Open a terminal window and navigate to the STAPLE folder you cloned:
cd /var/www/html/STAPLE
- Build the application:
blitz build
⚠️ Note: If the build process produces errors, you’ll need to fix these before you can continue. Common issues include missing dependencies or mismatched Prisma client versions. Check the terminal output for details. We do not update our dev or main branches without fixing these, but it may be that your edits for your server caused hiccups.
- Once the build completes successfully, start the app in production mode:
blitz start
4.3.10 Keeping the App Going
When running in production, you’ll want STAPLE to automatically restart after crashes or reboots. The recommended way to do this on Linux is by creating a systemd service.
- Create a service file
- Navigate to the systemd directory and create a new file (we’ll call it
blitz.service
):
- Navigate to the systemd directory and create a new file (we’ll call it
cd /etc/systemd/system/
sudo nano blitz.service
- Example service file:
- Replace
WorkingDirectory
with the path to your STAPLE installation. - You can also set specific users or production modes for security.
- Replace
[Unit]
Description=Starts the Blitz service.
After=network.target
[Service]
Type=simple
WorkingDirectory=/var/www/html/STAPLE
ExecStart=/usr/local/bin/blitz start
Restart=always
[Install]
WantedBy=default.target
- Enable and control the service
- Once your file is saved, you can manage it with:
# Start the service
sudo systemctl start blitz
# Check status (press "q" to quit)
sudo systemctl status blitz
# Restart the service
sudo systemctl restart blitz
# Stop the service
sudo systemctl stop blitz
# Enable service on boot
sudo systemctl enable blitz
# Disable service
sudo systemctl disable blitz
# Reset if failed
sudo systemctl reset-failed blitz
- Tutorial reference
- If you’re new to systemd services, see this helpful guide: Service Installation Instructions
4.3.11 Setting Up the Proxy (Nginx)
Now that STAPLE is running as a background service, you’ll want to expose it through your web domain with Nginx.
- Navigate to your Nginx configuration folder
cd /etc/nginx/sites-enabled
- Create a new site config file
- Name it after your site, e.g.:
sudo nano app.staple.science
- Add the server configuration
- Replace app.staple.science with your domain and update the log path if needed:
server {
listen 80;
server_name app.staple.science;
error_log /var/www/html/YOURFOLDER/logs/web-server.log;
location / {
proxy_pass http://localhost:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
⚠️ Important: Make sure the server_name matches your domain name, and the proxy_pass points to the port where Blitz is running (localhost:3000 by default).
- Test your config:
sudo nginx -t
- If you see syntax is ok and test is successful, reload Nginx:
sudo systemctl reload nginx
4.3.12 Enable HTTPS
- Use Let’s Encrypt to add SSL by changing the location of your app in the following:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d app.staple.science
- This will automatically configure HTTPS and renew your certificate.
- See Installation Instructions.
4.4 Common Issues & Fixes
4.4.1 Prisma / Database Errors
- Error: Error: P1000: Authentication failed against database server
- Fix: Double-check your DATABASE_URL in .env.local. Make sure the username/password match the Postgres user you created.
- Error: Error: P3014: The underlying table does not exist
- Fix: Run migrations again:
blitz prisma migrate dev
- Permission denied when running migrations
- Fix: Ensure the Postgres user has privileges:
ALTER ROLE your_username CREATEDB;
GRANT ALL ON SCHEMA public TO your_username;
4.4.2 Build Errors
- Error: blitz build fails with missing dependencies
- Fix: Run npm install again to ensure all dependencies are installed.
- Prisma client mismatch
- Fix: Run:
blitz prisma generate
4.4.3 Email Issues
- No emails are being sent
- Fix: Check that you kept only one mailer provider in mailer.ts.
- Ensure the correct environment variables (EMAIL_PASS, ACCESS_KEY, SECRET_ACCESS_KEY, or RESEND_API_KEY) are set in .env.local.
- For Amazon SES, make sure your MAIL_FROM address is verified.
- For Gmail, use an App Password, not your regular password.
4.4.4 Nginx / Proxy Issues
- Nginx won’t start
- Fix: Run
sudo nginx -t
to test configuration. Correct any syntax errors before restarting.
- Fix: Run
- Site loads, but app doesn’t respond
- Fix: Make sure blitz is running (check with
sudo systemctl status blitz
). - Check that the
proxy_pass
in your Nginx config matches the Blitz port (localhost:3000 by default).
- Fix: Make sure blitz is running (check with
- SSL certificate not working
- Fix: Ensure port 80/443 are open on your firewall.
- Re-run certbot:
sudo certbot --nginx -d yourdomain.com
4.4.5 Service Issues
- Blitz doesn’t restart after reboot
- Fix: Make sure the service is enabled:
sudo systemctl enable blitz
- Service crashes with permission errors
- Fix: Ensure the User in
blitz.service
has read/write access to the STAPLE folder.
- Fix: Ensure the User in
4.4.6 General Tips
- After editing .env.local, .env.test.local, or blitz.service, restart the app:
sudo systemctl restart blitz
- Check logs:
journalctl -u blitz -f
Get help: contact staple.helpdesk at gmail.com.