Apache notes

From raju

Configure Apache so users can set up their own websites

Set of packages I have installed are

rajulocal@hogwarts:~$ dpkg -l \*apache\* | grep ^ii
ii  apache2                   2.4.10-6        amd64        Apache HTTP Server
ii  apache2-bin               2.4.10-6        amd64        Apache HTTP Server (modules and other binary files)
ii  apache2-data              2.4.10-6        all          Apache HTTP Server (common files)
ii  apache2-utils             2.4.10-6        amd64        Apache HTTP Server (utility programs for web servers)
ii  libapache-poi-java        3.10-1          all          Apache POI - Java API for Microsoft Documents
ii  libapache-pom-java        10-2            all          Maven metadata for all Apache Software projects
ii  libapache2-mod-perl2-doc  2.0.9~1624218-2 all          Integration of perl with the Apache2 web server - documentation

Enable the userdir module and restart the web server

root@hogwarts:~# a2enmod userdir
Enabling module userdir.
To activate the new configuration, you need to run:
  service apache2 restart
root@hogwarts:~# service apache2 restart
[ ok ] Restarting web server: apache2.

I did not have to change default configuration. For reference, here is the default userdir module configuration.

root@hogwarts:~# cat /etc/apache2/mods-enabled/userdir.conf 
<IfModule mod_userdir.c>
        UserDir public_html
        UserDir disabled root

        <Directory /home/*/public_html>
                AllowOverride FileInfo AuthConfig Limit Indexes
                Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
                <Limit GET POST OPTIONS>
                        Require all granted
                </Limit>
                <LimitExcept GET POST OPTIONS>
                        Require all denied
                </LimitExcept>
        </Directory>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Create the public_html directory under the user account.

rajulocal@hogwarts:~$ mkdir public_html

change the group owner to www-data and restart the web server. You need to be root to do both of this.

root@hogwarts:~# chgrp www-data /home/rajulocal/public_html/
root@hogwarts:~# service apache2 restart
[ ok ] Restarting web server: apache2.

Any content under /home/rajulocal/public_html/ can now be viewed under http://localhost/~rajulocal

rajulocal@hogwarts:~$ cp /var/www/html/index.html public_html/

Which can be viewed as http://localhost/~rajulocal/index.html or simply http://localhost/~rajulocal

Ref:- https://wiki.debian.org/LaMp

Debian Apache mod_perl configuration

Here are the packages I have installed

root@hogwarts:/etc/apache2/mods-enabled# dpkg -l \*mod-perl\* | grep ^ii
ii  libapache2-mod-perl2     2.0.9~1624218-2 amd64        Integration of perl with the Apache2 web server
ii  libapache2-mod-perl2-doc 2.0.9~1624218-2 all          Integration of perl with the Apache2 web server - documentation

Debian supplies the perl.load file which looks like the following

root@hogwarts:/etc/apache2/mods-enabled# cat perl.load
LoadModule perl_module /usr/lib/apache2/modules/mod_perl.so

However, unlike other modules (ex:- userdir), it does not supply the .conf file. Here is my configuration file

root@hogwarts:/etc/apache2/mods-enabled# ls -al perl.conf 
-rw-r--r-- 1 root root 308 Nov 17 00:19 perl.conf

root@hogwarts:/etc/apache2/mods-enabled# cat perl.conf
<IfModule mod_perl.c>
        Alias /perl/ /home/rajulocal/public_html/perl/
        <Location /perl>
                SetHandler perl-script
                PerlResponseHandler ModPerl::Registry
                PerlOptions +ParseHeaders
                Options +ExecCGI
                Order allow,deny
                Allow from all 
        </Location>
</IfModule>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

To understand the meaning of various directives (ex:- Alias, Location) see http://perl.apache.org/docs/1.0/guide/config.html and also http://perl.apache.org/docs/2.0/user/config/config.html .

After adding the configuration file, I did

root@hogwarts:/etc/apache2/mods-enabled# a2dismod perl
Module perl disabled.
To activate the new configuration, you need to run:
  service apache2 restart
root@hogwarts:/etc/apache2/mods-enabled# service apache2 restart
[ ok ] Restarting web server: apache2.
root@hogwarts:/etc/apache2/mods-enabled# a2enmod perl
Enabling module perl.
To activate the new configuration, you need to run:
  service apache2 restart
root@hogwarts:/etc/apache2/mods-enabled# service apache2 restart
[ ok ] Restarting web server: apache2.

to make it effective.

To test it, create a simple perl script in the directory pointed by the Alias directive in the perl.conf file.

rajulocal@hogwarts:~/public_html/perl$ ls -al mod_perl_rules1.pl 
-rwxr-xr-x 1 rajulocal rajulocal 82 Nov 17 01:11 mod_perl_rules1.pl

rajulocal@hogwarts:~/public_html/perl$ cat mod_perl_rules1.pl 
#! /usr/bin/perl
print "Content-type: text/plain\n\n";
print "mod_perl rules!\n";

rajulocal@hogwarts:~/public_html/perl$ ./mod_perl_rules1.pl 
Content-type: text/plain

mod_perl rules!

Now point the web browser to http://localhost/perl/mod_perl_rules1.pl which should print

mod_perl rules!

Notice that pointing the web browser to http://localhost/perl/mod_perl_rules1.pl will execute the script while pointing it to http://localhost/~rajulocal/perl/mod_perl_rules1.pl will launch a file-dialog box (at least in iceweasel). The change in the URI is due to the Alias directive in perl.conf file.

More details of my system

rajulocal@hogwarts:~/public_html/perl$ dpkg -l \*iceweasel\* | grep ^ii | grep -v l10n
ii  iceweasel                   31.2.0esr-2~deb7u1   amd64        Web browser based on Firefox
ii  iceweasel-dbg               31.2.0esr-2~deb7u1   amd64        Debugging symbols for Iceweasel

rajulocal@hogwarts:~/public_html/perl$ dpkg -l \*apache\* | grep ^ii
ii  apache2                   2.4.10-6        amd64        Apache HTTP Server
ii  apache2-bin               2.4.10-6        amd64        Apache HTTP Server (modules and other binary files)
ii  apache2-data              2.4.10-6        all          Apache HTTP Server (common files)
ii  apache2-doc               2.4.10-7        all          Apache HTTP Server (on-site documentation)
ii  apache2-utils             2.4.10-6        amd64        Apache HTTP Server (utility programs for web servers)
ii  libapache-poi-java        3.10-1          all          Apache POI - Java API for Microsoft Documents
ii  libapache-pom-java        10-2            all          Maven metadata for all Apache Software projects
ii  libapache2-mod-perl2      2.0.9~1624218-2 amd64        Integration of perl with the Apache2 web server
ii  libapache2-mod-perl2-doc  2.0.9~1624218-2 all          Integration of perl with the Apache2 web server - documentation
ii  libapache2-reload-perl    0.12-3          all          module for reloading Perl modules when changed on disk

Ref:-