How to create new virtual host from command line?


I would like to create a script that will be able to create a new virtual host from a command line. Can be template based, so I need just add a new site to an existing template from a command line.

Is this possible and if so how?


Hi @ckissi

There is no cli for creating a virtual host per se, but if you have an example vhost you can work with, you can create a script for it.

The minimum requirements are:
1. vhost configuration file under /usr/local/lsws/conf/vhosts/NAME
2. vhost directory
3. server config - only a small section needs to be appended.

The configuration file can be based on another configuration file (remember to check the file ownership/permissions)

The only thing to do after that is to create a vhost mapping for the vhost.

Let us know how it goes!
Hi @lsfoo

Where are the vhosts defined in template located? I have a template defined and want to add new vhost to that template programmatically. Is that possible?


Do you mean adding a member to a vhost template? You will have to parse for your vhost template setting in the server configurations and add a new member entry.

vhTemplate PHP_SuEXEC {
  templateFile            $SERVER_ROOT/conf/templates/phpsuexec.conf
  listeners               Default

  member test
Had a hard time but finally found it in the /usr/local/lsws/conf/httpd_config.conf. Thank you.

So I have to just parse that file and add another member to the vhTemplate section of my template and make graceful restart. Right ?


That should create a new member vhost, yes. You can try creating one via web admin first to see what happens to the file so you know exactly what to add.