You’ve been asked to stand up ERPNext for the operations team. You follow the README, run bench init, type bench start in a terminal, leave the SSH session, and twenty minutes later the company is locked out because the dev process you launched got reaped. Six months further on, MariaDB is listening on 0.0.0.0:3306, the bench was installed under the team lead’s personal user account so nobody else has rights to restart it, supervisor was never set up so a kernel reboot takes the ERP offline, the Let’s Encrypt cert is four days past expiry, and the entire finance team is filing through a self-signed warning page.
What’s happening
An ERPNext deployment that is actually production-ready needs more than bench start. The bench has to run under a dedicated frappe system user, in production mode under supervisor so the worker processes (web, scheduler, RQ queues for short/default/long, socketio, redis-cache, redis-queue) come back after every reboot. MariaDB has to listen on 127.0.0.1 only — the auth payloads in tabUser are sensitive; never 0.0.0.0. nginx terminates TLS in front of the Frappe gunicorn binding with a real Let’s Encrypt cert on the renewal timer. The bench has to be multi-site capable from day one (dns_multitenancy in common_site_config.json) because the second site is when teams realize the install isn’t ready. And LimitNOFILE=64000 matters: a quiet ERPNext idle is a hundred persistent websockets between the browser and socketio.
How to verify
After install, the listeners should look like this:
ss -lntp | grep -E ':(80|443|3306|9000|11000|12000|13000)\b'
# 127.0.0.1:3306 mariadbd
# 127.0.0.1:8000 gunicorn (Frappe web)
# 127.0.0.1:9000 socketio
# 127.0.0.1:11000 redis-cache
# 127.0.0.1:12000 redis-queue
# 127.0.0.1:13000 redis-socketio
# 0.0.0.0:80 nginx
# 0.0.0.0:443 nginx
MariaDB on 3306 must be 127.0.0.1, never 0.0.0.0. Supervisor health (the single most useful command for a Frappe install):
supervisorctl status | head -15
# frappe-bench-redis:frappe-bench-redis-cache RUNNING
# frappe-bench-redis:frappe-bench-redis-queue RUNNING
# frappe-bench-redis:frappe-bench-redis-socketio RUNNING
# frappe-bench-web:frappe-bench-frappe-web RUNNING
# frappe-bench-web:frappe-bench-node-socketio RUNNING
# frappe-bench-workers:frappe-bench-frappe-default RUNNING
# frappe-bench-workers:frappe-bench-frappe-long RUNNING
# frappe-bench-workers:frappe-bench-frappe-short RUNNING
# frappe-bench-workers:frappe-bench-frappe-scheduler RUNNING
Site reachability through TLS:
curl -I https://erp.example.com/
# HTTP/2 200
# strict-transport-security: max-age=31536000; includeSubDomains
If any supervisor entry is FATAL or STOPPED, the site will load but background jobs (emails, scheduled exports, ERPNext stock auto-reconciliation) will silently fail.
The fix
Save the script below as /root/setup-erpnext-ubuntu22.sh, then run it. It runs base update + UFW + SSH hardening + unattended-upgrades, installs MariaDB 10.6 with bind-address=127.0.0.1 plus Redis, sets up Node 18 LTS via NVM under a frappe user, runs bench init (version-15) + bench new-site + bench install-app erpnext + bench setup production (which writes supervisor + nginx configs), then certbot for TLS, polling until :8000 and :443 respond.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 ERPNext clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs MariaDB + Redis + Frappe bench + ERPNext + supervisor + nginx + Let's Encrypt
### MariaDB bound to 127.0.0.1 only
### No local backups; assumes VM-level backup
### Reboot remains manual
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
: "${ERP_DOMAIN:?Set ERP_DOMAIN=erp.example.com}"
: "${ERP_EMAIL:?Set ERP_EMAIL=ops@example.com for Let's Encrypt}"
FRAPPE_BRANCH="${FRAPPE_BRANCH:-version-15}"
ERPNEXT_BRANCH="${ERPNEXT_BRANCH:-version-15}"
MARIADB_ROOT_PASS="$(openssl rand -hex 24)"
ADMIN_PASS="$(openssl rand -hex 16)"
echo
echo "========================================"
echo "ERPNext Ubuntu 22.04 Setup"
echo "Domain: ${ERP_DOMAIN}"
echo "Branch: ${FRAPPE_BRANCH}"
echo "========================================"
echo
echo "==> Updating base OS"
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get -y upgrade
echo "==> Installing base packages"
apt-get -y install \
vim curl wget ca-certificates gnupg2 \
chrony fail2ban unattended-upgrades \
ufw lsof tcpdump dnsutils tar gzip git \
iproute2 net-tools openssl xvfb libfontconfig \
build-essential python3-dev python3-pip python3-venv \
software-properties-common redis-server \
libmariadb-dev libssl-dev libffi-dev libjpeg-dev \
libxml2-dev libxslt1-dev libtiff-dev libwebp-dev \
zlib1g-dev pkg-config
echo "==> Enabling time sync"
systemctl enable --now chrony
timedatectl set-ntp true
echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-erpnext.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL
modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system
echo "==> Setting file limits"
cat > /etc/security/limits.d/99-erpnext.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
frappe soft nofile 64000
frappe hard nofile 64000
LIMITS
echo "==> Configuring UFW"
ufw --force reset
ufw default deny incoming
ufw default allow outgoing
ufw allow 22/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw --force enable
echo "==> Hardening SSH while keeping root key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
local key="$1"
local value="$2"
if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
else
echo "${key} ${value}" >> /etc/ssh/sshd_config
fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option ChallengeResponseAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart ssh
echo "==> Configuring fail2ban"
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN
systemctl enable --now fail2ban
echo "==> Configuring unattended-upgrades"
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AUTOUPG'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
APT::Periodic::AutocleanInterval "7";
AUTOUPG
echo "==> Installing MariaDB 10.6"
apt-get -y install mariadb-server mariadb-client
echo "==> Locking MariaDB to 127.0.0.1 and tuning for Frappe"
MDB_CONF=/etc/mysql/mariadb.conf.d/99-frappe.cnf
cat > "$MDB_CONF" <<'MARIADB'
[mysqld]
bind-address = 127.0.0.1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
innodb-file-format = barracuda
innodb-large-prefix = 1
innodb-default-row-format = dynamic
max_allowed_packet = 256M
innodb_buffer_pool_size = 1G
[mysql]
default-character-set = utf8mb4
[client]
default-character-set = utf8mb4
MARIADB
systemctl restart mariadb
systemctl enable mariadb
echo "==> Securing MariaDB root"
mysql --defaults-file=/etc/mysql/debian.cnf -e "
ALTER USER 'root'@'localhost' IDENTIFIED BY '${MARIADB_ROOT_PASS}';
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost','127.0.0.1','::1');
DROP DATABASE IF EXISTS test;
FLUSH PRIVILEGES;
"
cat > /root/.my.cnf <<MYCNF
[client]
user=root
password=${MARIADB_ROOT_PASS}
MYCNF
chmod 600 /root/.my.cnf
echo "==> Enabling Redis"
systemctl enable --now redis-server
echo "==> Creating frappe system user"
if ! id -u frappe >/dev/null 2>&1; then
useradd --create-home --home-dir /home/frappe --shell /bin/bash frappe
fi
echo "frappe ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/frappe
chmod 440 /etc/sudoers.d/frappe
echo "==> Installing Node 18 LTS via NVM as frappe"
sudo -iu frappe bash <<'FRAPPE_NODE'
set -e
if [[ ! -d ~/.nvm ]]; then
curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
fi
export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"
nvm install 18
nvm use 18
nvm alias default 18
npm install -g yarn
FRAPPE_NODE
echo "==> Installing wkhtmltopdf for ERPNext PDFs"
WKHTML_DEB=wkhtmltox_0.12.6.1-3.jammy_amd64.deb
if ! command -v wkhtmltopdf >/dev/null 2>&1; then
cd /tmp
wget -q "https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6.1-3/${WKHTML_DEB}"
apt-get -y install "./${WKHTML_DEB}"
rm -f "${WKHTML_DEB}"
fi
echo "==> Installing frappe-bench via pipx for the frappe user"
sudo -iu frappe bash <<'FRAPPE_BENCH'
set -e
export NVM_DIR="$HOME/.nvm"
. "$NVM_DIR/nvm.sh"
pip3 install --user --upgrade frappe-bench
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
FRAPPE_BENCH
echo "==> bench init"
sudo -iu frappe bash <<FRAPPE_INIT
set -e
export PATH="\$HOME/.local/bin:\$PATH"
export NVM_DIR="\$HOME/.nvm"
. "\$NVM_DIR/nvm.sh"
cd ~
if [[ ! -d frappe-bench ]]; then
bench init --frappe-branch ${FRAPPE_BRANCH} --python python3 frappe-bench
fi
FRAPPE_INIT
echo "==> bench get-app erpnext + new-site ${ERP_DOMAIN}"
sudo -iu frappe bash <<FRAPPE_SITE
set -e
export PATH="\$HOME/.local/bin:\$PATH"
export NVM_DIR="\$HOME/.nvm"
. "\$NVM_DIR/nvm.sh"
cd ~/frappe-bench
if [[ ! -d apps/erpnext ]]; then
bench get-app --branch ${ERPNEXT_BRANCH} erpnext https://github.com/frappe/erpnext.git
fi
if [[ ! -d sites/${ERP_DOMAIN} ]]; then
bench new-site ${ERP_DOMAIN} \
--mariadb-root-password '${MARIADB_ROOT_PASS}' \
--admin-password '${ADMIN_PASS}' \
--install-app erpnext
fi
bench --site ${ERP_DOMAIN} enable-scheduler
bench use ${ERP_DOMAIN}
bench set-config -g dns_multitenant true
bench set-config -g maintenance_mode 0
FRAPPE_SITE
echo "==> Switching bench to production (writes supervisor + nginx configs)"
sudo bench --site ${ERP_DOMAIN} setup nginx --yes >/dev/null || true
cd /home/frappe/frappe-bench
sudo bench setup production frappe --yes
echo "==> Waiting for Frappe gunicorn on 127.0.0.1:8000"
for i in {1..120}; do
if ss -lntp | grep -q '127.0.0.1:8000'; then
break
fi
sleep 2
done
if ! ss -lntp | grep -q '127.0.0.1:8000'; then
echo "Frappe failed to bind on 127.0.0.1:8000"
supervisorctl status || true
tail -200 /home/frappe/frappe-bench/logs/web.error.log 2>/dev/null || true
exit 1
fi
echo "==> Installing certbot and obtaining cert"
apt-get -y install certbot python3-certbot-nginx
certbot --nginx --non-interactive --agree-tos \
-m "${ERP_EMAIL}" -d "${ERP_DOMAIN}" --redirect
systemctl enable --now certbot.timer
echo "==> Waiting for HTTPS listener"
for i in {1..30}; do
if ss -lntp | grep -q ':443'; then
break
fi
sleep 1
done
echo "==> Final package update"
apt-get -y upgrade
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Kernel:"
uname -r
echo
echo "Services:"
systemctl is-active mariadb redis-server nginx supervisor fail2ban chrony || true
echo
echo "Supervisor:"
supervisorctl status 2>/dev/null || true
echo
echo "Listeners:"
ss -lntp | grep -E ':(80|443|3306|8000|9000|11000|12000|13000)\b' || true
echo
echo "Web UI:"
echo "https://${ERP_DOMAIN}/"
echo
echo "Credentials (record to your password manager NOW):"
echo " Site: ${ERP_DOMAIN}"
echo " Administrator: Administrator"
echo " Admin password: ${ADMIN_PASS}"
echo " MariaDB root: ${MARIADB_ROOT_PASS}"
echo
echo "Adding a second site (multi-tenant):"
echo " sudo -iu frappe bash -lc 'cd ~/frappe-bench && \\"
echo " bench new-site site2.example.com \\"
echo " --mariadb-root-password ${MARIADB_ROOT_PASS} \\"
echo " --admin-password \$(openssl rand -hex 16) \\"
echo " --install-app erpnext'"
echo " sudo bench setup nginx --yes && sudo systemctl reload nginx"
echo
echo "Final step:"
echo "Open the URL, log in as Administrator with the printed password, then run the ERPNext setup wizard (Company, Country, Currency, Chart of Accounts, fiscal year)."
Make it executable and run it:
chmod 700 /root/setup-erpnext-ubuntu22.sh
ERP_DOMAIN=erp.example.com ERP_EMAIL=ops@example.com /root/setup-erpnext-ubuntu22.sh
First bench init plus bench new-site plus the ERPNext schema build is the long pole — 25 to 40 minutes on a 4 vCPU / 8 GB VM. When the script finishes, log in as Administrator with the printed password and complete the setup wizard (Company, Country, Currency, Chart of Accounts, fiscal year). The first wizard run locks in the chart of accounts — get it right or restore from snapshot. The script does not configure host-level backups; /home/frappe/frappe-bench/sites/ plus a mariadb-dump of each site DB are the stateful paths and the assumption is the VM has snapshot/backup at the cloud layer.
Run the production ERPNext on a Stack Harbor-managed environment with patching cadence, supervisor monitoring, and on-call escalation built in: Monitoring & support →.