Table of Contents
- 1. Install apache2
- 2. Enable userdir module
- 3. Create ~/public_html directory
- 4. Digest authentication
- 5. CGI
1 Install apache2
Install apache2 with apt.
$ sudo apt-get install -y apache2
2 Enable userdir module
Enable userdir module with a2enmod.
$ sudo a2enmod userdir$ sudo systemctl restart apache2
3 Create ~/public_html directory
$ 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>
A index.html or index.cgi will be loaded by DirectoryIndex when accessing to URL.
I have created below index.html written by Japanese with emacs org-mode.
4 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 DigestAuthName “hiroom2″AuthUserFile /home/hiroom2/.htdigestrequire valid-user
Add user to accessing to realm “hiroom2” with htdigest.
$ htdigest -c ~/.htdigest “hiroom2” hiroom2Adding password for hiroom2 in realm hiroom2.New password:Re-type new password:
Username and password is required when accessing to URL.
5 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 userdir.conf.
$ diff -uprN /etc/apache2/mods-available/userdir.conf{.org,}— /etc/apache2/mods-available/userdir.conf.org 2016-05-11 07:22:10.861339651 +0900+++ /etc/apache2/mods-available/userdir.conf 2016-05-11 08:45:45.955093386 +0900@@ -4,7 +4,7 @@ <Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Indexes- Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec+ Options ExecCGI MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Require all granted </Limit>
Enable cgi module with a2enmod.
$ sudo a2enmod cgi$ sudo systemctl restart apache2
Create public_html/.htaccess as below.
AddHandler cgi-script .cgi
This article created public_html/index.cgi as below and ran “chmod a+x public_html/index.cgi”.
#!/bin/shecho “Content-type: text/html”echo “”echo “hello”
Accessing to URL returned HTML generated by index.cgi.