Skip to content

Instantly share code, notes, and snippets.

@anilprasad
Forked from drthilina/1_erpnext13_public.sh
Created November 8, 2022 07:52
Show Gist options
  • Save anilprasad/690c38e3bc0c8d3ba1a3085fb020bdb0 to your computer and use it in GitHub Desktop.
Save anilprasad/690c38e3bc0c8d3ba1a3085fb020bdb0 to your computer and use it in GitHub Desktop.
Install ERPNext V13 on Ubuntu 20.04 LTS || Production
Install ERPNext V13, FRAPPE-BENCH 13 on Ubuntu 20.04 and configure for production Environment
# Install GIT
$ apt install -y git
# Ubuntu update and upgrade packages
$ apt update -y && apt upgrade -y
# Install Python 3 and dependencies
$ apt install -y python3-dev python3-setuptools python3-pip virtualenv
# Install MariaDB
$ apt install -y mariadb-server mariadb-client
# Secure MariaDB Installation
$ mysql_secure_installation
Setup <your_password> and proceed forward with "y + Enter"
# Add Configuration parameters to MariaDB relevant for Frappe framework
$ nano /etc/mysql/my.cnf
# This will open mariadb main config file, add the following to end
[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
[mysql]
default-character-set = utf8mb4
# Save and exit
# Restart MariaDB service
$ systemctl restart mariadb
# Login to MYSQL to create User and Database for FRAPPE framework to access
$ mysql -u root -p
>>> CREATE USER 'erpnext'@'localhost' IDENTIFIED BY 'erpnext';
>>> GRANT ALL PRIVILEGES ON *.* TO 'erpnext'@'localhost' WITH GRANT OPTION;
>>> CREATE DATABASE erpnext;
>>> USE erpnext;
>>> FLUSH PRIVILEGES;
>>> EXIT;
$ service mysql restart
# Install Redis Server
$ apt install -y redis-server
# Install curl and install Node.js
$ apt install curl -y
$ curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
$ apt install nodejs -y
# Install NPM
$ apt update -y && apt install -y npm
# Install YARN
$ npm install -g yarn
# Install WKHTMLTOPDF 0.12.6 (0.12.5 version will not render Letterhead headers and footers)
$ apt install -y xvfb libfontconfig
$ wget https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
$ sudo apt install ./wkhtmltox_0.12.6-1.focal_amd64.deb
# Check WKHTMLTOPDF versions
$ wkhtmltopdf --version
wkhtmltopdf 0.12.6 (with patched qt)
# Add non-root user for the FRAPPE framework
$ adduser frappe
<frappe_password>
$ usermod -aG sudo frappe
$ apt update -y && apt upgrade -y
# Log in as the non-root user
$ su frappe
# navigate in to the "frappe" user home directory
$ cd
# Install frappe-bench via pip
$ sudo -H pip3 install frappe-bench
# check bench version
$ bench --version
# Take ownership of home directory
$ sudo chown frappe -R /home/frappe
# Install cron for managing scheduling
$ sudo apt install cron -y
# Test Database connection
$ mysql -u erpnext -p
# Initialize a frappe-bench working Directory
$ bench init /home/frappe/frappe-bench --frappe-path https://github.com/frappe/frappe --frappe-branch version-13
# If you run in to a problem "No Directory 'install', or "yarn install", do the following and repeat above step
$ sudo apt remove cmdtest
$ sudo apt remove yarn
$ sudo npm install -g yarn
# Navigate in to frappe-bench directory, except for "bench init" all other commands must happen from this directory
$ cd frappe-bench
# Check bench instance
$ bench start
# Goto <ip4>:8000 and will show a not found error, but this means frappe-bench initialization was successful
# press ctrl + C to stop and go back to prompt
# Create a new site
$ bench new-site v13.cubicoan.lk --admin-password '<admin_password>' --mariadb-root-username erpnext --mariadb-root-password 'erpnext'
# Let bench know the site can be used
$ bench use v13.cubicoan.lk
# Test bench instance again
$ bench start
# Goto <ip4>:8000 and it should show a wizard, do not proceed forward
# press ctrl + C to stop and go back to prompt
# Get bench app from GITHUB
$ bench get-app erpnext https://github.com/frappe/erpnext --branch version-13
# Install ERPNext v13 in to the site
$ bench --site v13.cubicoan.lk install-app erpnext
# Test bench instance again
$ bench start
# Goto <ip4>:8000 and it should show a wizard, you may proceed forward to complete the wizard
# Once it is complete, press ctrl + C to stop and go back to prompt
# ====================== Setting up for production ===========================
# Automated setup for ERPNext for production
$ sudo bench setup production frappe --yes
# If you are lucky everyting will go smooth, for me redis server configuration fails
# We need to manually add the redis configuration.
# make sure you are in frappe home (~) directory
$ cd frappe-bench/config
# Run the script using redis-server command
$ redis-server redis_cache.conf
# Everything shoud be okay, press "ctrl + c" to cancel and go back to prompt
# Try production setup again, this time it should go through
$ sudo bench setup production frappe --yes
# check output for
# supervisorctl reread
# supervisorctl update
# nginx -t
# several outputs for frappe-bench... should appear
# Check if other produciton environment tools are running
$ systemctl list-unit-files | grep 'fail2ban\|nginx\|supervisor'
Output
fail2ban.service enabled
nginx.service enabled
supervisor.service enabled
# Install SNAP for Centbot installation, this is for SSL
$ sudo apt install snapd -y
# For good measures lets reboot
$ sudo reboot now
# Log in as non-root user
$ login as frappe
# Install SNAP core etc.
$ sudo snap install core; sudo snap refresh core
# Install certbot
$ sudo snap install --classic certbot
# Create symbolic link for Certbot (explained in lets-encrypt instructions)
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot
# Navigate to frappe-bench folder
$ cd frappe-bench
# Turn on Multitenant in frappe-bench
$ bench config dns_multitenant on
# Finally get certification (You must have a domain name, else will not work)
$ sudo bench setup lets-encrypt v13.cubicoan.lk
# The following commands will help WKHTMLTOPDF to correctly render PDF outputs
#
# Navigate to ~/frappe-bench/sites/<your_site>
$ cd ~/frappe-bench/sites/v13.cubicoan.lk
# Adding the host name to the site_config.json (manually)
$ nano site_config.json
# add "host_name": "https://<your_site>", below "db_type"
"host_name": "https://v13.cubicoan.lk"
# Save and exit
# cd to frappe-bench
# below will add "hostname" to the site_config.json
$ bench --site v13.cubicoan.lk set-config hostname “https://v13.cubicoan.lk”
$ bench setup nginx
# For good measure
$ sudo reboot now
whats remaining is securing the SSH connection and setting up UFW.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment