Created
November 2, 2025 15:33
-
-
Save ChatchaiJ/821e85f2b64948cd55f85cc071f30d9e to your computer and use it in GitHub Desktop.
Setup ERPNext on Ubuntu 20.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # rev: 2023-01-14 v1 | |
| #export SITE="${SITE:-frappe-bench.com}" | |
| export SITE="${SITE:-u2004.cjv6.net}" | |
| export USER="frappe" | |
| export FBSETUP="frappe-bench-setup.sh" | |
| ## Make sure that we have enough of free memory or swap space | |
| ## This should NOT need in production, for this testing purpose only | |
| dd if=/dev/zero of=/var/swap bs=1024k count=4096 | |
| chmod 600 /var/swap | |
| mkswap /var/swap | |
| swapon /var/swap | |
| export DEBIAN_FRONTEND=noninteractive | |
| useradd -m -c "ERPNext User Acount" -s /bin/bash $USER | |
| usermod -aG sudo $USER | |
| echo "${USER} ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/${USER} | |
| chmod 0600 /etc/sudoers.d/${USER} | |
| apt-get update | |
| apt-get -y dist-upgrade | |
| apt-get install -y sudo tmux vim tcpdump tshark curl fping htop iotop netcat apg \ | |
| git build-essential \ | |
| python3-dev python3-setuptools python3-pip python3.8-venv virtualenv \ | |
| mariadb-server libmysqlclient-dev redis-server \ | |
| xvfb libfontconfig wkhtmltopdf | |
| DB_PASSWORD=$(apg -n 1 -m 32) | |
| DB_ROOT_PASSWORD=$(apg -n 1 -m 32) | |
| ADMIN_PASSWORD=$(apg -n 1 -m 32) | |
| cat <<EOT > /home/$USER/passwords.txt | |
| DB_PASSWORD=${DB_PASSWORD} | |
| DB_ROOT_PASSWORD=${DB_ROOT_PASSWORD} | |
| ADMIN_PASSWORD=${ADMIN_PASSWORD} | |
| EOT | |
| # This is freppe bench setup script that will be run by $USER later | |
| cat <<EOT > /home/$USER/$FBSETUP | |
| #!/bin/sh | |
| cd \$HOME | |
| pwd | |
| . passwords.txt | |
| bench --version | |
| bench init frappe-bench --frappe-branch version-13 | |
| cd frappe-bench/ | |
| bench new-site ${SITE} --db-type mariadb \\ | |
| --db-password \${DB_PASSWORD} \\ | |
| --db-root-username root \\ | |
| --db-root-password \${DB_ROOT_PASSWORD} \\ | |
| --admin-password \${ADMIN_PASSWORD} | |
| bench get-app erpnext --branch version-13 | |
| bench --site ${SITE} install-app erpnext | |
| # bench start | |
| EOT | |
| chmod +x /home/$USER/$FBSETUP | |
| cat <<EOT > /home/$USER/.my.cnf | |
| [client] | |
| user = root | |
| password = ${DB_ROOT_PASSWORD} | |
| EOT | |
| chown -R ${USER}:${USER} /home/${USER} | |
| cat <<EOT > /etc/mysql/my.cnf | |
| [mysqld] | |
| character-set-client-handshake = FALSE | |
| character-set-server = utf8mb4 | |
| collation-server = utf8mb4_unicode_ci | |
| [mysql] | |
| default-character-set = utf8mb4 | |
| EOT | |
| printf "\nn\ny\ny\ny\ny\n" | mysql_secure_installation | |
| echo "grant all privileges on *.* to 'root'@'localhost' identified by '${DB_ROOT_PASSWORD}';" | mysql | |
| systemctl restart mariadb | |
| curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash - | |
| apt-get install -y nodejs | |
| npm install -g yarn | |
| curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg |\ | |
| gpg --dearmor |\ | |
| tee /usr/share/keyrings/yarnkey.gpg >/dev/null | |
| echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] https://dl.yarnpkg.com/debian stable main" |\ | |
| tee /etc/apt/sources.list.d/yarn.list | |
| apt-get update | |
| apt-get -y install yarn | |
| echo fs.inotify.max_user_watches=524288 | tee -a /etc/sysctl.conf | |
| sudo sysctl -p | |
| pip3 install frappe-bench | |
| sudo -u ${USER} bash -x /home/${USER}/${FBSETUP} | |
| # Create systemd frappe-bench.service | |
| cat <<EOT > /etc/systemd/system/frappe-bench.service | |
| [Unit] | |
| Description=ERPNext for $SITE | |
| [Service] | |
| Type=simple | |
| PIDFile=/run/frappe-bench.pid | |
| WorkingDirectory=/home/frappe/frappe-bench | |
| ExecStart=bench start | |
| User=${USER} | |
| Group=${USER} | |
| Restart=always | |
| RestartSec=10 | |
| [Install] | |
| WantedBy=multi-user.target | |
| EOT | |
| systemctl daemon-reload | |
| systemctl enable frappe-bench | |
| # systemctl start frappe-bench | |
| ### end of script ### |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment