Configure apache

Table of Contents

Name
Synopsis
Auto-backup of patched files
Versions
URIs
Environment variables
MySQL
Documentation
Installation
Options
Security
PassEnv, ImageMagick and other Special Cases
Starting Apache from the command line
Starting Apache as a service
Virtual hosts and a crude DNS
Patching the demos
Required modules
Author
Copyright

Configure apache

Name

configure-apache.pl - A configuration program for the Apache web server for MS Windows.

Synopsis

If you wish to install Apache or Perl on a drive other than the default C:, then this program can help.

All of these instructions use D:\, rather than the default C:\, to more clearly indicate what needs to be done to install Perl and Apache on a drive other than C:.

  • Install perl-win32-bin-0.8.exe. Details below

    If you use MySQL, you must install V 3.23.51 or later.

    MySQL is not included in the file perl-win32-bin-0.8.exe.

  • Run configure-apache.pl [options]
    	Eg: shell>perl configure-apache.pl -ApacheRoot=e:\apache

    This example assumes Perl is in your path; ie that you have managed to get Perl working already.

    configure-apache.pl uses case-sensitive command line options.

    If you install Apache in D:\Apache, and Perl in D:\Perl, then the default options will be all you need to run configure-apache.pl.

    If you are installing both Perl and Apache on C:, then use the batch file config-Apache-for-C.bat. It overrides all the default options, and uses C: as the output drive.

    Note 1: That batch file contains an example of the option PassEnv.

    Note 2: You will need to put your own email address in for the ServerAdmin option.

    Of course, you will still have to edit your environment.

    Also, as explained below, you will almost certainly want to edit httpd.conf manually to limit incoming access to Apache, and to pass application-specific environment variables to CGI scripts.

Auto-backup of patched files

This program can safely be run repeatedly, since:

  • On the first run it backs up D:\apache\conf\httpd.conf to D:\apache\conf\httpd.conf.original
  • On the first run it backs up D:\perl\lib\Config.pm to D:\perl\lib\Config.pm.original
  • On the first run it backs up D:\perl\lib\CPAN\Config.pm to D:\perl\lib\CPAN\Config.pm.original
  • On every run it backs up D:\apache\conf\httpd.conf to D:\apache\conf\httpd.conf.bak
  • On every run it backs up D:\perl\lib\Config.pm to D:\perl\lib\Config.pm.bak
  • On every run it backs up D:\perl\lib\CPAN\Config.pm to D:\perl\lib\CPAN\Config.pm.bak

This means you always have a copy of the original files, and it is the output from the first run which gets patched on the second run, and so on.

Versions

  • MS Windows NT 4 SP 6
  • ActivePerl 5.6.1 Build 633
  • Apache 1.3.26
  • mod_perl 1.27
  • mod_ssl 2.8.10-1.3.26
  • OpenSSL 0.9.6d
  • configure-apache.pl 1.3.26
  • MySQL 3.23.51

URIs

A pre-compiled, self-extracting, binary of Perl + Apache + mod_perl + mod_ssl is at ftp://theoryx5.uwinnipeg.ca/pub/other/perl-win32-bin-0.8.exe and is of size 23,181,824 bytes.

configure-apache.pl is in http://savage.net.au/Perl/configure-apache.zip

This document can be extracted from configure-apache.pl and is at http://savage.net.au/Perl/html/configure-apache.html

The GNU utils for DOS can be installed using these instructions: http://savage.net.au/Ron/html/GNU-Utils.html

Environment variables

You'll find it convenient to patch and create some environment variables.

Under WinNT, use Start/Settings/Control Panel/System/Environment Variables to patch env vars.

Under Win2K, use Start/Settings/Control Panel/System/Advanced/Environment Variables to do the same thing.

Edit DOMAIN, HOME, NAME, PATH and TERM thus:

  • DOMAIN=www.ronnie.net.au
  • HOME=D:\
  • NAME=Your_name_without_spaces
  • Add these to PATH:
    • D:\Apache
    • D:\Apache\bin
    • D:\Apache\OpenSSL\Bin
    • D:\Perl\Bin
    • C:\MySQL\bin

      Or wherever you install LibMySQL.dll from MySQL.

      See also the next section for MySQL-specific notes.

  • TERM=dumb

MS Windows 9X/ME: You patch autoexec.bat to make these changes. Now you must reboot to have MS Windows recognize the changes.

MS Windows NT/2K: You need to reboot. Open DOS windows will not recognize the changes. Opening a DOS window from a shortcut will not make the changes visible, either. You must open a new DOS window via Start/Programs/Command Prompt or via the Microsoft Office toolbar (often at the top of the screen) to make the changes visible.

I've tried stopping/starting Apache after editing system environment variables, and the changes were not passed thru to CGI scripts. I've also tried stopping/uninstalling and installing/starting Apache, and that did not work either. Lastly, I've tried stopping/uninstalling/logging off as Admin and logging on/installing/starting Apache, and that did not work either.

Hint: Reboot all versions of MS Windows.

MySQL

I found that when using Win2K as a non-administrator, a CGI script can display the path including C:\MySQL\bin, but a CGI script which uses MySQL cannot find LibMySQL.dll. The simple solution is to copy LibMySQL.dll to the directory D:\Perl\site\lib\auto\DBD\mysql.

Also, in this non-administrator situation, I use MySQL like this:

  • Starting MySQL

    In one DOS box:

    	shell>cd C:\MySQL\bin
    	shell>mysqld-max -uroot

    This starts MySQL as the MySQL user 'root', not as a Win2K user.

  • Stopping MySQL

    In another DOS box:

    	shell>C:\MySQL\bin
    	shell>mysqladmin -uroot -ppass shutdown

    Test this before proceeding.

  • Connecting from Perl to MySQL
    	my($dbh) = DBI -> connect('DBI:mysql:mysql:127.0.0.1', 'root', 'pass', {});

However, I do not recommend this non-admin approach. I always install Apache and MySQL as admin, and patch all environment variables as admin. That way, I can install Apache and MySQL as services and have them available to all users, and have them restarted automatically whenever the system is rebooted.

Documentation

You can extract this documentation with pod2html, which is shipped with Perl.

Even better, perl-win32-bin-0.8.exe ships with Pod::POM, and a pod2html and pod2text replacement called pom2.

POM = POD Object Model. The name is modelled after DOM = Document Object Model.

Best though, is to download fancy-pom2.pl from my web site, and run it:

	shell>perl fancy-pom2.pl html css configure-apache2.pl > configure-apache2.html

or:

	shell>perl fancy-pom2.pl html -css configure-apache2.pl > configure-apache2.html

Installation

  • Backup old Apache
  • Uninstall old Apache
  • Remove the directory D:\apache
  • Backup old Perl, perhaps
  • Uninstall old Perl
  • Remove the directory D:\perl
  • Remove the directory D:\usr\bin

    See below for a note on the she-bang line of CGI scripts, and hence why you would have such a directory in the first place.

  • Run perl-win32-bin-0.8.exe

    This is a self-extracting WinZip file. Unpack into, say, D:\temp.

    See D:\temp\readmes\readme.txt for details. What follows in a very brief summary.

  • Copy D:\temp\apache to D:\apache

    The point of copying rather than moving is that the copy leaves you with untouched files, which, if necessary, you can re-install one-by-one to replace those which get patched in a way you don't like.

  • Disable EmbPerl

    Apache ships with Embperl, and the latter causes parts of Apache to crash upon startup. To fix this, edit D:\apache\conf\httpd.conf and comment out lines 1085 .. 1096.

  • Copy D:\temp\openssl to D:\apache\openssl
  • Copy D:\temp\perl to D:\perl
  • Copy D:\perl\bin\perl.exe to D:\usr\bin\perl.exe

    After installing Perl and doing this copy, the she-bang line of your CGI scripts can be the same on both Unix and MS Windows:

    	#!/usr/bin/perl

    as long as Perl and Apache are both on C:\ or both on D:\, of course.

  • Run configure-apache.pl [options]

    Options are documented in the next section.

  • Satisfy yourself configure-apache.pl worked

    The files patched are:

    • D:\apache\conf\httpd.conf
    • D:\perl\lib\Config.pm
    • D:\perl\lib\CPAN\Config.pm
  • Remove D:\temp\apache, D:\temp\openssl, D:\temp\perl and D:\temp\readmes

Options

configure-apache.pl uses case-sensitive command line options.

Here are the options and their defaults:

  • ApacheRoot = 'D:\Apache'
  • DLLRoot = 'D:/Perl'
  • OldApacheRoot = 'C:\Apache'
  • OldDLLRoot = 'C:/Perl'
  • OldPerlRoot = 'C:\Perl'
  • OldSSLRoot = 'C:/openssl'
  • OldServerRoot = 'C:/Apache'
  • PassEnv = ''

    PassEnv statements can be injected into httpd.conf by using the PassEnv option thus:

    	shell>perl configure-apache2.pl -PassEnv MAGICK_HOME,PATH

    Note the use of a comma separated list of environment variable names, without spaces.

  • PerlRoot = 'D:\Perl'
  • SSLRoot = 'D:/Apache/OpenSSL'
  • ServerAdmin = 'ron@savage.net.au'
  • ServerRoot = 'D:/Apache'
  • help | ?
  • man

-man only works if Perl is on C:\ or you have patched X:\perl\lib\config.pm, since it invokes X:\perl\bin\perldoc.

Security

As shipped, Apache responds to anyone who submits request to your web server, due to these 2 lines, which appear at various places in httpd.conf:

	Order allow,deny
	Allow from all

configure-apache2.pl now automatically converts almost all these to:

	# Order allow,deny
	# Allow from all
	   Order deny,allow
	   Deny from all
	   Allow from 127.0.0.1

When you feel comfortable with the amount of access you're allowing people to have, revert this limitation.

I said 'almost all'. Exceptions are where httpd.conf already says 'Deny from all'.

PassEnv, ImageMagick and other Special Cases

To get Apache to pass application-specific environment variables to CGI scripts, it is necessary to use Apache's PassEnv command.

ImageMagick, prior to V 5.4.8, is an application which relies on an environment variable called MAGICK_HOME.

Note: Pre-compiled versions of ImageMagick under MS Windows, from V 5.4.8 on, does not use MAGICK_HOME.

You can get configure-apache2.pl to patch httpd.conf so that CGI scripts have access to the value of MAGICK_HOME by using the following option:

	shell>perl configure-apache2.pl -PassEnv MAGICK_HOME

This would have the effect of putting:

	PassEnv MAGICK_HOME

at the end of httpd.conf.

As always after patching httpd.conf, you must stop and restart Apache.

You may want to do this, since ImageMagick uses TMPDIR, not TEMP and not TMP:

	shell>perl configure-apache2.pl -PassEnv MAGICK_HOME,TMPDIR

This would have the effect of putting:

	PassEnv MAGICK_HOME
	PassEnv TMPDIR

at the end of httpd.conf.

Consider doing the same with PERL5LIB.

Starting Apache from the command line

You did edit Embperl out of httpd.conf as explained right at the start of this doc, didn't you?

Start and stop Apache from the command line, ie not as a service:

In one DOS window:

	D:\>cd Apache
	D:\Apache>apache -k start

You'll get this message:

Apache/1.3.26 (Win32) AxKit/1.6 mod_ssl/2.8.10 OpenSSL/0.9.6d mod_perl/1.27_01-dev PHP/4.2.1 running...

Control will not return to the command line.

Then, in another DOS window:

	D:\>cd Apache
	D:\Apache>apache -k stop

Starting Apache as a service

You can install Apache as a service, but not start it, with:

	D:\>cd Apache
	D:\Apache>apache -i

This installation is permanent. Ie after a reboot you will not need to reinstall Apache.

You can remove Apache as a service, with:

	D:\Apache>apache -u

Enough practice.

Now, try installing but not starting Apache.

Then go to Start/Settings/Control Panel/Services. Click on Apache. Click on Start.

Also, Matt Wilkins tells me there is another way (which I have not tried):

Create a separate logon account just for Apache with restricted permissions (cannot install software etc) and tell the services manager (which is software, not a person) to use that account to start the Apache service instead of using the local system account.

Virtual hosts and a crude DNS

DSN stands for Domain Name Service.

In some versions of MS Windows (95/98/ME), the file C:\Windows\Hosts provides a conversion from an IP address to a domain name and visa versa. The file Hosts.sam is a sample, and is not read by Windows.

In MS Windows NT/2K/XP, the C:\WinNT\Hosts file's a fake: Use C:\WinNT\System32\Drivers\Etc\Hosts. Not only that, but Windows Explorer will lie to you about the attributes of the latter file. You must log off as a user and log on to NT as an administrator before you can save edits into this file.

MS Windows does search in other places too, including the LMHOSTS file. See also Start/Settings/Control Panel/Network/Protocols/(TCP/IP Protocol)/Properties/DNS. I'm ignoring this other search process here.

Now, put 1 non-comment line in C:\WinNT\System32\Drivers\Etc\Hosts (or in C:\Windows\Hosts if you're not using MS WinNT):

	127.0.0.2	ronnie.net.au

Start Apache again. Then in your web client, eg web browser, try both of these:

	http://127.0.0.1
	http://localhost

In both cases you will see a page which starts off:

	Forbidden
	You don't have permission to access / on this server.

Recall this is interacting with the 'Allow from localhost' discussed above.

Change the Hosts file to:

	127.0.0.1	ronnie.net.au

Stop and start Apache.

Edit line 1 of D:\apache\cgi-bin\printenv to be #!/perl/bin/perl. We can use /perl here since Apache and Perl are both on D:.

Now try these:

	http://127.0.0.1/cgi-bin/printenv
	http://localhost/cgi-bin/printenv

They fail! If they appear to work, this will be cached output from a previous attempt: Click Refresh.

The first fails because Apache is now using the Hosts file, but on line 656 of httpd.conf, it says:

    Allow from localhost

but 127.0.0.1 is not 'Allow'ed, whereas the second fails because localhost is 'Allow'ed, but not mentioned in the Hosts file!

So, edit line 656 of httpd.conf to say:

	Allow from localhost 127.0.0.1

Stop and start Apache.

Now they both work. Frankly, I think the second:

	http://localhost/cgi-bin/printenv

should not work because localhost is not mentioned in the Hosts file.

However, as soon as I try http://ronnie.net.au/cgi-bin/printenv Apache insists on connecting to the internet, by dialling out. I dial, and then Apache displays the same page that http://127.0.0.1/cgi-bin/printenv produced.

Further, if I put another line in C:\WinNT\System32\Drivers\Etc\Hosts:

	127.0.0.2	zoe.ronnie.net.au

then both http://127.0.0.2/cgi-bin/printenv and http://zoe.ronnie.net.au/cgi-bin/printenv return nothing unless and until Apache has forced me to dial my ISP.

Even then, I get this:

	Forbidden
	You don't have permission to access /cgi-bin/printenv on this server.

until I put:

	Allow from localhost ronnie.net.au

in httpd.conf at line 656, and restart Apache.

Ideally, I would change 'Allow from localhost' to 'Allow from localhost ronnie.net.au' everywhere, not just on line 656.

One last patch. I find putting:

	127.0.0.1	localhost

in the Hosts file makes life easy. For example, the demo clickable_image.cgi will not display the image until you patch Hosts like this, and make the other changes described in the next section.

Confused? Join the WWW (World Wide Worried).

Your Hosts file is the key to getting virtual hosts to work in Apache.

Patching the demos

  • D:\Apache\cgi-bin\clickable_image.cgi

    Patch line 1 to be #!/perl/bin/perl.

    But, the script is simply buggy. Patch line 14 from:

    	print $query->image_button('picture',"./wilogo.gif");

    to

    	print $query->image_button('picture',"/wilogo.gif");

    and move wilogo.gif from D:\Apache\cgi-bin to D:\Apache\htdocs.

  • D:\Apache\cgi-bin\save_state.cgi

    Patch line 1 to be #!/perl/bin/perl.

    Then, create the directory D:\Apache\cgi-bin\WORLD_WRITABLE before running this one.

  • D:\Apache\cgi-bin\tryit.cgi

    Patch line 1 to be #!/perl/bin/perl.

    Patch line 34 from:

    	print a({href=>'../cgi_docs.html'},'Go to the documentation');

    to

    	print a({href=>'/index.html'},'Go to the documentation');

Re the other demos: Some work, some require the Netscape browser, and some require Unix.

Required modules

Only modules which are shipped with this version of Perl.

Author

configure-apache.pl was written by Ron Savage <&#114;&#111;&#110;&#64;&#115;&#97;&#118;&#97;&#103;&#101;&#46;&#110;&#101;&#116;&#46;&#97;&#117;> in 2001.

Home page: http://savage.net.au/index.html

Copyright

Australian copyright © 2001, 2002, Ron Savage. All rights reserved.

This POD was converted to HTML by http://savage.net.au/Perl.html#fancy-pom2.pl

	All Programs of mine are 'OSI Certified Open Source Software';
	you can redistribute them and/or modify them under the terms of
	The Artistic License, a copy of which is available at:
	http://www.opensource.org/licenses/index.html
 
Top of page