Support → Documentation → Stunnix Perl Web Server

# Introduction to startsite.pl script

The script 'startsite.pl' is located in the same directory where 'srvrun.pl' script is. It's a multipurpose wrapper that performs following tasks:

- initializes some environment variables to provide platform abstraction to the scripts - by computing various paths;
- checks whether the same site is already running on the computer - by loading state files and file containing port number web server for started for a given site last time; if it finds that the server for this site is already running, it just opens browser window with default site page and finishes execution.
- If no server is running for the site in question, a pair of free TCP ports is found, and configuration file with these port numbers and location of the document root is written in the temporary configuration file;
- Then Stunnix Perl Web Server itself is started by invoking 'srvrun.pl' script in the background, getting settings from 'httpd.conf' located in the directory where 'srvrun.pl' resides and from temporary configuration file generated on the previous step;
- Then 'startsite.pl' script waits till web server starts serving http requests;
- Once web server is listening for incomming connections, user's browser is started and default web page of the site is opened in it;

These tasks are configurable using configuration settings. It's safe to modify the following configuration settings:

Name | Default value | Description
--- | --- | ---
_debug | 0 | Specifies whether debugging mode is On. When debugging mode is on, the trace of performed operation is written to stderr, and some temporary files are not deleted at the end of script execution.
_docroot_default | ../www/root | Specifies the directory that corresponds to the root of the site. It can be relative path (with directory containing 'srvrun.pl' being the base for it). It's highly recommended to use unix-style slashes as directory separators; trailing slash is mandatory.
sitename | default | Specifies the so-called site ID. It's a string that unqiuely distinguishes the site from others. It should contain version number too. No more than 1 web server process group can be serving site with the same site ID for the given user. Giving sites with different content different site IDs allows user to use these several sites simultaneously.
urlpath |  | Specifies the default URL path to open in the browser once web server is started for the site. Default value is empty string.
show_win32_firewall_alert | 1 | Specifies whether to show message about possibility of firewall alerts on Windows platforms. Set to 1 to show it, set to 0 in order not to show it.
macosx_prefer_ie | 0 | Specifies whether to try opening page in MSIE if it's available (instead of default browser, that is Safari on most of MacOSX computers) on MacOS X. Set to 1 to try MSIE first, set to 0 to use default browser.
win32_prefer_ie | 0 | Specifies whether to try opening page in MSIE (instead of default browser. Set to 1 use MSIE, set to 0 to use default browser.

In most cases, it's enough to change only settings 'sitename' and '_docroot_default' (if document root is located not in '../www/root/').

# Altering behavior of 'startsite.pl'

Behavior of 'startsite.pl' script is rather configurable. Default values for configuration settings are stored in the %config hash, initialized in the script. It's possible to specify desired values for the settings using two methods:

- In the external file with name 'siteinfo.pm' located in the directory where 'startsite.pl' resides;
- By passing space-separated names and values of configuration settings on the 'startsite.pl' commandline;

## Specifying settings in the external file

During execution of 'startsite.pl', the existance of file 'siteinfo.pm' is checked in the directory where 'startsite.pl' resides. If it exists, it's interpreted using 'do' statement. This script is supposed to modify values of %config hash in any meaningful way.

Here is a content of 'siteinfo.pm' from the sample site shipped with Stunnix Perl Web Server (it's located in `/sample-image/site/stunnixwebsrv/` directory):

    $config{_docroot_default} = '../www/root/';
    $config{sitename} = "Perl-Obfus-2.0-Standard-0";

As you can see, the 'sitename' setting includes version of the browser-based application to allow running several versions of browser-based applications at the same time.

## Specifying settings on the command line

It's possible to pass values of settings on the commandline of 'startsite.pl'. Just specify name and value pairs on the commandline, as in example below:

    perl startsite.pl _debug 1 urlpath /admin.shtml

In the example above, values of '_debug' and 'urlpath' settings were specified on the commandline.