How to create new virtual host from command line?

Discussion in 'General OpenLiteSpeed Discussion' started by ckissi, May 21, 2017.

  1. ckissi

    ckissi Member


    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?
  2. lsfoo

    lsfoo Administrator

    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!
  3. ckissi

    ckissi Member

    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?
  4. lsfoo

    lsfoo Administrator

    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
  5. ckissi

    ckissi Member

    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 ?
  6. lsfoo

    lsfoo Administrator

    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.

Share This Page