KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: How to run multiple web servers in a single 4D instance
PRODUCT: 4D | VERSION: 18 R3 | PLATFORM: Mac & Win
Published On: July 27, 2020

4D v18 R3 now allows us to start a web server for a host database and also each hosted component, using the command WEB Server and method webServer.start(). This means that we can have multiple web servers running simultaneously with just one 4D application open. Here is how we would set it up, so that each web server automatically launches after the host database starts up.

In our component database, we create a method to get our web server object and start the server:



We create and pass a $settings object into $webServer.start() to configure the HTTP and HTTPS ports, so as to not use the same ports as our host database's web server when we start the component web server. Then, we put our method in the On Host Database Event method:



We repeat the above steps for other component databases, making sure to select different port numbers each time.

In our host database, we configure the database settings to launch the web server at startup:



Also in database settings, under the Security tab, we toggle on the 'Execute "On Host Database Event" method of the components' option.



Then, after we restart the host database, all web servers for the host database and its components should be running. We can confirm this by using WEB Server List to get a collection of all Web server objects available:



After executing the above method, we get this alert message: