Archive for March, 2010

Commonly Used File Permissions

We need to use file permissions on servers, see? it’s good, hmmkay?

This page on wikipedia treats the subject in marvelous detail, but here’s a quick reference to the levels of permissions:

Quick Reference

Octal Symbolic English
0 no permission
1 –x execute
2 -w- write
3 -wx write and execute
4 r– read
5 r-x read and execute
6 rw- read and write
7 rwx read write and execute

Commands

To query file permissions, ls -l gives you the symbolic notation.

To set file permissions, use the chmod command. ” chmod -R 755 * ” for example, sets all children of the current location to world readable and executable.

Commonly Used Permissions

OK, now, the main point of this post is to document some of the commonly used combinations. Note that in all examples below, we’re setting the last two digits the same. This is because we’re only really designing for two users: us and them. We want us to have high permissions, and only give the minimum of permissions to them.

Octal Symbolic English
000 ———- no permissions
777 -rwxrwxrwx all permissions – careful!
755 -rwxr-xr-x read and execute – necessary for scripts on a webserver
644 -rw-r–r– read only – fine for non-executable static content – images and html files.
666 -rw-rw-rw- read and write, but no execute – good for if a web page needs to modify its own configuration files, but they don’t need to be executed

Commands

World Writable 777

chmod -R 777 *

Everyone can write. Some scripts may require these settings while installing themselves.

See Also

https://help.ubuntu.com/community/FilePermissions

Tags: , , , ,

Setting up VirtualHosts in Apache2 on uBuntu (in brief)

The detailed guide on how to go this can be found here.

This post is a quick reference guide that you’ll mostly find useful if you’ve done it before.

First create the folders to put your files in:

cd /home/www
mkdir mysite.net
mkdir mysite.net/htdocs
mkdir mysite.net/cgi-bin
mkdir mysite.net/logs

Then set the appropriate permissions on the folders

chmod -R 755 mysite.net/htdocs

The apache configuration files are located in /etc/apache2/sites-available, so locate a suitable config file to start from in that folder, make a copy of it, and edit it appropriately.

Your finished config file might look something like this:


# This configuration file is for mysite.net
<VirtualHost *>
 ServerAdmin webmaster@mysite.net
 ServerNameĀ  www.mysite.net
 ServerAlias mysite.net

 # Indexes + Directory Root.
 DocumentRoot /home/www/mysite.net/htdocs/
 <Directory />
 DirectoryIndex index.php index.html
 Options FollowSymLinks
 AllowOverRide All
 </Directory>

 # CGI Directory
 ScriptAlias /cgi-bin/ /home/www/mysite.net/cgi-bin/
 <Location /cgi-bin>
 Options +ExecCGI
 </Location>

 # Logfiles
 ErrorLogĀ  /home/www/mysite.net/logs/error.log
 CustomLog /home/www/mysite.net/logs/access.log combined
</VirtualHost>

Good, now to enable your new site, execute

a2ensite mysite.net
/etc/init.d/apache2 reload

and you’re done!