Red Antigua Logo
Yet another piece of web.
Ads by Goooooogle
Search this site (by Google)
Tools    (top)
Your IP
Check a site for broken links
(W3C)

Perl modules    (top)
Tree::Numbered::Tools
(CPAN)
Perl tutorials    (top)
Perl modules
HTML::Template
CGI::Application
Mail::POP3Client
Mail::Send
MIME::Tools
Cookies with CGI::Application
Upload files with CGI::Application
Download files with CGI::Application
Redirect with CGI::Application
CPAN shell
Install DBD::mysql from the CPAN shell
Perl trim function
Validate an IP with Perl
Run suid Perl scripts under Apache
Perl taint mode
Perl date functions with Date::Calc

In Spanish
Curso de Perl

C tutorials    (top)
C - Introduction
C - Absolute beginner's Emacs
C - Examples for beginners
C - Makefile examples
C - Autotools examples
Server configurations    (top)
DNS
Apache
Apache Authentication and Access Control
mod_perl on FreeBSD
MySQL
MySQL add account
phpMyAdmin
Squid
DHCP

UNIX on Windows    (top)
Apache setup on Windows
MySQL setup on Windows
PHP setup on Windows
Perl setup on Windows
Emacs setup on Windows
UnxUtils
PuTTY
WinSCP
GIMP on Windows
MinGW - gcc on Windows
MSYS - UNIX-styled shell on Windows
msysDTK - autotools on Windows
GDB for MinGW on Windows

Misc. FreeBSD/UNIX    (top)
CD and DVD creation on FreeBSD using 'k3b' on FreeBSD
'portupgrade' on FreeBSD
'ipf' on FreeBSD
'pf' on FreeBSD
'su' on FreeBSD
Mount an ISO image under FreeBSD
Load the correct sound driver under FreeBSD without knowing what sound card you are using
Simultaneous sound channels on FreeBSD
FreeBSD network stuff
DOS-to-UNIX file conversion
favicon.ico on UNIX
Emacs tips
Sendmail tips
GKrellm
Command Line Calculator
Save multimedia streams with 'mplayer'
xargs - solution to 'Argument list too long'
Process multiple images from the command line using 'ImageMagick'
Turn the system bell off under X Windows
Process each line in an input file from the command line (or in a shell script)
How to keep a program running in the background using 'nohup'
How to remove symbolic links in the current directory using 'find' and 'rm'
How to remove Emacs backup files in the current directory and all subdirectories using 'find' and 'rm'
How to execute .profile without logging in
Configure X to handle non-English characters
How to move /var to /usr/var

Redirect a web page    (top)
Redirect to another web page
Apache redirect
C redirect
Perl redirect
PHP redirect
HTML redirect
JavaScript redirect

Javascript    (top)
Trim function
Login form
Register form
Popup window

Virus list    (top)
Latest 10 viruses - Sophos

Off topic    (top)
Personal home links

Apache setup
Apache + mod_perl + mod_php installation and configuration
This tutorial describes how to setup Apache with DSO (Dynamic Shared Object) support, and how to add mod_perl and mod_php as DSOs.
It also describes how to configure Apache to be used for software development on the local host (configuration not recommended for a public server).

Install

On FreeBSD:
Use any port of your taste: http://www.freebsd.org/cgi/ports.cgi?query=apache&stype=name
For example Apache 2.2:
cd /usr/ports/www/apache22
make install clean
or:

Download Apache from www.apache.org, build it and install it (as root):
gunzip -c apache_X.X.XX.tar.gz|tar -xf -
cd apache_X.X.XX
./configure --prefix=/usr/local/apache --enable-rule=SHARED_CORE --enable-module=so
make
make install
Apache is built with DSO support, which means that we can install additional modules afterwards, without rebuilding Apache itself.

Install mod_perl from perl.apache.org this way:
gunzip -c mod_perl-X.XX.tar.gz|tar -xf -
cd mod_perl-X.XX
perl Makefile.PL \
USE_APXS=1 \
WITH_APXS=/usr/local/apache/bin/apxs \
EVERYTHING=1
make && make test && make install
Install mod_php from www.php.net this way:
(If you want PHP with MySQL-support, first install MySQL.)
gunzip -c php-4.X.X.tar.gz |tar -xf -
cd php-4.X.X
./configure --with-mysql=/usr/local --with-apxs=/usr/local/apache/bin/apxs
make && make install
Configure

As said in /usr/local/apache/conf/httpd.conf:
"If you use Apache strictly for local testing and development, you may use 127.0.0.1 as the server name."
As that is how we will use Apache, we set the directive in /usr/local/apache/conf/httpd.conf:
ServerName 127.0.0.1
I normally log in as user kuuse, and I prefer to edit my files in /home/kuuse.
If we want Apache to have write access to files in /home/kuuse, it must be run as user and group kuuse:
#User nobody
#Group nobody
User kuuse
Group kuuse
By default, only root has write access to DocumentRoot (/usr/local/apache/htdocs).
So let's move DocumentRoot inside /home/kuuse:
#DocumentRoot "/usr/local/apache/htdocs"
DocumentRoot "/home/kuuse/www"
and a bit further down in httpd.conf:
#<Directory "/usr/local/apache/htdocs">
<Directory "/home/kuuse/www">
We also have to change ScriptAlias. I use two different directories for this:

#ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
ScriptAlias /cgi-bin/ "/home/kuuse/www/cgi-bin/"
ScriptAlias /scgi-bin/ "/home/kuuse/www/scgi-bin/

and a bit further down (I want to symlink scripts sometimes):
#<Directory "/usr/local/apache/cgi-bin">
<Directory "/home/kuuse/www/cgi-bin">  
    AllowOverride None
    #Options None
    Options FollowSymlinks
    Order allow,deny
    Allow from all 
</Directory> 
<Directory "/home/kuuse/www/scgi-bin">  
    AllowOverride None
    #Options None
    Options FollowSymlinks
    Order allow,deny
    Allow from all
</Directory>
Finally, enable php scripts (add php3 extension to run old scripts):

<IfModule mod_dir.c>
    #DirectoryIndex index.html
    DirectoryIndex index.html index.php index.php3
</IfModule>

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

NOTE: This is not a secure configuration. So why didn't I install Apache with PREFIX=/home/kuuse? Well, the day I want to use my box as a public server, I just throw away this httpd.conf and configures a new one.

Run

Start Apache from the command line (as root):
$ /usr/local/apache/bin/apachectl start
/usr/local/apache/bin/apachectl start: httpd started
You should now be able to edit any CGI-script, let's say /home/kuuse/www/cgi-bin/my_script.pl, and run it as
$ opera http://www.redantigua.com/cgi-bin/my_script.pl


provided that you configured DNS as I did.

To start apache at boot and stop it at shutdown, create the script /usr/local/etc/rc.d/apache.sh as root:
#!/bin/sh
#
case $1 in
 start)
    /usr/local/apache/bin/apachectl start
    ;;
 stop)
    /usr/local/apache/bin/apachectl stop
    ;;
 *)
 echo "usage: $0 (start|stop)"
    ;;
esac


Virtual Hosts

To run various web sites on one server, you have to uncomment the NameVirtualHost option in httpd.conf, and then add as many sites as you want.
Note that when Virtual Hosts are enabled, the main Apache site configuration will be disabled.
Enable NameVirtualHost:
NameVirtualHost *
NameVirtualHost *:443
Configure the site www.redantigua.com:
<VirtualHost *>
    ServerName www.redantigua.com
    DocumentRoot /usr/local/apache/htdocs
    ScriptAlias /cgi-bin/ "/usr/local/apache/cgi-bin/"
    <Directory "/usr/local/apache/cgi-bin">
        AllowOverride None
        Options FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog /usr/local/apache/logs/error_log
    CustomLog /usr/local/apache/logs/access_log common
</VirtualHost>
Configure the site bengt.dennis.com:
<VirtualHost *>
    ServerName bengt.dennis.com
    DocumentRoot /usr/local/apache/bengt
    ScriptAlias /cgi-bin/ "/usr/local/apache/bengt-bin/"
    <Directory "/usr/local/apache/bengt-bin">
        AllowOverride None
        Options FollowSymLinks
        Order allow,deny
        Allow from all
    </Directory>
    ErrorLog /usr/local/apache/logs/bengt_log
    CustomLog /usr/local/apache/logs/bengt_log common
</VirtualHost>
Last modified: Thu Aug 23 15:07:32 Romance Daylight Time 2007