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).
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.
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 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:
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):
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
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>