azureerpnext

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.

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) at ‘/opt/bitnami/apps/erpnext/htdocs/frappe-bench’.

There are two ways of setting up multitenant: Port based and DNS based multitenancy.

Port based multitenancy

To configure Bitnami ERPNext to automatically select the site based on the port, follow the steps below. With this configuration you will be able to access your different ERPNext sites using different ports.

  • Create a new site by executing the commands below:

    $ cd /opt/bitnami/apps/erpnext/htdocs/frappe-bench
    $ bench new-site NEW_SITE_NAME
    $ bench --site NEW_SITE_NAME install-app erpnext
    
  • 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.

  • 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/apache2/conf/bitnami/bitnami-apps-vhosts.conf, duplicate the two existing code blocks and configure them as shown below. Please, be aware of the Listen PORT lines. PORT is a placeholder, remember to replace it with the corresponding value.

    <VirtualHost *:80>
        DocumentRoot "/opt/bitnami/erpnext/htdocs/frappe-bench/sites/"
    
        Include "/opt/bitnami/erpnext/conf/httpd-app.conf"
    </VirtualHost>
    
    <VirtualHost *:443>
        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>
    
    Listen 8080
    <VirtualHost *:8080>
        DocumentRoot "/opt/bitnami/erpnext/htdocs/frappe-bench/sites/"
    
        Include "/opt/bitnami/erpnext/conf/httpd-app2.conf"
    </VirtualHost>
    
    Listen 8443
    <VirtualHost *:8443>
        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
    

After this process, your first site should be reachable at http://SERVER_IP:80 or https://SERVER_IP:443 for SSL. To access your second site, enter http://SERVER_IP:8080 or https://SERVER_IP:8443 for SSL in your preferred browser. SERVER_IP is a placeholder, remember to replace it with the corresponding value. 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.

DNS based multitenancy

To configure Bitnami ERPNext to automatically select the site based on the hostname you use to access it, follow the steps below. With this configuration you will be able to access your different ERPNext sites using different hostnames.

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. Accessing the application using an IP address (127.0.0.1 or your server’s one) will lead to the Bitnami ERPNext Stack welcome page.

  • Create a new site and enable DNS multitenant by executing the commands below. NEW_SITE_NAME is a placeholders. Remember to replace it with you preferred site name.

    $ cd /opt/bitnami/apps/erpnext/htdocs/frappe-bench
    $ bench config dns_multitenant on
    $ bench new-site NEW_SITE_NAME
    $ bench --site NEW_SITE_NAME install-app erpnext
    
  • 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.

  • 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/apache2/conf/bitnami/bitnami-apps-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 you 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 October 19, 2018