Setting up a web server can be complicated, so OptiPerl provides an internal server. It is not optimized for speed, like most production servers, but for testing purposes.

 

It also does not need any set-up. The only thing it must know is the folder where the scripts you have are located.

 

To use the internal server do the following:

 

1) Enable menu Server / Internal server

2) Set it's Server root to the path where all your scripts are located.

 

To run all the included examples with optiperl, you must select menu Server / Change server root and select folder c:\program files\optiperl\webroot. (or accordingly were you installed optiperl).

 

Open now a script from the cgi-bin folder above. Make sure the option "Run with server" is enabled, and press "Run".

 

icon_exclaim If you don't see html output of the scripts, please read the "Possible errors" in the next section.

 

Notice the url sent to the browser; It is http://127.0.0.1/cgi-bin/script.cgi (where script.cgi the filename you opened).

 

Also try opening the test.html from c:\program files\optiperl\webroot. If you run it, the url called is http://127.0.0.1/test.html

 

icon_arrow To conclude: When we set up the webroot to 

 

c:\program files\optiperl\webroot

 

  • the file

c:\program files\optiperl\webroot\test.htm

is called as

http://127.0.0.1/test.htm

 

  • the file

c:\program files\optiperl\webroot\cgi-bin\test-form.cgi

is called as

http://127.0.0.1/cgi-bin/test-form.cgi

 

  • If you try to open a file that is not under the webroot, you will get an error if you try to run it.

 

Also notice the form part of test.htm:

 

<form method="POST" action="/cgi-bin/test-form.cgi" name="PostForm">

 

The action part tells the browser what script to call to process the form. Since the form was called with http://127.0.0.1/test.htm, the browser adds the host part to the action above when pressing the submit button, and calls: http://127.0.0.1/cgi-bin/test-form.cgi

 

 

icon_arrow If we change the webroot to

 

c:\mywebs\mysite

 

  • the file

c:\mywebs\mysite\test.html

is called as

http://127.0.0.1/test.html

 

  • the file

c:\mywebs\mysite\cgi-bin\forum\test.cgi

is called as

http://127.0.0.1/cgi-bin/forum/test.cgi

 

  • Any other file not under c:\mywebs\mysite results in an error.

 

icon_arrow Notice that in all cases, after the host part (http://127.0.0.1/) the relative paths of the file compared to the webroot are appended.

 

The best thing to do is actually have your entire site offline, copying the directory structure, and setting as webroot the folder you copied all the files. This is important, so you can develop scripts and html pages that will work both offline and remotely, without any (or minimal) changes.

 

Let's assume your site is http://www.site.com/ and you can access your site with an FTP program. From path / your entire site starts:

 

/index.html

/images/background.gif

/cgi-bin/form.cgi

 

Copy all these files to a folder on your computer, like c:\mywebs\coolsite. Select as the internal server's webroot the folder c:\mywebs\coolsite.

 

icon_idea If you use html publishing software, then you already have your entire site offline. Select as webroot the folder containing all your files and subfolders of the site.

 

Now just like http://www.site.com/ will send /index.html, the same thing will happen by calling http://127.0.0.1/ or http://localhost/, without being connected to the internet. You can try loading index.html in optiperl and pressing run, or entering the above address in the Browser menu / URL and pressing "Go to url".

 

Let's assume index.html has a form that calls form.cgi. It could have something like:

 

<form method="POST" action="/cgi-bin/form.cgi" name="Form">

 

If the webroot of the internal server is correct, this will work on both servers without any change. When running http://127.0.0.1/index.html, the browser will call http://127.0.0.1/cgi-bin/form.cgi after pressing "submit". On http://www.site.com/index.html, the browser would call http://www.site.com/cgi-bin/form.cgi.

 

Before setting the webroot, think how the url's would be translated. Suppose by error, we set the webroot to c:\mywebs\. Now index.html would have to be called as http://127.0.0.1/coolsite/index.html and the form.cgi as http://127.0.0.1/coolsite/cgi-bin/form.cgi. We would also have to change the Action in the html page to action="/coolsite/cgi-bin/form.cgi". All the above would work, but after uploading to www.site.com, the html page would not work, since http://www.site.com/coolsite/cgi-bin/form.cgi does not exist.

 

icon_exclaim However your site might have a different directory structure (like a different htdocs and cgi-bin folder), but OptiPerl can support any configuration using aliases. Read more in possible scenarios.

 

 

Top  Previous  Next