MySQL + Apache + PHP + (PHPLIB) + OpenSSL/mod_ssl + mod_gzip installation and configuration

Jun Da (

(Version 1.2. Last modified: 2001-09-17. Older versions: 1.0, 1.1.)

Table of contents

  1. Before you begin
  2. Operating systems
  3. Software to download
  4. Installation
    1. OpenSSL
    3. Webmin
    4. MySQL
    5. Apache (with optional mod_ssl)
    6. PHP
    7. phpMyAdmin
    8. PHPLIB
    9. mod_gzip
    10. DBI and Msql-Mysql
  5. After installation
    1. Simple sample code
  6. Disclaimer


This is my quick cookbook of a web server (with database backend) out of a Unix box. Most instructions found in this tutorial are either available online or included in those INSTALL/README docs that come with the source packages. It took me quite a while to put all the pieces of the puzzle together. Hence here is this document to save you some time. Please note that this tutorial is by no means a substitution of the original documentation from those packages. It is suggested that you consult them whenever necessary.

Please read the Disclaimer before you proceed!

1. Before you begin

1.1 Tips for using this document

It is recommended that you read, or at least skim through this document before attempting to build and install the software packages.

To print this document, it is suggest that you use Netscape Version 4 (for better printout layout).

1.2 Objectives

There are two objectives we want to achieve:

  1. A web server with database support on a UNIX system. Specifically, we are talking about running the Apache web server with MySQL as the database backend, PHP as the server-side scripting language (loaded as a dynamically linked module), and OpenSSL/mod_ssl for secure data transmission. (Note that PHP3 will be installed as an optional module.)
  2. Web-based interfaces for performing most system administration tasks including Apache and MySQL configuration/administration.

1.3 Hardware requirement

In order to compile MySQL successfully with reasonable speed, it is suggested that your machine has a 200MHz (or better) CPU with 64M+ RAM. (Note: I was able in installing MySQL 3.22.32 on a system with 32M of RAM but it took for ever to finish.)

1.4 Conventions used in this tutorial

I will use the # sign to indicate that the shell command is to be executed by the superuser (root) and the % sign by ordinary shell user in the rest of this tutorial.

2. Operating system(s)

Instructions provided in this tutorial have been tested on FreeBSD 4.3 ( (Previous versions were tested on FreeBSD 4.1 and Linux 6.2, respectively). With minor modifications such as folder paths or location of system init files, the instructions provided here should be applicable to other UNIX systems as well.

My FreeBSD box is a 'minimal installation', i.e., bare-bone OS that contains the necessary compilers, etc.. When you have a fresh FreeBSD installation, choose the 'minimal installation' option if you are going to use your UNIX box as a server (e.g., for web and email services) only (i.e., without using the X-window system).

With a few modifications such as system init scripts, the installation instructions provided here should be applicable to other UNIX flavors. Notes about Linux will be provided where appropriate.

3. Software to download

We will use /usr/src/local as the folder to store all the downloaded packages. Before downloading, you need to become the superuser and create the /usr/src/local folder.

% su root 

# mkdir /usr/src/local

# cd /usr/src/local

Now grab all the source packages listed below. Remember to download the source code only (but not pre-compiled binary packages). Note also that by the time you read this tutorial, version numbers may be different.

Suppose we save all the downloaded software packages in the /usr/src/local folder, we now unpack all the gzipped and tarred files. For example, to unpack the apache package, we issue the following commands:

# gunzip apache_1.3.20.tar.gz 

# tar xvf apache_1.3.20.tar

(Or alternatively, you can use

# tar zxvf apache_1.3.20.tar.gz

to unpack the gzipped tarball all at once if the tar on your system supports the z option.)

Repeat the above procedure for every gzipped tarball you have downloaded.

4. Installation

We are going to install the different packages in the order given below:

  1. OpenSSL (Optional)
  2. Net_SSLeay (Optional Perl module. Requires Perl5.005 or better)
  3. Webmin (Optional but strongly recommended)
  4. MySQL
  5. Apache (with MM, mod_ssl, etc.)
  6. PHP
  7. phpMyAdmin (Optional but strongly recommended)
  8. PHPLIB (Optional)
  9. mod_gzip (Optional)
  10. DBI and Msql-Mysql (Optional)

It is suggested that you follow the order of installation as given above, since some packages (e.g., mod_ssl) will depend on other packages (being installed properly).

Further, PHP Version 4 will be installed as dynamically linked modules within the Apache web server, whereas PHP3 is an optional installation.

4.1 Install OpenSSL (Optional)

If you are not interested in running Apache for secure transactions (that requires mod_ssl), you can skip this section.

FreeBSD 4.3 comes with OpenSSL 0.9.6 preinstalled as part of the base OS. This part is provided just in case your systems does not have it or you want to upgrade it to the latest version (The latest version of OpenSSL is 0.9.6a as of 2001-05-28, whereas FreeBSD 4.3 comes with OpenSSL 0.9.6).

# cd openssl-0.9.6a/

# ./config \

          -no-idea \                  (European users*)


# make

# make test

# make install

# cd ..

* Copied from mod_ssl INSTALL file. I do not know why this option should be added here.

4.2 Install (Optional) is a Perl module that is optionally required by the Webmin package for secure data transmission between your browser and Webmin. It is strongly recommended that you install this module.

Install the Perl module as follows:

# cd

# perl Makefile.PL

# make test

# make install  


  1. During make test, you may get error messages saying that the test is not OK. This happens when testing against external sites. You can ignore the message and continue with make install.
  2. Other Perl modules may be required before you will be able to install Net_SSLeay, depending on the version of Perl installed on your system.

4.3 Install Webmin

Webmin is an excellent web-based administration tools package for various Unix systems. With the package installed, you can perform many system tasks such as user management, Samba and Apache configuration, etc. through a web browser.

Suppose that you have already unpacked the Webmin tarball, you can install the package using the following command:

# cd webmin-0.85

# ./

During installation, just accept all the defaults when prompted (except, of course, the administrator's username and password). Note that the installation script will automatically test to see if you have NET_SSLeay installed. If it finds it, it will install webmin with secure transaction.

If you use the default port number for Webmin installation with secure connection support, you can access your Webmin installation using:


Without encryption, you will use http:// instead.

Don't forget to restrict access privileges to the IPs that you use. To do this, use the Webmin Configuration module and set up restricted IP address(es). You can do this after everything is installed.

(To uninstall Webmin, find the script and run it. If you accept the default settings during installation, the script is located in the /etc/webmin/ folder.)

4.4 Install MySQL

Installing MySQL involves four steps:

  1. Create both a user and group account (for running MySQL in a sandbox);
  2. Configure, compile and install MySQL;
  3. Run a few post-installation routines; and
  4. Set up relevant system init scripts so that MySQL will be automatically started or shutdown during system reboot.

4.4.1 Create a user and group account

We will create a user account called mysql and a group account mysql. Again, the account is to be used for running MySQL in a sandbox. The following applies to FreeBSD:

# pw groupadd mysql 

# pw useradd mysql -g mysql -d /usr/local/mysql -s /nonexistent

The pw command is for FreeBSD system only. If you are using other Unix systems, please use the corresponding commands on your system. Alternatively, you can use Webmin to add the mysql group and username.

Remember to disable the shell login for the mysql user!

4.4.2 Compile and install the software

We will install everything under the /usr/local/mysql folder

# cd mysql-3.23.38

# ./configure --prefix=/usr/local/mysql 

# make

# make install


  1. the option --prefix=/usr/local/mysql will get all MySQL files installed under that particular folder. Another common option is to use --prefix=/usr/local. Either option will work but the former is my personal preference. As far as I can see, the advantage of using the former is that when you want to uninstall the package, you just trash the entire /usr/local/mysql folder without worrying about accidentally deleting other system files.

4.4.3 Run MySQL for the first time

After MySQL is installed, run the following commands only ONCE:

# /usr/local/mysql/bin/mysql_install_db

# chown -R mysql /usr/local/mysql 

# chgrp -R mysql /usr/local/mysql 

# /usr/local/mysql/bin/safe_mysqld --user=mysql &

# /usr/local/mysql/bin/mysqladmin -u root password newpassword

where newpassword is the password you choose for the root.

4.4.4 Start MySQL after system reboot

This step is to link MySQL initiating script with system initiating process so that it will be restarted after each system reboot.

There is a file called mysql.server within your unpacked mysql-3.23.38/support-files folder.

On FreeBSD

Copy the same mysql-3.23.38/support-files/mysql.server file into, for example, the /etc folder and make it executable.

# cp mysql.server /etc/

# chmod 755 /etc/mysql.server

Add the following line into the /etc/rc.local file. If there is no rc.local file, create one yourself (and make it executable).

/etc/mysql.server start

Add the following line into the /etc/rc.shutdown file:

/etc/mysql.server stop

Change one line in the mysql.server script: Locate the following line (Line 107or nearby)

$bindir/safe_mysqld --datadir=$datadir --pid-file=$pid_file &

and add the --user=mysql option. After modification, the line should look like the following:

$bindir/safe_mysqld --user=mysql --datadir=$datadir --pid-file=$pid_file &

On a Linux box

Copy the mysql-3.23.38/support-files/mysql.server file into the /etc/rc.d/init.d/ folder and create a softlink in the /etc/rc.d/rc3.d folder. e.g.

# ln -s /etc/rc.d/init.d/mysql.server /etc/rc.d/rc3.d/S91mysql

We need to make mysql.server excutable so that it will be fired up when the system reboots:

# chmod a+x /etc/rc.d/init.d/mysql.server

Again, you need to modify the mysql.server script to include the --user=mysql option as per instruction in the FreeBSD subsection above.

4.4.5 Secure MySQL

It is strongly suggested that you read the following document about securing your MySQL server after you install everything covered in this tutorial:

In particular, read this page to find out how MySQL privilege system works.

If you are impatient :-), here is a minimal configuration to get things started (All the operations are done to the mysql database (which is automatically set up when you run the install_db command mentioned above. You can use the phpMyAdmin tool to be installed later at this tutorial.):

  1. Create a new database (e.g., mydb);
  2. In the user table, add localhost to the host field; add a username (e.g., foo) and password mysecret. All the privileges should remain unchanged, i.e., set to 'N'. Note that foo is not a Shell user!
  3. In the db table, add localhost to the host field; add the username (foo) you just created to the user field; add the new database name (e.g., mydb) to the db field; set the permissions for 'select, insert, update and delete' to 'Y'.

This will allow foo to access the database mydb with the select, insert, update and delete privileges from the localhost.

4.5 Install Apache (with mod_ssl as an optional module)

PHP can be built into Apache in two modes: 1) Statically linked; 2) Dynamically linked. In this tutorial, we build dynamically linked PHP modules. If you are not clear about the difference between 'statically' and 'dynamically' linked installation, it is suggested that you follow the instructions provided here. Otherwise, please take a look at the older version of this tutorial for building PHP as a static module (Note that the older version is no longer updated).

Installing Apache and PHP involves six steps in the following order:

  1. Install MM (shared memory);
  2. Install Apache;
  3. Install PHP4 and optionally PHP3;
  4. Configure Apache for running PHP;
  5. Create and link system init scripts;
  6. Manually fire up Apache;
  7. Test your installation.

4.5.1 Compile the MM Shared Memory Library

# cd mm-1.1.3/

# ./configure --disable-shared

# make

# make test

# cd ..

4.5.2 Configure mod_ssl

We will just run the configure command below (but NOT make).

# cd mod_ssl-2.8.4-1.3.20

# ./configure --with-apache=../apache_1.3.20

# cd ..


Please ignore the following message that will occur after you run the above configure command:

Now proceed with the following commands (Bourne-Shell syntax): 
$ cd ../apache_1.3.20 

$ SSL_BASE=/path/to/openssl ./configure ... --enable-module=ssl 

$ make 

$ make certificate 

$ make install

We will take care of making certificate when compiling and installing the apache server.

4.5.3 Compile and install Apache

We will install apache under the /usr/local/apache folder. Modify the --prefix= option if you want to install it elsewhere.

Suppose that both Apache and other packages (e.g., mod_ssl, mm, etc.) are untarred under the same parent folder. The installation commands are listed below. Read the notes below for some explanation before running them.

# cd apache_1.3.20

# SSL_BASE=../openssl-0.9.6 \

  EAPI_MM=../mm-1.1.3 \

  ./configure \

  --prefix=/usr/local/apache \

  --enable-module=ssl \

  --enable-module=so \

  --enable-module=log_agent \

  --enable-module=log_referer \

  --enable-module=proxy \

  --enable-module=rewrite \

  --enable-module=speling \

  --enable-module=usertrack \


# make

# make certificate TYPE=dummy

# make install


  1. There are many --enable-module= options there. I find them very useful for myself.
  2. If you optionally installed openssl-0.9.6a following the instruction earlier this tutorial, you can specify the location as SSL_BASE=../openssl-0.9.6a \ in the corresponding line above. Otherwise, omit this option.
  3. If you do not want to install mod_ssl, get rid of that option. You can take a look at for all available modules. The command

        ./configure --help

    will give you a list of all the core modules available.
  4. It is more efficient and less prone to typos if you create a text file with all the configure options in it and execute that file. For example, your text file can contain the following content (Modify it to meet your own needs):
SSL_BASE=../openssl-0.9.6 \

EAPI_MM=../mm-1.1.3 \

./configure \

     --prefix=/usr/local/apache \

     --enable-module=ssl \

     --enable-module=so \

     --enable-module=log_agent \

     --enable-module=log_referer \

     --enable-module=proxy \

     --enable-module=rewrite \

     --enable-module=speling \

     --enable-module=usertrack \


Suppose you edit the file and save it as You can issue the following command at the shell prompt:

# chmod +x

# ./

4.5.4 Create a login name for basic user authentication

By default, all the files and folder under the web root folder is viewable by everyone. If you need to restrict access to a certain web folder (which is the case for running phpMyAdmin), you need to create a login name for authentication. Note that this login name is different from (Shell) user accounts on your Unix box. You can choose any login name.

The following command will create a login name mynewuser which can be used for authentication to access a protected folder.

# /usr/local/apache/bin/htpasswd -c /home/www/userdb/userfile mynewuser

where /home/www/userdb is the folder which contains the file userfile which in turn contains the username mynewuser. With the option -c, a new userfile will be created. Otherwise the userfile will be updated (when, for example, you want to add a new user to the existing userfile or change the password associated with the username).

4.5.5 Set up a password protected folder

Suppose the folder /home/www/securefoldername needs to be protected. Only an authenticated user (which requires login with both a username and password) from a certain IP address (in our example, the 192.168 subnet or with the domain name can access it. In the /usr/local/apache/conf/httpd.conf file, add the following:

<Directory "/home/www/securefoldername">

AllowOverride AuthConfig


AuthType Basic

AuthUserFile /home/www/userdb/userfile

Order deny,allow

Deny from all

Allow from 192.168.


Note that MYCOMMUNITY is an arbitrary string I choose. You can use a different string as long as you keep it consistent in the following .htaccess file. If you do not want IP address restriction (so that you can access the folder from anywhere, simply comment out the three lines in bold.

In the /home/www/securefoldername folder, create the .htaccess file (don't forget  about the leading dot (.) in front of htaccess) which contains the following lines:


AuthType Basic

AuthUserFile /home/www/userdb/userfile

AuthGroupFile /dev/null

Require user mynewuser

The /home/www/securefoldername will now be protected with basic authentication (i.e., username/password are passed along in clear text). Only the username mynewuser from a computer whose IP address is in the 192.168 subnet or whose IP address can be mapped onto the domain will be able to view pages hosted within that folder. We will use this folder to install the phpMyAdmin files later.

4.5.6 Modifying system init file

To manually start Apache

# /usr/local/apache/bin/apachectl start

To start apache in secure mode:

# /usr/local/apache/bin/apachectl startssl

To automatically start Apache at system reboot, do the following:


The /etc/rc.d/rc.local file can be modified so that Apache will be fired at system reboot. Add the following line at the very end of the file:

/usr/local/apache/bin/apachectl start


Add the following line to the /etc/rc.local file (after the line that initiates MySQL (which we added earlier)):

/usr/local/apache/bin/apachectl start

Add the following line to the /etc/rc.shutdown file (before the line that shuts down MySQL (which we added earlier)):

/usr/local/apache/bin/apachectl stop

4.6 Install PHP (with ZendOptimizer as an option)

We are going to compile both PHP3 and PHP4 as two different dynamically linked modules in Apache. If you don't want PHP3, you can simply compile and install PHP4 alone.

4.6.1 Compile and install PHP

First, we compile and install PHP4.

# cd ../php-4.0.5

# EAPI_MM=../mm-1.1.3 \

  ./configure --with-apxs=/usr/local/apache/bin/apxs \

  --enable-versioning --with-mysql=/usr/local/mysql --enable-track-vars

# make

# make install

# cp php.ini-dist /usr/local/lib/php.ini

Next, we compile and install PHP3. This is OPTIONAL!

# cd ../php-3.0.17

# EAPI_MM=../mm-1.1.3 \

  ./configure --with-apxs=/usr/local/apache/bin/apxs \

	--enable-versioning --with-mysql=/usr/local/mysql --enable-track-vars

# make

# make install

# cp php3.ini-dist /usr/local/lib/php3.ini

Again, if the configure command has too many options, simply create a text file, put everything in it and execute it.

Note that there is an optimized php.ini file called php.ini-optimized. Please read the documentation about the differences between the two php.ini files. If you want to be on the safe side, use the generic php.ini-dist file.

4.6.2 Optional: Installing Zend Optimizer

Installing Zend Optimizer is optional. The following is copied from the UserGuide.pdf of Zend Optimizer:

Under UNIX:

  1. Compile PHP 4.0 in non-debug mode - or else the Zend Optimizer won't load. As of 4.0.1, this is the default, no special configure option is required.
  2. Copy the file to your system; a good place to put it is in the /usr/local/Zend/lib directory.
  3. Add the following two lines to your php.ini file; do not add any extra spaces or tabs:


  4. Restart your Apache web server; for recent Apache 1.3.* versions use the command apachectl restart.

4.6.3 Configure Apache to enable PHP scripting

This is done by modifying the /usr/local/apache/conf/httpd.conf file and make sure the following line is present exactly as below (What you need to do is to uncomment (i.e., delete the # sign at the beginning of) the two lines in the default httpd.conf file):

# (If you installed PHP3, include the following two lines:)
AddType application/x-httpd-php3 .php3 AddType application/x-httpd-php3-source .phps
AddType application/x-httpd-php .php

AddType application/x-httpd-php-source .phps

IMPORTANT: Before you restart Apache, run the following command to test your new configuration:

# /usr/local/apache/bin/apachectl configtest

If you receive an error message saying something like the following:

Syntax error on line 205 of /usr/local/apache/conf/httpd.conf: Cannot
load /usr/local/apache/libexec/ into server: Shared object "lib" not found

you need to create some soft links in your /usr/lib folder. (FYI: The error occurs when the system cannot find the expected module library in its path. Setting up a soft link is perhaps an easiest way of getting around the problem.)

# ln -s /usr/local/mysql/lib/mysql/ /usr/lib/

Now repeat the apachectl configtest command till you find no syntax error.

Now you can restart Apache to let the changes taking effect. Run this command:

# /usr/local/apache/bin/apachectl restart

4.6.4 Test your new server configuration

You can test all the configurations by creating a file (name it info.php, for example) and place it under the root directory of your web server. (If you haven't modified the DocumentRoot option in the httpd.conf file, the web server root is at /usr/local/apache/htdocs folder.) The file should just contains one line:

<?php phpinfo(); ?>

Run the script through a web browser and you should see a list of web server configuration parameters you have just set up.

Rename the file you just created as info.php3. Run it through your web browser. This will display your PHP3 installation parameters.

At this time, you can optionally reboot your machine to make sure that the two servers (MySQL and Apache) are fired up at system reboot.

4.7 Optional: Install phpMyAdmin for MySQL administration

phpMyAdmin is optional, though I find it quite handy when administering MySQL server.

Untar the phpMyAdmin file in a protected folder such as the one we just created above. It is suggested that you password protect the folder and implement IP access restriction at the same time (See relevant instrutions above).

Modify the file to add the root password of your MySQL server.

Remove the READ ('r') permission bit of this particular folder which contains the phpMyAdmin scripts. To do this, you can simply use the following command:

% cd phpMyAdminfolder

% chmod go-r .

This will prevent those users with shell login privileges to read your MySQL root passport through Shell (e.g., via telnet) access.

Now you can administer your MySQL database from a web browser.

Let us create our first database for use with the following PHPLIB installation.

  1. Create a database. It's easy with phpMyAdmin's web interface.
  2. Create a user in the mysql database by adding a user to the user table.
    E.g., username=mydbuser, password=secret, host=localhost.
    There is no need to change any permissions in that table. That is, leave anything else to N.
  3. Add the user info to the db table of the mysql database and change permissions for select, insert, delete and update to Y. Leave other permissions untouched.

You need to consult the MySQL manual for further information about its privilege systems, etc.. The latest Webmin (0.85) also has support to MySQL administration. Reload MySQL from the phpMyAdmin top page.

4.8 Optional: Install PHPLIB

Installing PHPLIB is optional but recommended if you are serious about PHP scripting. PHPLIB is an excellent library that will enable you to code in PHP more efficiently and cleanly.

Note that PHPLIB was developed for PHP3 and there may be some incompatibility issues involved with PHP4.

To install the library, do the following:

4.8.1 Uncompress the source code

Uncompress the downloaded tarball (phplib-7.2c.tar.gz) into a folder parallel to your web server's document root. For example, if your web root is at /home/www/docroot, you uncompress the phplib-7.2c.tar.gz file in the /home/www folder.

After uncompressing, you will find a new folder named phplib-7.2c, which further contains a subfolder called php. This is where the library code is.

4.8.2 Modify the PHP init file

Edit the /usr/local/lib/php.ini file (or the php3.ini file if you have PHP3 installed) by adding the following two lines:

include = "/path/to/the/php"

auto_prepend_file =  "/path/to/prepend.php3"

4.8.3 Create a container database for PHPLIB to use

Now we need to create a database for PHPLIB to use. Add the appropriate entries in MySQL:

Host: localhost

Database: mydb

Username: mydbuser

Password: secrete

where mydb is the database and mydbuser/secrete the username/password pair to be used by PHPLIB.

4.8.4 Add the database/username/password information to the file

First, modify the DB_Example lines in the file to add the above information.

Then, run the following command:

$ /usr/local/mysql/bin/mysql -h localhost -u root -p mydb < /whateverpath/phplib-7.2c/stuff/create_database.mysql

Now you should be able to use the PHPLIB for your coding. Check out this sample code page to see how to connect to a database with or without PHPLIB support.

PHPLIB can be customized for each virtual web server that is running on your unix box. If you need information or help with configuration, please contact me.

4.8.5 Upgrading PHP3 to PHP4 when PHPLIB is already being used

There will be an error when running sessions. You need to modify two lines in the file in the 7.2c distribution. The detailed instruction can be found from (Local copy is here.)

4.9 Optional: Install mod_gzip

mod_gzip ( is an apache module that compresses HTML source codes on the fly, even including dynamically generated data such as those from PHP script output. It saves bandwidth!

In fact, you can customize your PHP 4 installation by enabling its built-in compression function (c.f., the zlib compression directive in the /usr/local/lib/php.ini file). However, I'd suggest that you use mod_gzip instead, which compresses static pages (e.g., .html) as well.

Before you install the module, it is suggested that you visit its website, especially the FAQ section!

The installtion instruction below is taken directly from the module's website. To install:

4.9.1 Download the source code

Download the source code (Current version: from and save it as mod_gzip.c in, for example, the /usr/src/local folder.

4.9.2 Compile it as Apache module

Run the apxs command to compile and install it as a dynamically linked module:

# /usr/local/apache/bin/apxs -i -a -c /usr/src/local/mod_gzip.c 

4.9.3 Modify Apache runtime configuration file

Modify the httpd.conf file by adding the following (by Michael Suszycki (02/21/01), copied directly from

<IfModule mod_gzip.c>

mod_gzip_on yes

mod_gzip_dechunk yes

mod_gzip_keep_workfiles No

mod_gzip_temp_dir /tmp

mod_gzip_minimum_file_size 1002

mod_gzip_maximum_file_size 0

mod_gzip_maximum_inmem_size 1000000
mod_gzip_item_include file \.htm$

mod_gzip_item_include file \.html$

mod_gzip_item_include mime text/.*

mod_gzip_item_include file \.php$

mod_gzip_item_include mime "jserv-servlet"

mod_gzip_item_include handler "jserv-servlet"

mod_gzip_item_include mime "application/x-httpd-php.*"

mod_gzip_item_include mime httpd/unix-directory
mod_gzip_item_exclude file "\.css$"

mod_gzip_item_exclude file "\.js$"

mod_gzip_item_exclude file "\.wml$"

LogFormat "%h %l %u %t \"%V %r\" %>s %b \                        

mod_gzip:%{mod_gzip_result}n In:%{mod_gzip_input_size}n \         

Out:%{mod_gzip_output_size}n:%{mod_gzip_compression_ratio}npct." \


CustomLog /usr/local/apache/logs/mod_gzip common_with_mod_gzip_info2



  1. The four lines in RED (starting with LogFormat ...) should be in one line. Get rid of the trailing backslashes (\) when you restore them into one line. I break it up into four just for the same of displaying it properly on a web browser.
  2. Pay attention to the CustomLog line: Our logs are saved in /usr/local/apache/logs folder. Modify the location to fit your system settings!

4.9.4 Test and run!

Test the new apache configuration:

# /usr/local/apache/bin/apachectl configtest

and if there is no error, restart the apache server:

# /usr/local/apache/bin/apachectl restart

To find out how much bandwidth has been saved, you can use the 'mgstat' tool!

4.10 Optional: Install DBI and Msql-Mysql

Sometimes you will find it more convinient to manipulate MySQL databases using Perl. To do that, you need both the DBI and Msql-Mysql modules installed. Those modules can be downloaded from or

Installing Perl mdules uses the following standard procedure:

# cd /path/to/perl-module
# perl Makefile.PL # make # make test # make install

You can ignore the error message about using proxy servers when installing the DBI module. You will unlikely need this feature if you only use Perl script to interface with the MySQL database on a localhost.

Another way of installing Perl modules is like this: Become the superuser first and then:

# perl -MCPAN -e shell

Very often it is more convinient to use this method.

5 After installation

Sit back and take a break! You've done a great job within a very short period of time.

Two pieces of simple SAMPLE CODES can be found here to get started!

If you want to learn SQL in general, read this very informative tutorial. Tutorials on PHP scripting can be found by following links provided on the official PHP website (e.g., and PHPLIB also simplifies quite a few things.

Finally, the two must-haves are:

  1. MySQL Reference Manual;
  2. PHP Manual.

6. Disclaimer

The standard disclaimer applies :-)

  1. This tutorial is provided as it is. Use it at your own risk! The author is not responsible for any explicit or implicit damages of whatever kinds. 
  2. Please check your local laws concerning installing security software packages such as OpenSSL/mod_ssl on your system. The author of this tutorial does not assume any responsibility (whether stated or implied) of any kinds concerning the use of those software applications.

If you have any questions concerning this tutorial, feel free to use the online form or email me at