On vous demande de monter ERPNext pour l’équipe des opérations. Vous suivez le README, vous lancez bench init, vous tapez bench start dans un terminal, vous quittez la session SSH, et vingt minutes plus tard l’entreprise est verrouillée hors du module parce que le processus de développement que vous aviez lancé a été tué. Six mois plus tard, MariaDB écoute sur 0.0.0.0:3306, le bench a été installé sous le compte personnel du chef d’équipe et personne d’autre n’a les droits pour le relancer, supervisor n’a jamais été configuré donc un redémarrage du noyau coupe l’ERP, le certificat Let’s Encrypt est expiré depuis quatre jours, et toute l’équipe des finances passe par une page d’avertissement auto-signée.
Ce qui se passe
Un déploiement ERPNext réellement prêt pour la production demande plus que bench start. Le bench doit rouler sous un utilisateur système frappe dédié, en mode production sous supervisor pour que les processus workers (web, planificateur, files RQ pour short/default/long, socketio, redis-cache, redis-queue) reviennent après chaque redémarrage. MariaDB doit écouter sur 127.0.0.1 uniquement — les charges utiles d’auth dans tabUser sont sensibles ; jamais 0.0.0.0. nginx termine le TLS devant le bind gunicorn de Frappe avec un vrai certificat Let’s Encrypt sur le minuteur de renouvellement. Le bench doit être multi-sites dès le jour un (dns_multitenancy dans common_site_config.json) parce que le deuxième site est le moment où les équipes réalisent que l’installation n’est pas prête. Et LimitNOFILE=64000 compte : un ERPNext au repos garde une centaine de websockets persistants entre le navigateur et le socketio Frappe.
Comment vérifier
Après installation, les écouteurs doivent ressembler à ça :
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 sur 3306 doit être 127.0.0.1, jamais 0.0.0.0. État de supervisor (la commande la plus utile pour une installation Frappe) :
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
Joignabilité du site en TLS :
curl -I https://erp.example.com/
# HTTP/2 200
# strict-transport-security: max-age=31536000; includeSubDomains
Si une entrée supervisor est en FATAL ou STOPPED, le site va charger mais les travaux d’arrière-plan (courriels, exports planifiés, réconciliation auto de stock ERPNext) vont échouer silencieusement.
Le correctif
Enregistrez le script ci-dessous sous /root/setup-erpnext-ubuntu22.sh, puis exécutez-le. Il déroule mise à jour de base + UFW + durcissement SSH + unattended-upgrades, installe MariaDB 10.6 avec bind-address=127.0.0.1 plus Redis, configure Node 18 LTS via NVM sous un utilisateur frappe, lance bench init (version-15) + bench new-site + bench install-app erpnext + bench setup production (qui écrit les configurations supervisor + nginx), puis certbot pour le TLS, en sondant jusqu’à ce que :8000 et :443 répondent.
#!/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)."
Rendez-le exécutable et lancez-le :
chmod 700 /root/setup-erpnext-ubuntu22.sh
ERP_DOMAIN=erp.example.com ERP_EMAIL=ops@example.com /root/setup-erpnext-ubuntu22.sh
Le premier bench init plus le bench new-site plus la construction du schéma ERPNext est le poste qui prend le plus de temps — 25 à 40 minutes sur une VM 4 vCPU / 8 Go. Quand le script termine, connectez-vous comme Administrator avec le mot de passe affiché et complétez le gabarit de configuration (entreprise, pays, devise, plan comptable, année fiscale). La première exécution du gabarit verrouille le plan comptable — faites-le bien ou restaurez à partir d’un instantané. Le script n’active volontairement pas de sauvegardes au niveau hôte ; /home/frappe/frappe-bench/sites/ plus un mariadb-dump de chaque base de site sont les chemins persistants et l’hypothèse de base reste que la VM bénéficie d’un instantané/sauvegarde au niveau infonuagique.
Faites tourner l’ERPNext de production sur un environnement infogéré Stack Harbor avec cadence de patching, supervision supervisor et escalade d’astreinte intégrées : Surveillance et support →.