User Tools

Site Tools


computers:web_server_configuration

This is an old revision of the document!


Web Server Configuration

Packages

To install Apache and PHP on Ubuntu:

sudo apt-get install apache2
sudo apt-get install php5 libapache2-mod-php5

Apache

To start/stop/restart the service:

sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop
sudo /etc/init.d/apache2 restart

Security

Directory Listing

The default settings allow listing of the directory content. To prevent this, modify /etc/apache2/sites-available/default from:

	<Directory /var/www/>
		Options Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>

to:

	<Directory /var/www/>
		Options -Indexes FollowSymLinks MultiViews
		AllowOverride None
		Order allow,deny
		allow from all
	</Directory>

i.e., add '-' to 'Indexes'

PHP

Info

To find out the uid and gid, execute the following script:

<?php
 
if(function_exists('posix_geteuid')){
    // use posix to get current uid and gid
    $uid   = posix_geteuid();
    $usr   = posix_getpwuid($uid);
    $user  = $usr['name'];
    $gid   = posix_getegid();
    $grp   = posix_getgrgid($gid);
    $group = $grp['name'];
}else{
    // try to create a file and read it's ids
    $tmp = tempnam ('/tmp', 'check');
    $uid = fileowner($tmp);
    $gid = filegroup($tmp);
 
    // try to run ls on it
    $out = `ls -l $tmp`;
    $lst = explode(' ',$out);
    $user  = $lst[2];
    $group = $lst[3];
    unlink($tmp);
}
 
echo "Your PHP process seems to run with the UID $uid ($user) and the GID $gid ($group)\n"; ?>

Under a standard installation, both the uid and the gid are www-data

Problems and Solutions

If the browser asks to download the php files (instead of parsing them), comment all lines from <IfModule mod_userdir.c> to the next </IfModule> in /etc/apache2/mods-available/php5.conf and restart apache2.

Dokuwiki Installation

Permissions

Make the permissions more restrictive for security reasons. Assuming the wiki is installed in /var/www/wiki

# change the ownership
sudo chown -R www-data:admin /var/www/wiki
# restrict access by other
sudo chmod -R o-rwx /var/www/wiki
computers/web_server_configuration.1290739025.txt.gz · Last modified: 2010/11/26 10:37 by chkuo