Guide: Manual Install ERPNext on Ubuntu 17.xx & 18.xx

NOTE:

1). Clean install on Ubuntu

2). User is bench with sudo privileges

3). Installed on Virtualbox Virtual machines

Login to your Local User

Prerequisites

Ubuntu 17.XX or 18.XX server instance.

sudo apt update
sudo apt -y upgrade

Install Development Tools

ERPNext needs Python version 2.7 to work. Install Python 2.7.

sudo apt -y install python-minimal
You should be able to verify its version.
python -V

Install a few more dependencies.

sudo apt -y install git build-essential python-setuptools python-dev libffi-dev libssl-dev

"Install Python's pip tool. Pip is the dependency for Python Pakages."

wget https://bootstrap.pypa.io/get-pip.py
sudo python get-pip.py

"Ensure that you have the latest version of " pip " and " setuptools "."

sudo pip install --upgrade pip setuptools

Install Ansible using Pip. Ansible automates software provisioning, configuration management, and application deployment.

sudo pip install ansible

Install yarn On Debian or Ubuntu Linux, you can install Yarn via our Debian package repository. You will first need to configure the repository

curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list

Then you can simply

sudo apt-get update && sudo apt-get install yarn

Install MariaDB Server

Add the MariaDB repository into the system.

sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://mirror.nodesdirect.com/mariadb/repo/10.2/ubuntu xenial main'

Install MariaDB.

sudo apt update
sudo apt -y install mariadb-server libmysqlclient-dev

Provide a strong password for the MariaDB root user when asked.

The Barracuda storage engine is required for the creation of ERPNext databases, so you will need to configure MariaDB to use the Barracuda storage engine. Edit the default MariaDB configuration file my.cnf

sudo nano /etc/mysql/my.cnf

Add the following lines under the [mysqld] line.

innodb-file-format=barracuda
innodb-file-per-table=1
innodb-large-prefix=1
character-set-client-handshake = FALSE
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci

Also, add the following line under the [mysql] line.

default-character-set = utf8mb4

Restart MariaDB and enable it to automatically start at boot time.

sudo systemctl restart mariadb
sudo systemctl enable mariadb

Before configuring the database, you will need to secure MariaDB. You can secure it by running the mysql_secure_installation script.

sudo mysql_secure_installation

Install Nginx, Node.js and Redis

Add the Nodesource repository for Node.js 8.x.

sudo curl --silent --location https://deb.nodesource.com/setup_8.x | sudo bash -

Install Nginx, Node.js and Redis.

sudo apt -y install nginx nodejs redis-server

Start Nginx and enable it to start at boot time.

sudo systemctl start nginx
sudo systemctl enable nginx

Start Redis and enable it to start at boot time.

sudo systemctl start redis-server
sudo systemctl enable redis-server

Install PDF Converter

The wkhtmltopdf program is a command line tool that converts HTML into PDF using the QT Webkit rendering engine. Install the required dependencies.

sudo apt -y install libxrender1 libxext6 xfonts-75dpi xfonts-base

Download the latest version of wkhtmltopdf.

wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz

Extract the archive.

sudo tar -xf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz -C /opt

The above command will extract the archive to /opt/wkhtmltox. Create a softlink so that wkhtmltopdf and wkhtmltoimage can be executed globally as a command.

sudo ln -s /opt/wkhtmltox/bin/wkhtmltopdf /usr/bin/wkhtmltopdf
sudo ln -s /opt/wkhtmltox/bin/wkhtmltoimage /usr/bin/wkhtmltoimage

You can now run wkhtmltopdf -V to check if it is working, you will see this.

wkhtmltopdf -V
Result wkhtmltopdf 0.12.4 (with patched qt)

At this point, we have all the required dependencies installed. You can now proceed to install Bench.

Install Bench

Bench is a command line utility provided by Frappe to install and manage the ERPNext application on a Unix-based system for both development and production purposes. Bench can also create and manage Nginx and supervisor configurations.

Create a new user to run Bench processes in the isolated environment.

sudo adduser bench --home /opt/bench

Provide sudo permissions to the bench user.

sudo usermod -aG sudo bench

Login as the newly created bench user.

sudo su - bench

Clone the Bench repository in /opt/bench.

cd /opt/bench
git clone https://github.com/frappe/bench bench-repo

Install Bench using pip.

sudo pip install -e bench-repo

Once Bench is installed, proceed further to install ERPNext using Bench.

Install ERPNext using Bench

Initialize a bench directory with frappe framework installed. To keep everything tidy, we will work under the /opt/bench directory. Bench will also setup regular backups and auto updates once a day.

cd /opt/bench
bench init erpnext && cd erpnext

Create a new Frappe site.

bench new-site site1.local

The above command will prompt you for the MySQL root password. Provide the password which you have set for the MySQL root user earlier. It will also ask you to set a new password for the administrator account. You will need this password later to log into the administrator dashboard.

Download ERPNext installation files from the remote git repository using Bench.

bench get-app erpnext https://github.com/frappe/erpnext

Install ERPNext on your newly created site.

bench --site erp.example.com install-app erpnext

You can start the application immediately to check if the application installed successfully.

bench start

However, you should stop the execution and proceed further to set up the application for production use.

27 Likes

Thank you for the accurate and highly detailed installation steps. :slight_smile:

1 Like

Database Login Issues

In some cases Database may not login, to rectify the issue Please Follow below steps
sudo vim /etc/mysql/my.cnf

Add the following lines at the end:

[mysqld]

skip-grant-tables

Then Restart the service

sudo service mysql restart

Login to Mysql & follow the command

mysql -u root

use mysql

select * from mysql where user = 'root'; - Look at the top to determine whether the password column is called password or authentication_string

UPDATE mysql.user set *password_field from above* = PASSWORD('your_new_password') where user = 'root' and host = 'localhost'; - Use the proper password column from above

SELECT User, Host, plugin FROM user;

If Plugin is not mysql_native_password, then set the plugin by the below command

UPDATE user SET plugin='mysql_native_password' WHERE User='root';
FLUSH PRIVILEGES;
exit;

Remove the skip-grant-tables from /etc/mysql/my.cnf, restart the service & it’s Done

2 Likes

Setup Supervisor & Nginx for Production

By default, the ERPNext application listens on port 8000, not the standard HTTP port 80. Also, running the built in web server for production use is not recommended as we will be exposing the server to the world. You should use a production web server as a reverse proxy such as Apache or Nginx. We will use Nginx as a reverse proxy as it can be automatically configured using Bench. Bench can automatically generate and install the configuration according to the ERPNext setup.

Although we can start the application using the ‘bench start’ command, the execution of ERPNext will stop as soon as you close the terminal. To overcome this issue, you should use Supervisor, which is very helpful in running the application continuously in a production environment. Supervisor is a process control system that enables you to monitor and control a number of processes on Linux operating systems. Once Supervisor is configured, it will automatically start the application at boot time as well as on failures. Bench can automatically configure Supervisor for the ERPNext application.

Install Supervisor.

sudo apt -y install supervisor

Start Supervisor and enable it to automatically start at boot time.

sudo systemctl start supervisor
sudo systemctl enable supervisor

Setup Bench for production use.

sudo bench setup production bench

The above command may prompt you before replacing the existing Supervisor default configuration file with a new one. Choose y to proceed. Bench adds a number of processes to the Supervisor configuration file. The above command will also ask you if you wish to replace the current Nginx configuration with a new one. Enter y to proceed. Once Bench has finished installing the configuration, provide other users to execute the files in your home directory of the Bench user.

chmod o+x /opt/bench/

You can now access the site on http://erp.example.com.

You can check the status of the processes by running.

sudo supervisorctl status all

You should see the following output.

sudo supervisorctl status all
erpnext-redis:erpnext-redis-cache                 RUNNING   pid 13852, uptime 0:00:54
erpnext-redis:erpnext-redis-queue                 RUNNING   pid 13851, uptime 0:00:54
erpnext-redis:erpnext-redis-socketio              RUNNING   pid 13853, uptime 0:00:54
erpnext-web:erpnext-frappe-web                    RUNNING   pid 13856, uptime 0:00:54
erpnext-web:erpnext-node-socketio                 RUNNING   pid 13855, uptime 0:00:54
erpnext-workers:erpnext-frappe-default-worker-0   RUNNING   pid 13862, uptime 0:00:54
erpnext-workers:erpnext-frappe-long-worker-0      RUNNING   pid 13870, uptime 0:00:54
erpnext-workers:erpnext-frappe-schedule           RUNNING   pid 13869, uptime 0:00:54
erpnext-workers:erpnext-frappe-short-worker-0     RUNNING   pid 13875, uptime 0:00:54

To stop and Start all of the ERPNext processes.

sudo supervisorctl stop all
sudo supervisorctl start all
1 Like

Thanks for the detailed steps.

I tried installing on Ubuntu 18.04

Environment

Distributor ID: Ubuntu
Description: Ubuntu 18.04 LTS
Release: 18.04
Codename: bionic

Error

On bench installation i get the below error
command : bench init && cd erpnex
Result :
Exception:

Traceback (most recent call last):
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/commands/install.py", line 324, in run
    requirement_set.prepare_files(finder)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/req/req_set.py", line 554, in _prepare_file
    require_hashes
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/req/req_install.py", line 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/index.py", line 465, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/index.py", line 423, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/index.py", line 568, in _get_pages
    page = self._get_page(location)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/index.py", line 683, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/index.py", line 792, in get_page
    "Cache-Control": "max-age=600",
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 521, in get
    return self.request('GET', url, **kwargs)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/download.py", line 386, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 508, in request
    resp = self.send(prep, **send_kwargs)
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 640, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 218, in resolve_redirects
    **adapter_kwargs
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 658, in send
    r.content
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/_vendor/requests/models.py", line 823, in content
    self._content = bytes().join(self.iter_content(CONTENT_CHUNK_SIZE)) or bytes()
  File "/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pip/_vendor/requests/models.py", line 748, in generate
    raise ChunkedEncodingError(e)
ChunkedEncodingError: ("Connection broken: error(104, 'Connection reset by peer')", error(104, 'Connection reset by peer'))
Traceback (most recent call last):
  File "/usr/local/bin/bench", line 11, in <module>
    load_entry_point('bench', 'console_scripts', 'bench')()
  File "/opt/bench/bench-repo/bench/cli.py", line 40, in cli
    bench_command()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/opt/bench/bench-repo/bench/commands/make.py", line 30, in init
    python 		 = python)
  File "/opt/bench/bench-repo/bench/utils.py", line 75, in init
    get_app(frappe_path, branch=frappe_branch, bench_path=path, build_asset_files=False, verbose=verbose)
  File "/opt/bench/bench-repo/bench/app.py", line 134, in get_app
    install_app(app=app_name, bench_path=bench_path, verbose=verbose)
  File "/opt/bench/bench-repo/bench/app.py", line 167, in install_app
    find_links=find_links))
  File "/opt/bench/bench-repo/bench/utils.py", line 153, in exec_cmd
    raise CommandFailedError(cmd)
bench.utils.CommandFailedError: erpnext/env/bin/pip install -q  -e erpnext/apps/frappe --no-cache-dir

Could you please guide me what correction is required from my side.

Hi @jignesh_shah

I have tested the installation for Ubuntu 18.04 on virtual machine it’s worked for me, let me check and revert back

I tested on clean Installation of Ubuntu 18.04.
Not VM.

Let also check with complete installation

Hi @jignesh_shah

the command you entered is

bench init && cd erpnex

do enter the same command

that was typo error in the post, i actually ran the below command

bench init && cd erpnext

on re-executing the command got below error

Traceback (most recent call last):
  File "/usr/local/bin/bench", line 11, in <module>
    load_entry_point('bench', 'console_scripts', 'bench')()
  File "/opt/bench/bench-repo/bench/cli.py", line 40, in cli
    bench_command()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/opt/bench/bench-repo/bench/commands/make.py", line 30, in init
    python 		 = python)
  File "/opt/bench/bench-repo/bench/utils.py", line 52, in init
    raise ValueError('Bench Instance {path} already exists.'.format(path = path))
ValueError: Bench Instance erpnext already exists.

Sir the command is bench init erpnext && cd erpnext and first remove the folder as the command identifies the folder or the files already exists, please run the command inside the /opt/bench/erpnext folder

I have tested with the on system installation working fine with no issues

System details
Dell T30 Tower mini server
Xeon processor
8 GB Ram
Ubuntu 18.04 server

Sorry , Corrected the path, bench installed successfully.

after that when i ran command

bench new-site site1.local
Usage: bench [OPTIONS] COMMAND [ARGS]...

Error: No such command "new-site".

i did bench --help to list the command available, but “new-site” is not listed.

Commands:
  backup                 backup site
  backup-all-sites       backup all sites
  config                 change bench configuration
  disable-production     Disables production environment for the...
  download-translations  Download latest translations
  exclude-app            Exclude app from updating
  get-app                clone an app from the internet and set it up...
  include-app            Include app from updating
  init                   Create a New Bench Instance.
  install                Install system dependancies
  migrate-env            Migrate Virtual Environment to desired Python...
  new-app                start a new app
  release                Release app (internal to the Frappe team)
  remote-reset-url       Reset app remote url to frappe official
  remote-set-url         Set app remote url
  remote-urls            Show apps remote url
  remove-app             completely remove app from bench
  renew-lets-encrypt     Renew Let's Encrypt certificate
  restart                Restart supervisor processes or systemd units
  retry-upgrade
  set-default-site       Set default site for bench
  set-mariadb-host       Set MariaDB host for bench
  set-nginx-port         Set nginx port for site
  set-ssl-certificate    Set ssl certificate path for site
  set-ssl-key            Set ssl certificate private key path for site
  set-url-root           Set url root for site
  setup                  Setup bench
  shell
  src                    Prints bench source folder path, which can be...
  start                  Start Frappe development processes
  switch-to-branch       Switch all apps to specified branch, or...
  switch-to-develop      Switch frappe and erpnext to develop branch
  switch-to-master       Switch frappe and erpnext to master branch
  update                 Update bench

this is because the erpnext is not installed properly,
first remove erpnext and bench, & reinstall

i have make changes to paths due to security, now we have created the user bench instead of frappe & bench is also not have any home folder only a sudo user can make the changes

hurray ! it worked.

Thanks for your kind help and superb detailed steps.

Should i delete all my post for your post to remain clean and clear for all new users ?

Please add this to Wiki.

Thanks

1 Like

Done. Courtesy @Parag_Kapoor

Link to wiki Article

2 Likes

Using a clean install of ubuntu 18. When you get to the create a new site there is an error.

The original did something before this is that it does not ask for a root password on the database, instead it will skip over that.

Another time I installed the database which did ask for the root password during creation. However the results are the same.

Here is the traceback

Traceback (most recent call last):
File “/usr/lib/python2.7/runpy.py”, line 174, in _run_module_as_main
main”, fname, loader, pkg_name)
File “/usr/lib/python2.7/runpy.py”, line 72, in _run_code
exec code in run_globals
File “/opt/bench/erpnext/apps/frappe/frappe/utils/bench_helper.py”, line 97, in
main()
File “/opt/bench/erpnext/apps/frappe/frappe/utils/bench_helper.py”, line 18, in main
click.Group(commands=commands)(prog_name=‘bench’)
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/click/core.py”, line 722, in call
return self.main(*args, **kwargs)
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/click/core.py”, line 697, in main
rv = self.invoke(ctx)
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/click/core.py”, line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/click/core.py”, line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/click/core.py”, line 535, in invoke
return callback(*args, **kwargs)
File “/opt/bench/erpnext/apps/frappe/frappe/commands/site.py”, line 34, in new_site
verbose=verbose, install_apps=install_app, source_sql=source_sql, force=force)
File “/opt/bench/erpnext/apps/frappe/frappe/commands/site.py”, line 65, in _new_site
admin_password=admin_password, verbose=verbose, source_sql=source_sql,force=force, reinstall=reinstall)
File “/opt/bench/erpnext/apps/frappe/frappe/installer.py”, line 38, in install_db
create_database_and_user(force, verbose)
File “/opt/bench/erpnext/apps/frappe/frappe/installer.py”, line 62, in create_database_and_user
if force or (db_name not in dbman.get_database_list()):
File “/opt/bench/erpnext/apps/frappe/frappe/model/db_schema.py”, line 553, in get_database_list
return [d[0] for d in self.db.sql(“SHOW DATABASES”)]
File “/opt/bench/erpnext/apps/frappe/frappe/database.py”, line 165, in sql
self.connect()
File “/opt/bench/erpnext/apps/frappe/frappe/database.py”, line 115, in connect
charset=‘utf8mb4’, use_unicode = True, conv = conversions, local_infile = self.local_infile)
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/init.py”, line 90, in Connect
return Connection(*args, **kwargs)
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py”, line 704, in init
self.connect()
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py”, line 974, in connect
self._request_authentication()
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py”, line 1203, in _request_authentication
auth_packet = self._read_packet()
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py”, line 1059, in _read_packet
packet.check_error()
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/connections.py”, line 384, in check_error
err.raise_mysql_exception(self._data)
File “/opt/bench/erpnext/env/local/lib/python2.7/site-packages/pymysql/err.py”, line 109, in raise_mysql_exception
raise errorclass(errno, errval)
pymysql.err.InternalError: (1698, u"Access denied for user ‘root’@‘localhost’")

Hi @blueduck
please check whether you are able to login to database with

parag@parag-pc$mysql -uroot -p

if not then i have mentioned the steps for database login issue try with the steps then create the site you will get sucess
__
Thanks
Parag kapoor

1 Like