See setup and config file in ahapache.
NOTE: OLD, OUT OF DATE INFO
This works as of Dec 29, 2011 with Apache 2.2 as installed via Ubuntu 11.10 server.
Do this to setup apache2 after installing apache2 on Ubuntu or Debian.
mkdir -p /home/acorn/bcorn.com/www
<html><body><h1>My server works!</h1></body></html>
mkdir -p ~/public_html/cgi-bin chmod 755 ~/public_html ~/public_html/cgi-bin
<html><body><h1>Acorn's personal page.!</h1></body></html>
ServerName bcorn.com
ServerName bcorn.com
DocumentRoot /home/acorn/bcorn.com/www
<Directory "/home/acorn/bcorn.com/www"> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory>
# run cgi scripts in /usr/lib/cgi-bin/... as user=nobody group=nogroup SuexecUserGroup nobody nogroup # look for user webpages in ~/public_html/... <IfModule userdir> UserDir public_html </IfModule> # options for user webpages <Directory /home/*/public_html> Options FollowSymLinks Indexes MultiViews AllowOverride None Order deny,allow allow from all </Directory> # options for user cgi scripts <Directory /home/*/public_html/cgi-bin> Options ExecCGI SetHandler cgi-script </Directory>
sudo apt-get install apache2-suexec
sudo a2enmod suexec sudo a2enmod userdir
apachectl configtest
sudo service apache2 restart
Anytime you change config files first check the change with
apachectl configtestThis checks the file syntax. If it reports "Syntax OK" then restart the server with
sudo service apache2 restart
Apache default config file location is /etc/apache2/httpd.conf but Debian (and Ubuntu) do not use this. In Debian/Ubuntu the main config file is /etc/apache2/apache2.conf and this file includes all the other config files. To see all config files that get included:
grep -r -a -i '^ *include' /etc/apache2
The file you should edit is
suvw /etc/apache2/sites-available/defaultwhich configures the default virtual host.
You can enable modules with
sudo a2enmod <module-name>This creates symlinks in /etc/apache2/mods-enabled dir.
(Note: see next section too)
AuthType Basic AuthName "Acorn's Private Stuff" AuthUserFile <pwdfile> Require user <username>
AuthType Basic AuthName "Acorn's Private Stuff" AuthUserFile /home/acorn/Mine/web_password Require user acorn user joe user susan
AllowOverride AuthConfigThe word "All" can be used in place of "AuthConfig". This allows apache to read the local .htaccess files. Also, if a "AccessFileName" line exists it must be set to ".htaccess" like this:
AccessFileName .htaccessThere may be several AllowOverride statements in the file, each in a separate <Directory> section. The one in the <Directory> section corresponding to the directory where the .htaccess file is located is the one which must be set to "All" or "AuthConfig."
In place of the .htaccess file as described above the described-above contents of the .htaccess file may be placed directly into the main config file (/etc/httpd/conf/httpd.conf). The entire contents of the .htaccess file, as described above, should be placed in the main config file inside the markers <Directory "/path/to/my/dir"> and </Directory>, where /path/to/my/dir is the directory of the files in question (the full path of the directory where the .htaccess file would have been located). For example:
<Directory "/path/to/my/dir"> AuthType Basic AuthName "Acorn's Private Stuff" AuthUserFile /home/acorn/Mine/web_password Require user acorn user joe user susan </Directory>When using this method the .htaccess file should be removed, and the "AllowOverride" directive is not needed - it can be set to "None" like this:
AllowOverride NoneThis method is faster than using the .htaccess file when "AllowOverride" is "None" because apache does not need to read the .htaccess file each time.
sudo /etc/init.d/httpd restart
Look in /etc/apache2/sites-available/default for ScriptAlias line. Shows where to put the file.
Here is an example scriptalias that allows running scripts named /usr/lib/cgi-bin/myscript as http://localhost/cgi-bin/myscript
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory>
Sample cgi script. Put in /usr/lib/cgi-bin/mydate.
#!/bin/bash echo "Content-type: text/html" echo "" echo "<html><body>" echo "<h1>Today's date: `date`</h1>" echo "</body></html>"Be sure to
Sample cgi form. Put in /usr/lib/cgi-bin/myform.
#!/bin/bash echo 'Content-type: text/html' echo '' _from_form() { echo "$1" \ | sed \ -e 's|&|\&|g' \ -e 's|<|\<|g' \ -e 's|>|\>|g' \ -e 's|+| |g' \ -e 's|%09| |g' \ -e 's|%20| |g' \ -e 's|%21|!|g' \ -e 's|%22|"|g' \ -e 's|%23|#|g' \ -e 's|%24|$|g' \ -e 's|%26|\&|g' \ -e "s|%27|'|g" \ -e 's|%28|(|g' \ -e 's|%29|)|g' \ -e 's|%2[Aa]|*|g' \ -e 's|%2[Bb]|+|g' \ -e 's|%2[Cc]|,|g' \ -e 's|%2[Dd]|-|g' \ -e 's|%2[Ee]|.|g' \ -e 's|%2[Ff]|/|g' \ -e 's|%3[Aa]|:|g' \ -e 's|%3[Bb]|;|g' \ -e 's|%3[Cc]|\<|g' \ -e 's|%3[Dd]|=|g' \ -e 's|%3[Ee]|\>|g' \ -e 's|%3[Ff]|?|g' \ -e 's|%40|@|g' \ -e 's|%5[Bb]|[|g' \ -e 's|%5[Cc]|\\|g' \ -e 's|%5[Dd]|]|g' \ -e 's|%5[Ee]|^|g' \ -e 's|%5[Ff]|_|g' \ -e 's|%60|`|g' \ -e 's|%7[Bb]|{|g' \ -e 's@%7[Cc]@|@g' \ -e 's|%7[Dd]|}|g' \ -e 's|%7[Ee]|~|g' \ -e 's|%7[Ff]||g' \ -e 's|@|@a|g' \ -e 's|%25|@b|g' \ -e 's|%[0-9a-fA-F][0-9a-fA-F]||g' \ -e 's|%||g' \ -e 's|@b|%|g' \ -e 's|@a|@|g' \ -e 's|[^ -~]|?|g' } _escape() { sed \ -e 's|&|\&|g' \ -e 's|<|\<|g' \ -e 's|>|\>|g' \ -e 's|\t| |g' \ -e 's|[^ -~]|?|g' } _to_csv() { echo "$1" \ | sed \ -e 's|<|<|g' \ -e 's|>|>|g' \ -e 's|&|\&|g' \ -e 's|\\|\\\\|g' \ -e 's|"|\\"|g' \ -e 's|.*|"&"|g' } echo '<html><body>' echo '<form action="myform" method="post">' all='&'`cat`'&' fname=`echo "$all" | sed -n -e 's|.*&fname=\([^&]*\)&.*|\1|p'` lname=`echo "$all" | sed -n -e 's|.*&lname=\([^&]*\)&.*|\1|p'` fname=`_from_form "$fname"` lname=`_from_form "$lname"` fname_csv=`_to_csv "$fname"` lname_csv=`_to_csv "$lname"` if [[ -n "$fname" || -n "$lname" ]] ; then if [[ -n $fname && -n $lname ]] ; then echo "$fname_csv,$lname_csv" >> /tmp/mydata.csv echo "<p>Successfully added entry: fname=$fname lname=$lname</p>" echo "<p>Contents of /tmp/mydata.csv:" echo "<pre>" cat /tmp/mydata.csv | _escape echo "</pre>" else echo "Bad entry:<br/>" echo " fname='$fname'<br/>" echo " lname='$lname'<br/>" fi echo "<hr>" fi echo "First name: <input type="text" name="fname" /><br/>" echo "Last name: <input type="text" name="lname" /><br/>" echo "<input type="submit" value="Submit" />" echo '</form>' echo '</body></html>'Be sure to chmod a+x /usr/lib/cgi-bin/myform the script.