Liferay provides us facility to run more than one portal instance on a single server. Liferay comes with one inbuilt portal instance, which is names 'Liferay' and its web id is 'liferay.com', however it can be modified with following properties in portal-ext.properties file:
Note: There are several other properties regarding portal instances present in portal.properties as well which can be referred in Liferay Portal SRC.
If we login as administrator (generally firstname.lastname@example.org), and go to control panel we can see list of all available portal instances in 'Portal Instances' section inside 'Server' category. Here we will see a table with atlest one entry (inbuilt one) , lets know what the column of this table depicts:
- Instance ID: It’s a numeric Id, generated by code automatically at the time of Instance creation. Internally this Instance ID is referred as 'companyid' in the database table. We can see all available instances in database table 'company'.
- Web ID: It’s a user-generated ID for the instance. It can be anything relevant but a general convention is to use the domain name.
- Virtual Host: Domain name which is to be configured in the network kept here. This domain name is referred when users are directed to our Liferay server, and the same enables Liferay to resolve request for proper portal instance.
- Mail Domain: The domain name to be used as mail host for this instance kept here. Liferay will use this to send email notifications from the portal, and the same is used for creating the default test user, as email@example.com
- # of Users: Depicts current number of users on particular portal instance.
- Max # of Users: Depicts total number of users allowed on particular portal instance.
- Active: Depicts if the portal instance active or not (Yes / No).
Enough of theory, lets experience it. Startup the server and replicate the following steps:
- Login as administrator. (firstname.lastname@example.org/test will work)
- Navigate to Manage → Control Panel → Portal Instances section in 'Server' category.
- By default only one portal instance will be listed. To add new, click on add button fill up the form fields. Say you have created 'newinstance.com'.
- Assuming that you are working on your local system, you have to edit the host file (%SYSTEMROOT%\ System32\ drivers\ etc\ hosts). Add the following in the file:
If you are in network then you can map the entry with the IP address of the server on which Liferay is running and try.
- Start the browser (restart in case already running) and put 'newinstance.com:<PORT>' in address bar. What you see now in the new portal instance.
- You can login as test@<domainname>, (email@example.com in out case). This is the admin user of the instance. As an administrator you cannot see the 'Server' category in Control Panel, which means new instance can be created only from main portal instance.
Handling Portal Instances in Custom Code:
In real life scenario, we may need to process data differently for each Portal Instance in our custom code. So have a look on small code snippet:
Hope you enjoyed the reading.