How to install Frappe Framework & Bench on Ubuntu 20.04 LTS (Focal Fossa)

This article will help you install Frappe Framework on Ubuntu 20.04 LTS (Focal Fossa). This guide has been tested on Ubuntu 20.04 LTS (Focal Fossa)

Update your system packages and dependencies

Run the following commands to get information on the newest versions of packages and their dependencies and update them

sudo apt-get update -y && sudo apt-get upgrade -y

Install some required and necessary software prerequisites

Some of the softwares prerequisites added on the install are for ERPNEXT. I’m assuming you will add it later after exploring Frappe Framework.

sudo apt install git curl libffi-dev python3-minimal build-essential python3-distutils python3-setuptools python3-pip python3-testresources libssl-dev wkhtmltopdf redis -y 

// Output - Full install no errors 

Import MariaDB 10.5 gpg key

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

// Output

Executing: /tmp/apt-key-gpghome.zs3Z1AeEVj/gpg.1.sh --fetch-keys https://mariadb.org/mariadb_release_signing_key.asc
gpg: requesting key from 'https://mariadb.org/mariadb_release_signing_key.asc'
gpg: key F1656F24C74CD1D8: public key "MariaDB Signing Key <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1

Add MariaDB 10.5 Apt repository

After importing the GPG key, add the APT repository by running the following command:

sudo add-apt-repository 'deb [arch=amd64] http://mariadb.mirror.globo.tech/repo/10.5/ubuntu focal main'

// Output

Hit:1 http://europe-west2.gce.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://europe-west2.gce.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://europe-west2.gce.archive.ubuntu.com/ubuntu focal-backports InRelease
Get:4 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:5 http://mariadb.mirror.globo.tech/repo/10.5/ubuntu focal InRelease [6264 B]
Get:6 http://mariadb.mirror.globo.tech/repo/10.5/ubuntu focal/main amd64 Packages [17.4 kB]
Fetched 137 kB in 1s (222 kB/s)
Reading package lists... Done

Install MariaDB 10.5 Server & MariaDB client

// Run update first to refresh repo's

sudo apt update -y
sudo apt install mariadb-server mariadb-client -y

Secure your MariaDB Server

After successful install, we will use the mysql_secure_installation command that helps us to improve the security of MariaDB installation. If you were not prompted for a password during MariaDB installation then you password is blank, just press enter for none:

larry@server-2:~$ sudo mysql_secure_installation


// Output


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] Y
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

MariaDB will reload tables after the hardening script. Reloading the privilege tables will ensure that all changes will take effect immediately

Edit the MariaDB config file & save

sudo nano /etc/mysql/my.cnf

# Add below items at the end of the my.cnf file

[mysqld]
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

[mysql]
default-character-set = utf8mb4

Restart MariaDB server and check status of MariaDB

sudo systemctl restart mysql
sudo systemctl status mysql

// Output

mariadb.service - MariaDB 10.5.10 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Thu 2021-06-10 21:51:28 UTC; 10s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 21219 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 21229 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 21235 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl>
    Process: 21314 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 21316 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 21299 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 15 (limit: 4713)
     Memory: 59.4M
     CGroup: /system.slice/mariadb.service
             └─21299 /usr/sbin/mariadbd

Jun 10 21:51:28 server-2 mariadbd[21299]: 2021-06-10 21:51:28 0 [Note] Reading of all Master_info entries succeeded
Jun 10 21:51:28 server-2 mariadbd[21299]: 2021-06-10 21:51:28 0 [Note] Added new Master_info '' to hash table
Jun 10 21:51:28 server-2 mariadbd[21299]: 2021-06-10 21:51:28 0 [Note] /usr/sbin/mariadbd: ready for connections.
Jun 10 21:51:28 server-2 mariadbd[21299]: Version: '10.5.10-MariaDB-1:10.5.10+maria~focal'  socket: '/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distrib>
Jun 10 21:51:28 server-2 systemd[1]: Started MariaDB 10.5.10 database server.

Test login to MariaDB shell using mysql command

Use your MariaDB password you set during hardening script above

larry@server-2:~$ sudo mysql -u root -p


// output


Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 30
Server version: 10.5.10-MariaDB-1:10.5.10+maria~focal mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Check and verify the of MariaDB version:

MariaDB [(none)]> SELECT VERSION();
+---------------------------------------+
| VERSION()                             |
+---------------------------------------+
| 10.5.10-MariaDB-1:10.5.10+maria~focal |
+---------------------------------------+
1 row in set (0.000 sec)

Install Node Version Manager (NVM)

We recommend installing node via NVM. The nvm command will help you to manage different versions of Node.js on a single environment. NOTE: Please read the output after install carefully

To install nvm, you should run the install script. To do that, you may either download and run the script manually, or use the following cURL command:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

// Output - The End of my Output after my install 

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

// I edited my ~/.bashrc , Add above output because it was not added automatically

// Run following command to reload .bashrc file after editing

source ~/.bashrc

After nvm is installed, you may have to close your terminal and open another one.

Test if NVM installed correctly

command -v nvm

// Output

nvm

Install node.js version 14 using NVM

Install node.js v14 and don’t use sudo

larry@server-2:~$ nvm install 14

// Output

Downloading and installing node v14.17.0...Downloading https://nodejs.org/dist/v14.17.0/node-v14.17.0-linux-x64.tar.xz...
############################################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v14.17.0 (npm v6.14.13)
Creating default alias: default -> 14 (-> v14.17.0)

Check `node.js` version if necessary

larry@server-2:~$ node -v
v14.17.0

Install yarn via npm

npm install -g yarn

// Output

> [email protected] preinstall /home/larry/.nvm/versions/node/v14.17.0/lib/node_modules/yarn
> :; (node ./preinstall.js > /dev/null 2>&1 || true)

/home/larry/.nvm/versions/node/v14.17.0/bin/yarn -> /home/larry/.nvm/versions/node/v14.17.0/lib/node_modules/yarn/bin/yarn.js
/home/larry/.nvm/versions/node/v14.17.0/bin/yarnpkg -> /home/larry/.nvm/versions/node/v14.17.0/lib/node_modules/yarn/bin/yarn.js
+ [email protected]
added 1 package in 0.635s

Install Bench CLI via pip3

Bench is a CLI tool to manage Frappe Deployments. It provides an easy interface to help you setup and manage multiple sites and apps based on Frappe Framework

sudo pip3 install frappe-bench

In case you having difficulties with install frappe-bench, try this article https://discuss.erpnext.com/t/tutorial-installing-and-upgrading-bench-cli-ver-5-3/73463

Confirm your bench installation by checking version

larry@server-2:~$ bench --version

// Output

WARN: Command not being executed in bench directory
5.4.1

Create your first bench folder using bench init

The init command will create a bench directory with frappe framework installed. It will be setup for periodic backups and auto updates once a day. Make sure you are in your home dir:

cd ~
bench init frappe-bench

// Output

$ /usr/local/bin/virtualenv -q env -p python3

Getting frappe
$ git clone https://github.com/frappe/frappe.git  --depth 1 --origin upstream
Cloning into 'frappe'...
remote: Enumerating objects: 2920, done.
remote: Counting objects: 100% (2920/2920), done.
remote: Compressing objects: 100% (2613/2613), done.
remote: Total 2920 (delta 430), reused 1710 (delta 228), pack-reused 0
Receiving objects: 100% (2920/2920), 16.01 MiB | 10.24 MiB/s, done.
Resolving deltas: 100% (430/430), done.

Installing frappe
$ frappe-bench/env/bin/python -m pip install -q -U -e frappe-bench/apps/frappe
$ yarn install
yarn install v1.22.10
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[###################################################################

// Output truncated

 DONE  Total Build Time: 557.44ms

clean: postcss.plugin was deprecated. Migration guide:
https://evilmartians.com/chronicles/postcss-8-plugin-migration
 WARN  Cannot connect to redis_cache to update assets_json
Done in 6.61s.
SUCCESS: Bench frappe-bench initialized

After the frappe-bench folder is created, change your directory to frappe-bench and run bench start. Bench will need to keep running in that terminal

cd ~/frappe-bench 
bench start

// Output should look like this 

22:34:14 socketio.1       | listening on *: 9000
22:34:15 watch.1          |
22:34:15 web.1            |  * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
22:34:15 web.1            |  * Restarting with stat
22:34:15 watch.1          | yarn run v1.22.10
22:34:16 watch.1          | $ node esbuild --watch
22:34:16 web.1            |  * Debugger is active!
22:34:16 web.1            |  * Debugger PIN: 144-141-302
22:34:17 watch.1          | clean: postcss.plugin was deprecated. Migration guide:
22:34:17 watch.1          | https://evilmartians.com/chronicles/postcss-8-plugin-migration
22:34:25 watch.1          | clean: postcss.plugin was deprecated. Migration guide:
22:34:25 watch.1          | https://evilmartians.com/chronicles/postcss-8-plugin-migration
22:34:27 watch.1          | clean: postcss.plugin was deprecated. Migration guide:
22:34:27 watch.1          | https://evilmartians.com/chronicles/postcss-8-plugin-migration
22:34:28 watch.1          | Watching for changes...

Open a 2nd terminal window and go into the frappe-bench directory. Congratulations, you have successfully installed bench on to your system.

Creating a sample app and install

This tutorial is based on the Frappe Framework website tutorial. Please visit https://frappeframework.com/docs/user/en/tutorial to complete full tutorial.

Creating an app

To create our Library Management app, run the following command from the frappe-bench directory. You will be prompted with details of your app, fill them up and an app named library_management will be created in the apps folder.

bench new-app library_management

// Output

larry@server-2:~/frappe-bench$ bench new-app library_management
App Title (default: Library Management): Library Management
App Description: Library Management Application
App Publisher: Larry D
App Email: [email protected]
App Icon (default 'octicon octicon-file-directory'):
App Color (default 'grey'):
App License (default 'MIT'):
'library_management' created at /home/larry/frappe-bench/apps/library_management

Installing library_management
$ ./env/bin/python -m pip install -q -U -e ./apps/library_management
$ bench build --app library_management
✔ Application Assets Linked

yarn run v1.22.10
$ node esbuild --production --apps library_management --run-build-command
File                                                        Size

 DONE  Total Build Time: 1.098s

clean: postcss.plugin was deprecated. Migration guide:
https://evilmartians.com/chronicles/postcss-8-plugin-migration
Done in 2.15s.

Create a new site

A site comes with a database and apps can be installed on it. To create a new site, run the following command from the frappe-bench directory:

larry@server-2:~/frappe-bench$ bench new-site library.test


// Output


MySQL root password:

Installing frappe...
Updating DocTypes for frappe        : [========================================] 100%
Updating country info               : [========================================] 100%
Set Administrator password:
Re-enter Administrator password:
*** Scheduler is disabled ***
Current Site set to library.test

This command will create a new database, so you need to enter your MySQL root password. It will also ask to set the password for the Administrator user, just set a password that you won’t forget. This will be useful later.

Now, you will have a new folder named library.test in the sites directory

Access the site in your browser

Now, that we have created our first site, we can access it on http://localhost:8000 in our browser.

At this point you should be able to login to your frappe Site. You can complete the tutorial on the Frappe Framework website. Thank you for reading.


Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.