generalerpnext

Enable multi-tenant support

NOTE: We are in the process of modifying the file structure and configuration for many Bitnami stacks. On account of these changes, the file paths stated in this guide may change depending on whether your Bitnami stack uses native Linux system packages (Approach A), or if it is a self-contained installation (Approach B). To identify your Bitnami installation type and what approach to follow, run the command below:

 $ test ! -f "/opt/bitnami/common/bin/openssl" && echo "Approach A: Using system packages." || echo "Approach B: Self-contained installation."

The output of the command indicates which approach (A or B) is used by the installation, and will allow you to identify the paths, configuration and commands to use in this guide. Refer to the FAQ for more information on these changes.

With Bitnami ERPNext you can host several ERPNext sites at the same time. This section describes the steps required to add a second site using DNS-based multitenancy. With this configuration you will be able to access your different ERPNext sites using different hostnames.

Your first site is automatically set as default site. You can change it with the command:

$ bench use sitename

NOTE: All bench commands should be executed as the bitnami user (or the user who installed the application) inside the frappe-bench directory of your ERPNext installation.

To configure Bitnami ERPNext to automatically select the site based on the hostname you use to access it, follow the steps below, depending on your installation type.

NOTE: Take into account that this configuration requires that you use different domains for each site. They can be public domains or local domains routed using the hosts file.

Approach A: Bitnami installations using system packages

  • Navigate to the frappe-bench directory of your ERPNext installation:

      $ cd /opt/bitnami/erpnext/frappe-bench
    
  • Create a new site and enable DNS multitenancy by executing the commands below.

      $ mysql -u root -pDB_PASSWORD -e "create database bitnami_NEW_SITE_NAME;"
      $ mysql -u root -pDB_PASSWORD -e "grant all privileges on bitnami_NEW_SITE_NAME.* TO 'bitnami_NEW_SITE_NAME'@'127.0.0.1' identified by 'bitnami';"
      $ bench config dns_multitenant on
      $ bench new-site NEW_SITE_NAME --db-name bitnami_NEW_SITE_NAME --db-password bitnami --mariadb-root-username root --mariadb-root-password DB_PASSWORD --install-app erpnext --force
    

    NOTE: NEW_SITE_NAME is a placeholder, remember to replace it with your preferred site name.

  • Copy the file /opt/bitnami/apache2/conf/vhosts/erpnext-vhost.conf to /opt/bitnami/apache2/conf/vhosts/erpnext-NEW_SITE_NAME-vhost.conf.

      $ sudo cp -rp /opt/bitnami/apache2/conf/vhosts/erpnext-vhost.conf /opt/bitnami/apache2/conf/vhosts/erpnext-NEW_SITE_NAME-vhost.conf
    
  • Copy the file /opt/bitnami/apache2/conf/vhosts/erpnext-vhost.conf to /opt/bitnami/apache2/conf/vhosts/erpnext-NEW_SITE_NAME-https-vhost.conf.

      $ sudo cp -rp /opt/bitnami/apache2/conf/vhosts/erpnext-vhost.conf /opt/bitnami/apache2/conf/vhosts/erpnext-NEW_SITE_NAME-https-vhost.conf
    
  • Modify the previously created files, erpnext-NEW_SITE_NAME-vhost.conf and erpnext-NEW_SITE_NAME-https-vhost.conf, replacing sites/erpnext by sites/NEW_SITE_NAME.

  • In the same files, also change the lines

      <Location />
          RequestHeader set X-Frappe-Site-Name erpnext
      </Location>
    

    to

      <Location />
          RequestHeader set X-Frappe-Site-Name NEW_SITE_NAME
      </Location>
    
  • In the same files, also change the line

      ServerAlias *
    

    to

      ServerName DOMAIN
      ServerAlias SUBDOMAIN
    

    NOTE: Replace the DOMAIN and SUBDOMAIN placeholders with the domain and subdomain names of the new ERPNext site (e.g. mydomain.com and www.mydomain.com, respectively).

  • Run the commands below to set permissions:

      $ sudo chown -R bitnami:daemon -R /opt/bitnami/erpnext/frappe-bench/sites/NEW_SITE_NAME
      $ sudo find /opt/bitnami/erpnext/frappe-bench/sites/NEW_SITE_NAME -type d -exec chmod 0775 {} \;
      $ sudo find /opt/bitnami/erpnext/frappe-bench/sites/NEW_SITE_NAME -type f -exec chmod 0664 {} \;
    
  • Restart the Apache server:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
    

Now, you should be able to access your new site using the configured ERPNext site domain, in your preferred browser. You can log in using the Administrator username and the password you specified when creating the new site using bench.

To access the original site, enter any other domain (or IP address) pointing to your instance in your preferred browser.

Approach B: Self-contained Bitnami installations

  • Navigate to the frappe-bench directory of your ERPNext installation:

      $ cd /opt/bitnami/apps/erpnext/htdocs/frappe-bench
    
  • Create a new site and enable DNS multitenancy by executing the commands below. NEW_SITE_NAME is a placeholder. Remember to replace it with your preferred site name.

      $ mysql -u root -pDB_PASSWORD -e "create database bitnami_NEW_SITE_NAME;"
      $ mysql -u root -pDB_PASSWORD -e "grant all privileges on bitnami_NEW_SITE_NAME.* TO 'bitnami_NEW_SITE_NAME'@'127.0.0.1' identified by 'bitnami';"
      $ bench config dns_multitenant on
      $ bench new-site NEW_SITE_NAME --db-name bitnami_NEW_SITE_NAME --db-password bitnami --mariadb-root-username root --mariadb-root-password DB_PASSWORD --install-app erpnext --force
    
  • Comment out the line that includes the prefix configuration file in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf file:

      # Include "/opt/bitnami/apps/erpnext/conf/httpd-prefix.conf"
    
  • Include the virtual host configuration file for ERPNext in the /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf file:

      Include "/opt/bitnami/apps/erpnext/conf/httpd-vhosts.conf"
    
  • Move the following lines from the beginning of /opt/bitnami/apps/erpnext/conf/httpd-app.conf to /opt/bitnami/apache2/conf/bitnami/bitnami-apps-vhosts.conf:

      <IfDefine !IS_ERPNEXT_LOADED>
          Define IS_ERPNEXT_LOADED
          WSGIDaemonProcess wsgi-erpnext user=daemon group=daemon processes=2 threads=15 home=/opt/bitnami/apps/erpnext/htdocs/frappe-bench/sites python-path=/opt/bitnami/apps/erpnext/htdocs/venv/lib/python2.7/site-packages:/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/erpnext:/opt/bitnami/apps/erpnext/htdocs/frappe-bench/env/lib/python2.7/site-packages:/opt/bitnami/apps/erpnext/htdocs/frappe-bench/apps/frappe python-eggs=/opt/bitnami/apps/erpnext/htdocs/.tmp display-name=%{GROUP}
      </IfDefine>
    
      WSGIProcessGroup wsgi-erpnext
      WSGIApplicationGroup %{GLOBAL}
    
  • Copy the file /opt/bitnami/apps/erpnext/conf/httpd-app.conf to /opt/bitnami/apps/erpnext/conf/httpd-app2.conf.

      $ sudo cp -rp /opt/bitnami/apps/erpnext/conf/httpd-app.conf /opt/bitnami/apps/erpnext/conf/httpd-app2.conf
    
  • Modify /opt/bitnami/apps/erpnext/conf/httpd-app2.conf replacing sites/erpnext by sites/NEW_SITE_NAME.

  • In the same file, also change the lines

      <Location "/">
          RequestHeader set X-Frappe-Site-Name "erpnext"
      </Location>
    

    to

      <Location "/">
          RequestHeader set X-Frappe-Site-Name "NEW_SITE_NAME"
      </Location>
    
  • Run the command below to set permissions:

      $ sudo chown daemon:daemon -R /opt/bitnami/apps/erpnext/htdocs/frappe-bench/sites/NEW_SITE_NAME
    
  • Edit the file /opt/bitnami/apps/erpnext/conf/httpd-vhosts.conf, duplicate the two existing code blocks and configure them as shown below. firsthostname.com and secondhostname.com are placeholders. Remember to replace them with your preferred host.

      <VirtualHost *:80>
          ServerName firsthostname.com
          ServerAlias www.firsthostname.com
          DocumentRoot "/opt/bitnami/erpnext/htdocs/frappe-bench/sites/"
    
          Include "/opt/bitnami/erpnext/conf/httpd-app.conf"
      </VirtualHost>
    
      <VirtualHost *:443>
          ServerName firsthostname.com
          ServerAlias www.firsthostname.com
          DocumentRoot "/opt/bitnami/erpnext/htdocs/frappe-bench/sites/"
          SSLEngine on
          SSLCertificateFile "/opt/bitnami/erpnext/conf/certs/server.crt"
          SSLCertificateKeyFile "/opt/bitnami/erpnext/conf/certs/server.key"
    
          Include "/opt/bitnami/erpnext/conf/httpd-app.conf"
      </VirtualHost>
    
      <VirtualHost *:80>
          ServerName secondhostname.com
          ServerAlias www.secondhostname.com
          DocumentRoot "/opt/bitnami/erpnext/htdocs/frappe-bench/sites/"
    
          Include "/opt/bitnami/erpnext/conf/httpd-app2.conf"
      </VirtualHost>
    
      <VirtualHost *:443>
          ServerName secondhostname.com
          ServerAlias www.secondhostname.com
          DocumentRoot "/opt/bitnami/erpnext/htdocs/frappe-bench/sites/"
          SSLEngine on
          SSLCertificateFile "/opt/bitnami/erpnext/conf/certs/server.crt"
          SSLCertificateKeyFile "/opt/bitnami/erpnext/conf/certs/server.key"
    
          Include "/opt/bitnami/erpnext/conf/httpd-app2.conf"
      </VirtualHost>
    
  • Restart the Apache server:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
    

Now, you should be able to access your first site using firsthostname.com. To access your second site enter secondhostname.com in your preferred browser. The credentials for the first site are the same credentials from the original ERPNext installation. The credentials for the second site are Administrator as username and the password you specified when creating the new site using bench.

Last modification September 6, 2021