Mini Servers: Apache 2.2.9 Service

Revision as of 19:24, 20 July 2008 by Ric (talk | contribs) (New page: {{Uc nav mini servers}} Apache 2.2.9|right'''Mini server using Apache 2.2.9 Core run as service''' This page covers running our mini server (describe on the previ...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Mini Servers:  Introduction | Support | Server 1 - Portable | Server 2 - Service | Server 3 - Portable Authentication | Server 4 - Portable Authen. SSL | Server 5 - SSL Standalone | Browsers dislike self-signed certificates | Server 6 - PHP 5.2.6 Portable | Server 7 - PHP 5.2.6 Service | Server 8 - MySQL Support | Guest Book | Server 9 - Perl 5.2.6 Portable | Server 10 - Perl 5.2.6 Service | Server 11 - MySQL 5.0.67 Portable | Server 12 - MySQL 5.0.67 Service | Server 13 - MySQL 4.1.22 Portable | Server 14 - MySQL 4.1.22 Service | phpMyAdmin - Mini support | MySQL - General problems

Mini Servers:
Compact but fully functional.

Mini server using Apache 2.2.9 Core run as service

Apache 2.2.9
Apache 2.2.9

This page covers running our mini server (describe on the previous page) as a service, its big brother Uniform Server 3.5-Apollo automates this process. We are not going to take this easy option! Well you would never learn anything by doing that, the manual alternative although slightly more difficult provides an insight into Apache and Uniform Servers flexibility.

Interestingly I looked at the surgery performed on both Apache and Uniform Server, seems Uniform Server was mutilated beyond all recognition only the batch files survived while Apache remained reasonably recognisable.

Note: Check support section for download details

Top

Specification

The server has the following specification:

  • Server shall run as a service
  • Only static HTML pages shall be served.
  • The server shall log all web requests.
  • All unused modules shall be disabled.

The only difference in this specification server is no longer portable but run as a service. This means every time you restart your PC the Apache server will automatically start. The advantage of this, when running a server permanently connected to the Internet should a power interruption occur the server will automatically restart when power is restored. If other elements of the system have been set accordingly then your Internet presence will also be restored.

Top

Security Issues

Security issues remain as explained on the previous page. I would like to stress this is about as best as it gets. If you take this server and pop it on a Unix box you can harden it a little more, however they are also faced with the same issues.

Top

Changes

Interestingly if you run the portable version of this sever on a dedicated disk the configuration file would remain unchanged. Use the two new batch files and you are ready to go.

However like many others I run this on C drive with loads of other software yep alarm bells security issue, I am neither complacent nor unaware of these issues, Apache is probably the most secure bit on kit I have on my PC. Anyway I digress; changes are all associated with paths more precisely relative and absolute.

Top

Relative

In theory Apache is quite happy to use relative paths for example “/” refers to the top level of the current disk. Uniform Server and our portable mini server use this to great advantage by defining a dedicated virtual disk “w”. However when changing across disk space Windows gets uptight about relative paths unless you can explicitly define a disk.

Absolute

Windows likes pegs hammered into the ground so to speak, hence when running as a service specifying absolute paths is essential to keep both parties happy for example c:\uc_server_1b, the drive must be specified and then any folders etc.

No need to ramble on, just remember absolute paths are the order of the day so lets roll up ours sleeves and look at some code hacking.

Top

Configuring Apache

As mentioned above absolute paths are required in the configuration file. I have chosen to run the server on C drive from folder uc_server_1b you can use a different drive and or folder the choice is yours, just substitute accordingly. I have highlighted these absolute paths in bold interestingly these are the only changes required to our original configuration file.

httpd.conf located in folder: C:\uc_server_1b\usr\local\apache2\conf

# UniCenter - Very basic server
# Author: Mike Gleaves
# Main Apache 2.2.9 HTTP server configuration file.
# 14-7-2008

# ================================================
# Modules
# ================================================
 LoadModule authz_host_module modules/mod_authz_host.so
 LoadModule dir_module modules/mod_dir.so
 LoadModule log_config_module modules/mod_log_config.so
 LoadModule mime_module modules/mod_mime.so

# ========================================
# Basic settings
# ========================================
 Listen 80
 ServerName localhost:80
 ServerAdmin fred@www.somedomain.com
 UseCanonicalName Off
 ServerSignature Off
 HostnameLookups Off
ServerTokens Prod
 ServerRoot "c:/uc_server_1b/usr/local/apache2"
 DocumentRoot "c:/uc_server_1b/www"
 PidFile /logs/httpd.pid
<IfModule mod_dir.c>
  DirectoryIndex index.html index.htm
</IfModule>

# ========================================
# HTTP and performance settings
# ========================================
 Timeout 300
 KeepAlive On
 MaxKeepAliveRequests 100
 KeepAliveTimeout 15
<IfModule mpm_winnt.c>
  ThreadsPerChild 64
  MaxRequestsPerChild 0
</IfModule>

# ========================================
# Access control
# ========================================
<Directory />
  Options None
  AllowOverride None
  Order deny,allow
  Deny from all
</Directory>

<Directory "c:/uc_server_1b/www">
  Order allow,deny
  Allow from all
</Directory>

# ========================================
# MIME encoding
# ========================================
 DefaultType text/plain
 TypesConfig /usr/local/apache2/conf/mime.types

# ========================================
# Logs: debug, info, notice, warn, error, crit
# ========================================
 LogLevel warn
 LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\"
 \"%{User-Agent}i\"" combined
 LogFormat "%h %l %u %t \"%r\" %>s %b" common
 LogFormat "%{Referer}i -> %U" referer
 LogFormat "%{User-agent}i" agent
 ErrorLog "logs/error_log"
 CustomLog "logs/access.log" combined
# ========================================

Top

uc_install.bat

Batch files to install and uninstall Apache as a service are not very complex; the trick is to supply all the right parameters as shown.

Install service employs a nice bit of defensive programming when run the first line checks Apache’s configuration file for errors. Errors are listed including line numbers once corrected rerun the batch file. The second line installs Apache as a service once installed the third line starts the service.

uc_install.bat located in folder: C:\uc_server_1b
@echo off
echo.
c:\uc_server_1b\usr\local\apache2\bin\Apache.exe -k install -n "Apache2"
echo.
net start Apache2
echo.
echo Type http://localhost into your browser to access server.
echo.
pause

Top

uc_uninstall.bat

The uninstall batch file first stops the “Apache2” service and then proceeds to uninstall it.

uc_uninstall.bat located in folder: C:\uc_server_1b
@echo off
echo.
net stop Apache2
echo.
c:\uc_server_1b\usr\local\apache2\bin\Apache.exe -k uninstall -n "Apache2"
echo.
echo Done
pause

Top

Command Line

After installing the Apache service with the above batch file you can start and stop the "Apache2" service at anytime using a command line this saves uninstalling the service every time you want to stop the server:

  • net stop Apache2
  • net start Apache2

Top

Support files

Each mini server is complete and zipped into a single self-extracting archive file.

Download

Download this server from the mini server's Support and download page. Save the file uc_server_1b.exe to drive C.

Note: Check the file's integrity using its MD5 a suitable checker winMd5Sum Portable can be found at Portable Apps under Utilities.

Top

Extract files

Double click on uc_server_1b.exe, starts the extraction process. No need to change the folder destination, click extract, this creates a new folder uc_server_1b containing two files and two folders.

  1. uc_install.bat - Double click to install and start server as a service.
  2. uc_uninstall.bat - Double click to stop and uninstall server service.
  3. usr - Folder containing the server.
  4. www - Folder containing a test web site (delete this and place your site in this folder).

Top

Test

Testing is straight forward.

  1. Install the server by double clicking on uc_install.bat (Checks config file, installs service and runs it)
  2. Type http://localhost/ into the browser address bar.
  3. An index page is displayed, check out the test site MPG1.

Note 1: The server automatically starts when your PC is restarted (that’s the reason for installing as a service.)

Note 2: Adding extra pages or changing your web site there is no need to either restart or uninstall the server.

Note 3: Stop the service before making changes to Apache's configuration file; restarting service guarantees the new changes will be picked up.

Top

Your web site

Open the folder www located in folder *uc_server_1b\www delete everything in this folder and copy your site in to it.

Note: Make sure one of your pages in folder www is named index.html or index.htm, otherwise you will need to type a page name in every time to access your site.

e.g. http://localhost/somepage.html

Top

Summary

That concludes server 1, I have shown how to run it either in a portable or service configuration. It is a very powerful mini server you can use for either testing or putting your web site on-line (production server). The configuration file is clean allowing you to easily explore other Apache configurations.

Shame it’s only capable of serving static pages, not to worry the next mini server has this covered with PHP.dynamic duo Apache and Uniform Server make an excellent basic portable server.

Top


  Ric