11.03 Configuring Apache

To change the Apache configuration you will need to modify the file “httpd.conf”.

If you have forgotten where this file can be found, try looking for it in the “conf” folder of your Apache installation. The actual location will depend on how you installed Apache.

Using the cgi-bin folder

If you want to run a very small number of scripts, you may be best placing them in the cgi-bin folder. Apache is often configured to treat any file in this folder as a CGI script.

Locate the line in the file “httpd.conf” that looks similar to the one below. It may have been commented out and the path may be different.

ScriptAlias /cgi-bin/ "C:/Program Files/Apache Group/Apache/cgi-bin/" 

If it has been commented out, that is, if there is a hash mark (“#”) before the line, remove the hash character to enable it.

If it has not been commented out, it means that your Apache is already configured to run CGI scripts in that folder. You can change this to whatever folder you want as your cgi default.

Running CGI from anywhere in your domain

If you don't want to be restricted to running CGI scripts from the default folder, you can allow cgi to run from any folder in your domain. Add the following line to your “httpd.conf” file.

AddHandler cgi-script .cgi 

The default httpd.conf file that is supplied by Apache comes with that line commented out. Just search for that string in your existing file, and remove the preceding comment character, that is, remove the “#”.

You will also want the .plex extension recognised as a CGI script as well. To do this simply add the extension to the list, as follows:

AddHandler cgi-script .cgi .plex

Now search for the line that says “<Directory /> in the file. The group of lines should look something like this:

<Directory />
  Options FollowSymLinks
  AllowOverride None
</Directory> 

Change the options list to read:

Options FollowSymLinks +ExecCGI 

Defaulting to your CGI Script

You now need to make your CGI script execute as the default page. You have to add another line to the Apache configuration file (httpd.conf).

Search for the line in the file that begins with a “DirectoryIndex”. You then add “index.cgi” or “index.plex” or whatever your file is called to the list of files on that line. For example, if the line used to be:

DirectoryIndex index.html 

change it to

DirectoryIndex index.plex index.html

Apache will search for the files in the order listed. The first one that it finds is used.

You can use any files that you want. For example, you could use the following line:

DirectoryIndex index.plex index.php index.cgi index.shtml index.html 

After you restart Apache and access “http://localhost/” or “http://localhost/directory/” without any filename specified, Apache will run “index.plex”. If that is not available it will look for the next in the list and will use the first one that it finds.

Modifying Your CGI Script

If your CGI script was a Windows executable file it would now be executed by Apache with no problem. As it is a script, however, it relies on the interpreter to run. You therefore need to tell Apache where to find the interpreter.

Your LynPlex script should contain an initial line of

#!/usr/bin/lynplex

or something similar. On a Unix-based kernel Apache needs this information to locate the interpreter.

Currently LynPlex only runs on Windows. Also it is unlikely that you installed your interpreter in the /usr/bin directory. In theory, you will need to change that first line to point to the real location of your interpreter.

In practice, you will probably set up your system so that Windows automatically invokes the interpreter. In this case the contents of this line will be ignored.


lynplex/lp1103.txt · Last modified: 2012/09/08 11:50 (external edit)