OpenSUSE 13: Install apache2 userdir and run web server for each user

This article will describe installing apache2 userdir and running web server for each user.

1 Install apache2

Install apache2.

> sudo zypper -n in apache2
> sudo systemctl enable apache2
> sudo systemctl start apache2

2 Enable userdir module

mod_userdir is enabled by default on OpenSUSE 13. If not enabled, enable userdir module with a2enmod.

$ sudo a2enmod userdir
$ sudo systemctl restart apache2

3 Open TCP port

Open TCP port with SuSEfirewall service file for apache2.

> firewall_open_service()
{
  for t in FW_CONFIGURATIONS_EXT FW_CONFIGURATIONS_DMZ FW_CONFIGURATIONS_INT; do
    sudo sed -e "s/^${t}=\"\(.*\)\"/${t}=\"\1 $1\"/g" \
         -i /etc/sysconfig/SuSEfirewall2
  done
  sudo systemctl restart SuSEfirewall2
}
> firewall_open_service apache2

4 Create ~/public_html directory

~/public_html is exists by default on OpenSUSE 13. If not exists, create ~/public_html.

$ mkdir ~/public_html

Now accessing to below URL returns below HTML. If you need to provide file downloader, you only put your file to public_html directory.

http://<server>/~<username>

0001_FileList.png

A index.html or index.cgi will be loaded by DirectoryIndex when accessing to URL.

I have created below index.html written with emacs org-mode.

0002_IndexHTML.png

5 Digest authentication

Enable auth_digest module with a2enmod.

$ sudo a2enmod auth_digest
$ sudo systemctl restart apache2

Create public_html/.htaccess as below. "hiroom2" is a realm for digest authentication.

AuthType Digest
AuthName "hiroom2"
AuthUserFile /home/hiroom2/.htdigest
require valid-user

Add user to accessing to realm "hiroom2" with htdigest2.

$ htdigest2 -c ~/.htdigest "hiroom2" hiroom2
Adding password for hiroom2 in realm hiroom2.
New password:
Re-type new password:

Username and password is required when accessing to URL.

0003_Password.png

6 CGI

A userdir module does not allow ExecCGI by default. It may be better to use container like LXC for ExecCGI.

Add ExecCGI to Options in mod_userdir.conf.

> sudo sed -e 's/\( *\)Options \(.*\)/\1Options ExecCGI \2/g' \
           -i /etc/apache2/mod_userdir.conf

Enable cgi module with a2enmod.

$ sudo a2enmod cgi
$ sudo systemctl restart apache2

Create public_html/.htaccess as below.

AddHandler cgi-script .cgi
DirectoryIndex index.cgi

This article created public_html/index.cgi as below and ran "chmod a+x public_html/index.cgi".

#!/bin/sh

echo "Content-type: text/html"
echo ""

echo "<pre>"
free -m
echo "</pre>"

echo "<pre>"
w
echo "</pre>"

Accessing to URL returned HTML generated by index.cgi.

0004_IndexCGI.png