virtualMachineerpnext

Enable multi-tenant support

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.

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.

  • 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/apache/conf/vhosts/erpnext-vhost.conf to /opt/bitnami/apache/conf/vhosts/erpnext-NEW_SITE_NAME-vhost.conf.

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

      $ sudo cp -rp /opt/bitnami/apache/conf/vhosts/erpnext-vhost.conf /opt/bitnami/apache/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.

Last modification February 9, 2023