<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>AskApache &#187; Search Results  &#187;  servers</title>
	<atom:link href="http://www.askapache.com/search/servers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.askapache.com</link>
	<description>Advanced Web Development</description>
	<lastBuildDate>Thu, 26 Apr 2012 11:29:28 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Mod_Rewrite Security</title>
		<link>http://www.askapache.com/security/mod_rewrite.html</link>
		<comments>http://www.askapache.com/security/mod_rewrite.html#comments</comments>
		<pubDate>Sat, 18 Feb 2012 06:54:18 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Htaccess]]></category>
		<category><![CDATA[mod_rewrite]]></category>
		<category><![CDATA[RewriteCond]]></category>
		<category><![CDATA[RewriteRule]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=7045</guid>
		<description><![CDATA[<p><a class="hs hs13" href="http://www.askapache.com/security/mod_rewrite.html" title="Mod_Rewrite Artwork"></a>These are a few of the mod_rewrite uses that <a href="http://blogsecurity.net/">BlogSecurity</a> declared <strong>pushed the boundaries of Mod_Rewrite!</strong>  Some of these snippets are quite exotic and unlike anything you may have seen before, also only for those who understand them as they can kill a website pretty quick.<br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/security/mod_rewrite.html"></a><a href="http://www.askapache.com/security/mod_rewrite.html"><cite>AskApache.com</cite></a></p><p>Here are some <a href="http://www.askapache.com/htaccess/htaccess.html" title="Htaccess Tutorial">specific htaccess</a> examples taken mostly from my WordPress Password Protection plugin, which does alot more than password protection as you will see from the following mod_rewrite examples. These are a few of the mod_rewrite uses that <a href="http://blogsecurity.net/">BlogSecurity</a> declared <strong>pushed the boundaries of Mod_Rewrite!</strong>  Some of these snippets are quite exotic and unlike anything you may have seen before, also only for those who understand them as they can kill a website pretty quick.</p>

<h4>Directory Protection</h4>
<p>Enable the DirectoryIndex Protection, preventing directory index listings and defaulting. [<a href="/htaccess/htaccess.html">Disable</a>]</p>
<pre>
Options -Indexes
DirectoryIndex index.html index.php /index.php
</pre>

<h4>Password Protect wp-login.php</h4>
<p>Requires a valid user/pass to access the login page[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
&lt;Files wp-login.php&gt;
Order Deny,Allow
Deny from All
Satisfy Any
AuthName "Protected By AskApache"
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;/Files&gt;
</pre>


<h4>Password Protect wp-admin</h4>
<p>Requires a valid user/pass to access any non-static (css, js, images) file in this directory.[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
Options -ExecCGI -Indexes +FollowSymLinks -Includes
DirectoryIndex index.php /index.php
Order Deny,Allow
Deny from All
Satisfy Any
AuthName "Protected By AskApache"
AuthUserFile /home/askapache.com/.htpasswda1
AuthType Basic
Require valid-user
&lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$"&gt;
Allow from All
&lt;/FilesMatch&gt;
&lt;FilesMatch "(async-upload)\.php$"&gt;
&lt;IfModule mod_security.c&gt;
SecFilterEngine Off
&lt;/IfModule&gt;
Allow from All
&lt;/FilesMatch&gt;
</pre>

<h4>Protect wp-content</h4>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-401">401</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-content/.*$ [NC]
RewriteCond %{REQUEST_FILENAME} !^.+flexible-upload-wp25js.php$
RewriteCond %{REQUEST_FILENAME} ^.+\.(php|html|htm|txt)$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Protect wp-includes</h4>
<p>Denies any Direct request for files ending in .php with a 403 Forbidden.. May break plugins/themes [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /wp-includes/.*$ [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ /wp-includes/js/.+/.+\ HTTP/ [NC]
RewriteCond %{REQUEST_FILENAME} ^.+\.php$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Common Exploits</h4>
<p>Block common exploit requests with 403 Forbidden. These can help alot, may break some plugins. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ ///.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\=?(http|ftp|ssl|https):/.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\?\?.*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(asp|ini|dll).*\ HTTP/ [NC,OR]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*\.(htpasswd|htaccess|aahtpasswd).*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Stop Hotlinking</h4>
<p>Denies any request for static files (images, css, etc) if referrer is not local site or empty. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_REFERER} !^http://www.askapache.com.*$ [NC]
RewriteRule \.(ico|pdf|flv|jpg|jpeg|mp3|mpg|mp4|mov|wav|wmv|png|gif|swf|css|js)$ - [F,NS,L]
</pre>

<h4>Safe Request Methods</h4>
<p>Denies any request not using <a href="http://www.askapache.com/online-tools/request-method-scanner/">GET,PROPFIND,POST,OPTIONS,PUT,HEAD</a>[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} !^(GET|HEAD|POST|PROPFIND|OPTIONS|PUT)$ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Forbid Proxies</h4>
<p>Denies any POST Request using a Proxy Server. Can still access site, but not comment.  See <a href="http://perishablepress.com/press/2008/04/20/how-to-block-proxy-servers-via-htaccess/">Perishable Press</a> [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:VIA}%{HTTP:FORWARDED}%{HTTP:USERAGENT_VIA}%{HTTP:X_FORWARDED_FOR}%{HTTP:PROXY_CONNECTION} !^$ [OR]
RewriteCond %{HTTP:XPROXY_CONNECTION}%{HTTP:HTTP_PC_REMOTE_ADDR}%{HTTP:HTTP_CLIENT_IP} !^$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Real wp-comments-post.php</h4>
<p>Denies any POST attempt made to a non-existing wp-comments-post.php[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>HTTP PROTOCOL</h4>
<p>Denies any badly formed HTTP PROTOCOL in the request, 0.9, 1.0, and 1.1 only[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ .+\ HTTP/(0\.9|1\.0|1\.1) [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>SPECIFY CHARACTERS</h4>
<p>Denies any request for a url containing characters other than "a-zA-Z0-9.+/-?=&amp;"  - REALLY helps but may break your site depending on your links. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{THE_REQUEST} !^[A-Z]{3,9}\ [a-zA-Z0-9\.\+_/\-\?\=\&amp;amp;]+\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>BAD Content Length</h4>
<p>Denies any POST request that doesnt have a Content-Length Header[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Length} ^$
RewriteCond %{REQUEST_URI} !^/(wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>BAD Content Type</h4>
<p>Denies any POST request with a content type other than application/x-www-form-urlencoded|multipart/form-data[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP:Content-Type} !^(application/x-www-form-urlencoded|multipart/form-data.*(boundary.*)?)$ [NC]
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Missing HTTP_HOST</h4>
<p>Denies requests that dont contain a HTTP HOST Header.[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteCond %{HTTP_HOST} ^$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Bogus Graphics Exploit</h4>
<p>Denies obvious exploit using bogus graphics[<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{HTTP:Content-Disposition} \.php [NC]
RewriteCond %{HTTP:Content-Type} image/.+ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>No UserAgent, Not POST</h4>
<p>Denies POST requests by blank user-agents.  May prevent a small number of visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{REQUEST_URI} !^/(wp-login.php|wp-admin/|wp-content/plugins/|wp-includes/).* [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>No Referer, No Comment</h4>
<p>Denies any comment attempt with a blank HTTP_REFERER field, highly indicative of spam.  May prevent some visitors from POSTING. [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*/wp-comments-post\.php.*\ HTTP/ [NC]
RewriteCond %{HTTP_REFERER} ^-?$
RewriteRule .* - [F,NS,L]
</pre>

<h4>Trackback Spam</h4>
<p>Denies obvious trackback spam.  See Holy Shmoly! [<a href="/htaccess/apache-status-code-headers-errordocument.html#status-403">403</a>]</p>
<pre>
RewriteCond %{REQUEST_METHOD} =POST
RewriteCond %{HTTP_USER_AGENT} ^.*(opera|mozilla|firefox|msie|safari).*$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.+/trackback/?\ HTTP/ [NC]
RewriteRule .* - [F,NS,L]
</pre>

<h4>Map all URIs except those corresponding to existing files to a handler</h4>
<pre>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-d
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule . /script.php
</pre>

<h4>Map any request to a handler</h4>
<p>In the case where all URIs should be sent to the same place (including potentially requests for static content) the method to use depends on the type of the handler. For php scripts, use:
For other handlers such as php scripts, use:</p>
<pre>
RewriteEngine On
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php
</pre>

<h4>And for CGI scripts:</h4>
<pre>
ScriptAliasMatch .* /var/www/script.cgi
</pre>

<h4>Map URIs corresponding to existing files to a handler instead</h4>
<pre>
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f
RewriteCond %{REQUEST_URI} !=/script.php
RewriteRule .* /script.php
</pre>
<p>If the existing files you wish to have handled by your script have a common set of file extensions distinct from that of the hander, you can bypass mod_rewrite and use instead mod_actions. Let's say you want all .html and .tpl files to be dealt with by your script:</p>
<pre>
Action foo-action /script.php
AddHandler foo-action html tpl
</pre>

<h4>Deny access if var=val contains the string foo.</h4>
<pre>
RewriteCond %{QUERY_STRING} foo
RewriteRule ^/url - [F]
</pre>

<h4>Removing the Query String</h4>
<pre>
RewriteRule ^/url /url?
</pre>

<h4>Adding to the Query String</h4>
<p>Keep the existing query string using the Query String Append flag, but add var=val to the end.</p>
<pre>
RewriteRule ^/url /url?var=val [QSA]
</pre>

<h4>Rewriting For Certain Query Strings</h4>
<p>Rewrite URLs like http://askapache.com/url1?var=val to http://askapache.com/url2?var=val but don't rewrite if val isn't present.</p>
<pre>
RewriteCond %{QUERY_STRING} val
RewriteRule ^/url1 /url2
</pre>

<h4>Modifying the Query String</h4>
<p>Change any single instance of val in the query string to other_val when accessing /path. Note that %1 and %2 are back-references to the matched part of the regular expression in the previous RewriteCond.</p>
<pre>
RewriteCond %{QUERY_STRING} ^(.*)val(.*)$
RewriteRule /path /path?%1other_val%2
</pre>
<hr class="C" />
<p><a href="http://www.askapache.com/security/mod_rewrite.html"></a><a href="http://www.askapache.com/security/mod_rewrite.html">Mod_Rewrite Security</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/security/mod_rewrite.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Chmod, Umask, Stat, Fileperms, and File Permissions</title>
		<link>http://www.askapache.com/security/chmod-stat.html</link>
		<comments>http://www.askapache.com/security/chmod-stat.html#comments</comments>
		<pubDate>Fri, 17 Feb 2012 11:16:56 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[chmod]]></category>
		<category><![CDATA[File Permissions]]></category>
		<category><![CDATA[umask]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=1800</guid>
		<description><![CDATA[<p><a class="IFL" id="id8" href="http://www.askapache.com/security/chmod-umask-fileperms-stat-tricks.html"></a>Unix file permissions are one of the more difficult subjects to grasp.. Well, ok maybe "grasp" isn't the word.. Master is the right word.. Unix file permissions is a hard topic to fully master, mainly I think because there aren't many instances when a computer user encounters them seriously, and bitwise is oldschool.  This contains a listing of all possible permission masks and bits from a linux, php, and web hosting view.... cuz you guys <em>AskApache Regs</em> Rock! <br class="C" /></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/security/chmod-stat.html"></a><a href="http://www.askapache.com/security/chmod-stat.html"><cite>AskApache.com</cite></a></p><p><a class="IFL" id="id8" href="http://www.askapache.com/security/chmod-stat.html"></a>Unix file permissions are one of the more difficult subjects to grasp.. Well, ok maybe "grasp" isn't the word.. Master is the right word.. Unix file permissions is a hard topic to fully master, mainly I think because there aren't many instances when a computer user encounters them.   Windows has been trying to figure it out for decades with little progress, so don't feel bad if you don't know much about it.  <strong>Unless you're with the program</strong> and running Mac or any other <a href="http://www.archlinux.org/">BSD/Unix</a> based OS you've never had the ability to secure your system in this most basic and fundamental way.  Usually the first time someone encounters file permissions it's because their website was cracked.. <br class="C" /></p>

<h3>.htaccess</h3>
<p><kbd>$ chmod 604 .htaccess</kbd></p>
<pre>
604 -rw----r--  /home/askapache/cgi-bin/.htaccess
</pre>


<h3>php.cgi</h3>
<p><kbd>$ chmod 711 php.cgi</kbd></p>
<pre>
$ 711 -rwx--x--x  /home/askapache/cgi-bin/php.cgi
</pre>


<h3>.php.ini</h3>
<p><kbd>$ chmod 600 php.ini</kbd></p>
<pre>
$ 600 -rw-------  /home/askapache/cgi-bin/php.ini
</pre>

<p>I'm in the process of developing an updated version of the .htaccess security plugin, and one thing I have been working on is file permissions.  Some people had problems trying to create files on their server and I realized it was bad programming on my part..  so I began researching permissions in detail. I went deep into the source code of Apache (<em>which is why this site is called AskApache, BTW</em>), PHP, Python, Ocaml, Perl, Ruby, and POSIX operating systems and got a pretty good handle on it now..</p>

<h2>Tips before we dig in</h2>
<p>Here's a few things I've learned that I didn't know before (using php).</p>

<h3>Deleting Files and Directories</h3>
<p>Deleting a file may require chmodding the file to 666 or even 777 before you are able to delete it.  You also might have to chmod the parent directory of the file as well.  Also, you may have to chdir to the directory the file is in.  And lastly you may have to change the owner or group of the file.  Further than that you can try renaming the file first then deleting it..</p>
<p>Deleting a directory means you need to remove every file in it first.  It needs to be empty.  And if your file system uses NFS or some other networked FS you might have even more problems deleting files.  If the file you are trying to delete is being used by say, Apache or php then you might have to kill that process first.</p>

<h3>Creating Files in Restrictive Environments</h3>
<p>My research has been geared to try and make my code as robust as possible, I'm throwing everything but the kitchen sink into some of these functions because so many people are on such different types of servers.  To create a file in a restrictive environment is a fun excercise to take.. You can write a file using many different functions, but there are some tricks if they all fail.  One trick is instead of trying to "write" the data to the file, you can UPLOAD the data to the server and let PHP handle the file as if you used an upload form.  I like to use fsockopen to do it, as some installations have been setup to prevent this type of fake upload.</p>
<p>Then there are the various other hacks like using an ftp connection (if you know the user/pass) to send the file from php, using ssh from php, whatever is available on the hosts php installation.  In addition to those more involved workarounds you can often get around this problem by doing little hacks discussed at php.net in the comments for various functions.  Such as changing the umask, changing directories with chdir first, creating a temporary file using a function like tempfile and then renaming or copying the tempfile to your desired file which sometimes gives you the permissions needed to write to the location.</p>
<p>If the php installation is newer than you can also look into creating your own stream context to pass write the data direct.</p>


<h2>Stat Function</h2>
<p>I've created a stat function in php that goes farther than the normal stat function... Just give the function a file to stat, and it returns an array of information.  </p>
<pre>
function askapache_stat($filename) {
 clearstatcache();
 $ss=@stat($filename);
 if(!$ss) die("Couldnt stat {$filename}");
 $file_convert=array(0140000=&gt;&#039;ssocket&#039;,0120000=&gt;&#039;llink&#039;,0100000=&gt;&#039;-file&#039;,0060000=&gt;&#039;bblock&#039;,0040000=&gt;&#039;ddir&#039;,0020000=&gt;&#039;cchar&#039;,0010000=&gt;&#039;pfifo&#039;);
 $p=$ss[&#039;mode&#039;];
 $t=decoct($ss[&#039;mode&#039;] &amp; 0170000);
 $str = (array_key_exists(octdec($t),$file_convert)) ? $file_convert[octdec($t)]{0} : &#039;u&#039;;
 $str.=(($p&amp;0x0100)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0080)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0040)?(($p&amp;0x0800)?&#039;s&#039;:&#039;x&#039;):(($p&amp;0x0800)?&#039;S&#039;:&#039;-&#039;));
 $str.=(($p&amp;0x0020)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0010)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0008)?(($p&amp;0x0400)?&#039;s&#039;:&#039;x&#039;):(($p&amp;0x0400)?&#039;S&#039;:&#039;-&#039;));
 $str.=(($p&amp;0x0004)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0002)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0001)?(($p&amp;0x0200)?&#039;t&#039;:&#039;x&#039;):(($p&amp;0x0200)?&#039;T&#039;:&#039;-&#039;));
&nbsp;
 $s=array(
 &#039;perms&#039;=&gt;array(
  &#039;umask&#039;=&gt;sprintf("%04o",umask()),
  &#039;human&#039;=&gt;$str,
  &#039;octal1&#039;=&gt;sprintf("%o", ($ss[&#039;mode&#039;] &amp; 000777)),
  &#039;octal2&#039;=&gt;sprintf("0%o", 0777 &amp; $p),
  &#039;decimal&#039;=&gt;sprintf("%04o", $p),
  &#039;fileperms&#039;=&gt;@fileperms($filename),
  &#039;mode1&#039;=&gt;$p,
  &#039;mode2&#039;=&gt;$ss[&#039;mode&#039;]),
&nbsp;
 &#039;filetype&#039;=&gt;array(
  &#039;type&#039;=&gt;substr($file_convert[octdec($t)],1),
  &#039;type_octal&#039;=&gt;sprintf("%07o", octdec($t)),
  &#039;is_file&#039;=&gt;@is_file($filename),
  &#039;is_dir&#039;=&gt;@is_dir($filename),
  &#039;is_link&#039;=&gt;@is_link($filename),
  &#039;is_readable&#039;=&gt; @is_readable($filename),
  &#039;is_writable&#039;=&gt; @is_writable($filename)),
&nbsp;
 &#039;owner&#039;=&gt;array(
  &#039;fileowner&#039;=&gt;$ss[&#039;uid&#039;],
  &#039;filegroup&#039;=&gt;$ss[&#039;gid&#039;],
  &#039;owner_name&#039;=&gt;(function_exists(&#039;posix_getpwuid&#039;)) ? @reset(@posix_getpwuid($ss[&#039;uid&#039;])) : &#039;&#039;,
  &#039;group_name&#039;=&gt;(function_exists(&#039;posix_getgrgid&#039;)) ? @reset(@posix_getgrgid($ss[&#039;gid&#039;])) : &#039;&#039;),
&nbsp;
 &#039;file&#039;=&gt;array(
  &#039;filename&#039;=&gt;$filename,
  &#039;realpath&#039;=&gt;(@realpath($filename) != $filename) ? @realpath($filename) : &#039;&#039;,
  &#039;dirname&#039;=&gt;@dirname($filename),
  &#039;basename&#039;=&gt;@basename($filename)),
&nbsp;
 &#039;device&#039;=&gt;array(
  &#039;device&#039;=&gt;$ss[&#039;dev&#039;], //Device
  &#039;device_number&#039;=&gt;$ss[&#039;rdev&#039;], //Device number, if device.
  &#039;inode&#039;=&gt;$ss[&#039;ino&#039;], //File serial number
  &#039;link_count&#039;=&gt;$ss[&#039;nlink&#039;], //link count
  &#039;link_to&#039;=&gt;($s[&#039;type&#039;]==&#039;link&#039;) ? @readlink($filename) : &#039;&#039;),
&nbsp;
 &#039;size&#039;=&gt;array(
  &#039;size&#039;=&gt;$ss[&#039;size&#039;], //Size of file, in bytes.
  &#039;blocks&#039;=&gt;$ss[&#039;blocks&#039;], //Number 512-byte blocks allocated
  &#039;block_size&#039;=&gt; $ss[&#039;blksize&#039;]), //Optimal block size for I/O.
&nbsp;
 &#039;time&#039;=&gt;array(
  &#039;mtime&#039;=&gt;$ss[&#039;mtime&#039;], //Time of last modification
  &#039;atime&#039;=&gt;$ss[&#039;atime&#039;], //Time of last access.
  &#039;ctime&#039;=&gt;$ss[&#039;ctime&#039;], //Time of last status change
  &#039;accessed&#039;=&gt;@date(&#039;Y M D H:i:s&#039;,$ss[&#039;atime&#039;]),
  &#039;modified&#039;=&gt;@date(&#039;Y M D H:i:s&#039;,$ss[&#039;mtime&#039;]),
  &#039;created&#039;=&gt;@date(&#039;Y M D H:i:s&#039;,$ss[&#039;ctime&#039;])),
 );
&nbsp;
 clearstatcache();
 return $s;
}
</pre>


<h3>PHP Stat Function Output</h2>
<p>Example output, say from <code>print_r(askapache_stat( __FILE__ ) );</code></p>
<pre>
Array(
[perms] =&gt; Array
  (
  [umask] =&gt; 0022
  [human] =&gt; -rw-r--r--
  [octal1] =&gt; 644
  [octal2] =&gt; 0644
  [decimal] =&gt; 100644
  [fileperms] =&gt; 33188
  [mode1] =&gt; 33188
  [mode2] =&gt; 33188
  )
&nbsp;
[filetype] =&gt; Array
  (
  [type] =&gt; file
  [type_octal] =&gt; 0100000
  [is_file] =&gt; 1
  [is_dir] =&gt;
  [is_link] =&gt;
  [is_readable] =&gt; 1
  [is_writable] =&gt; 1
  )
&nbsp;
[owner] =&gt; Array
  (
  [fileowner] =&gt; 035483
  [filegroup] =&gt; 23472
  [owner_name] =&gt; askapache
  [group_name] =&gt; grp22558
  )
&nbsp;
[file] =&gt; Array
  (
  [filename] =&gt; /home/askapache/askapache-stat/public_html/ok/g.php
  [realpath] =&gt;
  [dirname] =&gt; /home/askapache/askapache-stat/public_html/ok
  [basename] =&gt; g.php
  )
&nbsp;
[device] =&gt; Array
  (
  [device] =&gt; 25
  [device_number] =&gt; 0
  [inode] =&gt; 92455020
  [link_count] =&gt; 1
  [link_to] =&gt;
  )
&nbsp;
[size] =&gt; Array
  (
  [size] =&gt; 2652
  [blocks] =&gt; 8
  [block_size] =&gt; 8192
  )
&nbsp;
[time] =&gt; Array
  (
  [mtime] =&gt; 1227685253
  [atime] =&gt; 1227685138
  [ctime] =&gt; 1227685253
  [accessed] =&gt; 2008 Nov Tue 23:38:58
  [modified] =&gt; 2008 Nov Tue 23:40:53
  [created] =&gt; 2008 Nov Tue 23:40:53
  )
)
</pre>






<h2><a id="chmod-0-to-7777"></a>Every Permission 0000 to 0777</h2>
<p><a class="IFL" href="http://uploads.askapache.com/2008/11/danger-chmod-screenshot.png"><img src="http://uploads.askapache.com/2008/11/danger-chmod-screenshot.png" alt="chmod, umask, file permissions test" title="chmod, umask, file permissions test" /></a>This shows what each numeric permission does to a REGULAR file.  I'll provide the code to do this below so you can do the same thing on your server.<br class="C" /></p>
<dl class="dlsm" style="border-right:1px solid #CCC;">
<dt><kbd>chmod 0</kbd></dt>
<dd><code>----------</code></dd>
<dt><kbd>chmod 1</kbd></dt>
<dd><code>---------x</code></dd>
<dt><kbd>chmod 2</kbd></dt>
<dd><code>--------w-</code></dd>
<dt><kbd>chmod 3</kbd></dt>
<dd><code>--------wx</code></dd>
<dt><kbd>chmod 4</kbd></dt>
<dd><code>-------r--</code></dd>
<dt><kbd>chmod 5</kbd></dt>
<dd><code>-------r-x</code></dd>
<dt><kbd>chmod 6</kbd></dt>
<dd><code>-------rw-</code></dd>
<dt><kbd>chmod 7</kbd></dt>
<dd><code>-------rwx</code></dd>
<dt><kbd>chmod 10</kbd></dt>
<dd><code>------x---</code></dd>
<dt><kbd>chmod 11</kbd></dt>
<dd><code>------x--x</code></dd>
<dt><kbd>chmod 12</kbd></dt>
<dd><code>------x-w-</code></dd>
<dt><kbd>chmod 13</kbd></dt>
<dd><code>------x-wx</code></dd>
<dt><kbd>chmod 14</kbd></dt>
<dd><code>------xr--</code></dd>
<dt><kbd>chmod 15</kbd></dt>
<dd><code>------xr-x</code></dd>
<dt><kbd>chmod 16</kbd></dt>
<dd><code>------xrw-</code></dd>
<dt><kbd>chmod 17</kbd></dt>
<dd><code>------xrwx</code></dd>
<dt><kbd>chmod 20</kbd></dt>
<dd><code>-----w----</code></dd>
<dt><kbd>chmod 21</kbd></dt>
<dd><code>-----w---x</code></dd>
<dt><kbd>chmod 22</kbd></dt>
<dd><code>-----w--w-</code></dd>
<dt><kbd>chmod 23</kbd></dt>
<dd><code>-----w--wx</code></dd>
<dt><kbd>chmod 24</kbd></dt>
<dd><code>-----w-r--</code></dd>
<dt><kbd>chmod 25</kbd></dt>
<dd><code>-----w-r-x</code></dd>
<dt><kbd>chmod 26</kbd></dt>
<dd><code>-----w-rw-</code></dd>
<dt><kbd>chmod 27</kbd></dt>
<dd><code>-----w-rwx</code></dd>
<dt><kbd>chmod 30</kbd></dt>
<dd><code>-----wx---</code></dd>
<dt><kbd>chmod 31</kbd></dt>
<dd><code>-----wx--x</code></dd>
<dt><kbd>chmod 32</kbd></dt>
<dd><code>-----wx-w-</code></dd>
<dt><kbd>chmod 33</kbd></dt>
<dd><code>-----wx-wx</code></dd>
<dt><kbd>chmod 34</kbd></dt>
<dd><code>-----wxr--</code></dd>
<dt><kbd>chmod 35</kbd></dt>
<dd><code>-----wxr-x</code></dd>
<dt><kbd>chmod 36</kbd></dt>
<dd><code>-----wxrw-</code></dd>
<dt><kbd>chmod 37</kbd></dt>
<dd><code>-----wxrwx</code></dd>
<dt><kbd>chmod 40</kbd></dt>
<dd><code>----r-----</code></dd>
<dt><kbd>chmod 41</kbd></dt>
<dd><code>----r----x</code></dd>
<dt><kbd>chmod 42</kbd></dt>
<dd><code>----r---w-</code></dd>
<dt><kbd>chmod 43</kbd></dt>
<dd><code>----r---wx</code></dd>
<dt><kbd>chmod 44</kbd></dt>
<dd><code>----r--r--</code></dd>
<dt><kbd>chmod 45</kbd></dt>
<dd><code>----r--r-x</code></dd>
<dt><kbd>chmod 46</kbd></dt>
<dd><code>----r--rw-</code></dd>
<dt><kbd>chmod 47</kbd></dt>
<dd><code>----r--rwx</code></dd>
<dt><kbd>chmod 50</kbd></dt>
<dd><code>----r-x---</code></dd>
<dt><kbd>chmod 51</kbd></dt>
<dd><code>----r-x--x</code></dd>
<dt><kbd>chmod 52</kbd></dt>
<dd><code>----r-x-w-</code></dd>
<dt><kbd>chmod 53</kbd></dt>
<dd><code>----r-x-wx</code></dd>
<dt><kbd>chmod 54</kbd></dt>
<dd><code>----r-xr--</code></dd>
<dt><kbd>chmod 55</kbd></dt>
<dd><code>----r-xr-x</code></dd>
<dt><kbd>chmod 56</kbd></dt>
<dd><code>----r-xrw-</code></dd>
<dt><kbd>chmod 57</kbd></dt>
<dd><code>----r-xrwx</code></dd>
<dt><kbd>chmod 60</kbd></dt>
<dd><code>----rw----</code></dd>
<dt><kbd>chmod 61</kbd></dt>
<dd><code>----rw---x</code></dd>
<dt><kbd>chmod 62</kbd></dt>
<dd><code>----rw--w-</code></dd>
<dt><kbd>chmod 63</kbd></dt>
<dd><code>----rw--wx</code></dd>
<dt><kbd>chmod 64</kbd></dt>
<dd><code>----rw-r--</code></dd>
<dt><kbd>chmod 65</kbd></dt>
<dd><code>----rw-r-x</code></dd>
<dt><kbd>chmod 66</kbd></dt>
<dd><code>----rw-rw-</code></dd>
<dt><kbd>chmod 67</kbd></dt>
<dd><code>----rw-rwx</code></dd>
<dt><kbd>chmod 70</kbd></dt>
<dd><code>----rwx---</code></dd>
<dt><kbd>chmod 71</kbd></dt>
<dd><code>----rwx--x</code></dd>
<dt><kbd>chmod 72</kbd></dt>
<dd><code>----rwx-w-</code></dd>
<dt><kbd>chmod 73</kbd></dt>
<dd><code>----rwx-wx</code></dd>
<dt><kbd>chmod 74</kbd></dt>
<dd><code>----rwxr--</code></dd>
<dt><kbd>chmod 75</kbd></dt>
<dd><code>----rwxr-x</code></dd>
<dt><kbd>chmod 76</kbd></dt>
<dd><code>----rwxrw-</code></dd>
<dt><kbd>chmod 77</kbd></dt>
<dd><code>----rwxrwx</code></dd>
<dt><kbd>chmod 100</kbd></dt>
<dd><code>---x------</code></dd>
<dt><kbd>chmod 101</kbd></dt>
<dd><code>---x-----x</code></dd>
<dt><kbd>chmod 102</kbd></dt>
<dd><code>---x----w-</code></dd>
<dt><kbd>chmod 103</kbd></dt>
<dd><code>---x----wx</code></dd>
<dt><kbd>chmod 104</kbd></dt>
<dd><code>---x---r--</code></dd>
<dt><kbd>chmod 105</kbd></dt>
<dd><code>---x---r-x</code></dd>
<dt><kbd>chmod 106</kbd></dt>
<dd><code>---x---rw-</code></dd>
<dt><kbd>chmod 107</kbd></dt>
<dd><code>---x---rwx</code></dd>
<dt><kbd>chmod 110</kbd></dt>
<dd><code>---x--x---</code></dd>
<dt><kbd>chmod 111</kbd></dt>
<dd><code>---x--x--x</code></dd>
<dt><kbd>chmod 112</kbd></dt>
<dd><code>---x--x-w-</code></dd>
<dt><kbd>chmod 113</kbd></dt>
<dd><code>---x--x-wx</code></dd>
<dt><kbd>chmod 114</kbd></dt>
<dd><code>---x--xr--</code></dd>
<dt><kbd>chmod 115</kbd></dt>
<dd><code>---x--xr-x</code></dd>
<dt><kbd>chmod 116</kbd></dt>
<dd><code>---x--xrw-</code></dd>
<dt><kbd>chmod 117</kbd></dt>
<dd><code>---x--xrwx</code></dd>
<dt><kbd>chmod 120</kbd></dt>
<dd><code>---x-w----</code></dd>
<dt><kbd>chmod 121</kbd></dt>
<dd><code>---x-w---x</code></dd>
<dt><kbd>chmod 122</kbd></dt>
<dd><code>---x-w--w-</code></dd>
<dt><kbd>chmod 123</kbd></dt>
<dd><code>---x-w--wx</code></dd>
<dt><kbd>chmod 124</kbd></dt>
<dd><code>---x-w-r--</code></dd>
<dt><kbd>chmod 125</kbd></dt>
<dd><code>---x-w-r-x</code></dd>
<dt><kbd>chmod 126</kbd></dt>
<dd><code>---x-w-rw-</code></dd>
<dt><kbd>chmod 127</kbd></dt>
<dd><code>---x-w-rwx</code></dd>
<dt><kbd>chmod 130</kbd></dt>
<dd><code>---x-wx---</code></dd>
<dt><kbd>chmod 131</kbd></dt>
<dd><code>---x-wx--x</code></dd>
<dt><kbd>chmod 132</kbd></dt>
<dd><code>---x-wx-w-</code></dd>
<dt><kbd>chmod 133</kbd></dt>
<dd><code>---x-wx-wx</code></dd>
<dt><kbd>chmod 134</kbd></dt>
<dd><code>---x-wxr--</code></dd>
<dt><kbd>chmod 135</kbd></dt>
<dd><code>---x-wxr-x</code></dd>
<dt><kbd>chmod 136</kbd></dt>
<dd><code>---x-wxrw-</code></dd>
<dt><kbd>chmod 137</kbd></dt>
<dd><code>---x-wxrwx</code></dd>
<dt><kbd>chmod 140</kbd></dt>
<dd><code>---xr-----</code></dd>
<dt><kbd>chmod 141</kbd></dt>
<dd><code>---xr----x</code></dd>
<dt><kbd>chmod 142</kbd></dt>
<dd><code>---xr---w-</code></dd>
<dt><kbd>chmod 143</kbd></dt>
<dd><code>---xr---wx</code></dd>
<dt><kbd>chmod 144</kbd></dt>
<dd><code>---xr--r--</code></dd>
<dt><kbd>chmod 145</kbd></dt>
<dd><code>---xr--r-x</code></dd>
<dt><kbd>chmod 146</kbd></dt>
<dd><code>---xr--rw-</code></dd>
<dt><kbd>chmod 147</kbd></dt>
<dd><code>---xr--rwx</code></dd>
<dt><kbd>chmod 150</kbd></dt>
<dd><code>---xr-x---</code></dd>
<dt><kbd>chmod 151</kbd></dt>
<dd><code>---xr-x--x</code></dd>
<dt><kbd>chmod 152</kbd></dt>
<dd><code>---xr-x-w-</code></dd>
<dt><kbd>chmod 153</kbd></dt>
<dd><code>---xr-x-wx</code></dd>
<dt><kbd>chmod 154</kbd></dt>
<dd><code>---xr-xr--</code></dd>
<dt><kbd>chmod 155</kbd></dt>
<dd><code>---xr-xr-x</code></dd>
<dt><kbd>chmod 156</kbd></dt>
<dd><code>---xr-xrw-</code></dd>
<dt><kbd>chmod 157</kbd></dt>
<dd><code>---xr-xrwx</code></dd>
<dt><kbd>chmod 160</kbd></dt>
<dd><code>---xrw----</code></dd>
<dt><kbd>chmod 161</kbd></dt>
<dd><code>---xrw---x</code></dd>
<dt><kbd>chmod 162</kbd></dt>
<dd><code>---xrw--w-</code></dd>
<dt><kbd>chmod 163</kbd></dt>
<dd><code>---xrw--wx</code></dd>
<dt><kbd>chmod 164</kbd></dt>
<dd><code>---xrw-r--</code></dd>
<dt><kbd>chmod 165</kbd></dt>
<dd><code>---xrw-r-x</code></dd>
<dt><kbd>chmod 166</kbd></dt>
<dd><code>---xrw-rw-</code></dd>
<dt><kbd>chmod 167</kbd></dt>
<dd><code>---xrw-rwx</code></dd>
<dt><kbd>chmod 170</kbd></dt>
<dd><code>---xrwx---</code></dd>
<dt><kbd>chmod 171</kbd></dt>
<dd><code>---xrwx--x</code></dd>
<dt><kbd>chmod 172</kbd></dt>
<dd><code>---xrwx-w-</code></dd>
<dt><kbd>chmod 173</kbd></dt>
<dd><code>---xrwx-wx</code></dd>
<dt><kbd>chmod 174</kbd></dt>
<dd><code>---xrwxr--</code></dd>
<dt><kbd>chmod 175</kbd></dt>
<dd><code>---xrwxr-x</code></dd>
<dt><kbd>chmod 176</kbd></dt>
<dd><code>---xrwxrw-</code></dd>
<dt><kbd>chmod 177</kbd></dt>
<dd><code>---xrwxrwx</code></dd>
<dt><kbd>chmod 200</kbd></dt>
<dd><code>--w-------</code></dd>
<dt><kbd>chmod 201</kbd></dt>
<dd><code>--w------x</code></dd>
<dt><kbd>chmod 202</kbd></dt>
<dd><code>--w-----w-</code></dd>
<dt><kbd>chmod 203</kbd></dt>
<dd><code>--w-----wx</code></dd>
<dt><kbd>chmod 204</kbd></dt>
<dd><code>--w----r--</code></dd>
<dt><kbd>chmod 205</kbd></dt>
<dd><code>--w----r-x</code></dd>
<dt><kbd>chmod 206</kbd></dt>
<dd><code>--w----rw-</code></dd>
<dt><kbd>chmod 207</kbd></dt>
<dd><code>--w----rwx</code></dd>
<dt><kbd>chmod 210</kbd></dt>
<dd><code>--w---x---</code></dd>
<dt><kbd>chmod 211</kbd></dt>
<dd><code>--w---x--x</code></dd>
<dt><kbd>chmod 212</kbd></dt>
<dd><code>--w---x-w-</code></dd>
<dt><kbd>chmod 213</kbd></dt>
<dd><code>--w---x-wx</code></dd>
<dt><kbd>chmod 214</kbd></dt>
<dd><code>--w---xr--</code></dd>
<dt><kbd>chmod 215</kbd></dt>
<dd><code>--w---xr-x</code></dd>
<dt><kbd>chmod 216</kbd></dt>
<dd><code>--w---xrw-</code></dd>
<dt><kbd>chmod 217</kbd></dt>
<dd><code>--w---xrwx</code></dd>
<dt><kbd>chmod 220</kbd></dt>
<dd><code>--w--w----</code></dd>
<dt><kbd>chmod 221</kbd></dt>
<dd><code>--w--w---x</code></dd>
<dt><kbd>chmod 222</kbd></dt>
<dd><code>--w--w--w-</code></dd>
<dt><kbd>chmod 223</kbd></dt>
<dd><code>--w--w--wx</code></dd>
<dt><kbd>chmod 224</kbd></dt>
<dd><code>--w--w-r--</code></dd>
<dt><kbd>chmod 225</kbd></dt>
<dd><code>--w--w-r-x</code></dd>
<dt><kbd>chmod 226</kbd></dt>
<dd><code>--w--w-rw-</code></dd>
<dt><kbd>chmod 227</kbd></dt>
<dd><code>--w--w-rwx</code></dd>
<dt><kbd>chmod 230</kbd></dt>
<dd><code>--w--wx---</code></dd>
<dt><kbd>chmod 231</kbd></dt>
<dd><code>--w--wx--x</code></dd>
<dt><kbd>chmod 232</kbd></dt>
<dd><code>--w--wx-w-</code></dd>
<dt><kbd>chmod 233</kbd></dt>
<dd><code>--w--wx-wx</code></dd>
<dt><kbd>chmod 234</kbd></dt>
<dd><code>--w--wxr--</code></dd>
<dt><kbd>chmod 235</kbd></dt>
<dd><code>--w--wxr-x</code></dd>
<dt><kbd>chmod 236</kbd></dt>
<dd><code>--w--wxrw-</code></dd>
<dt><kbd>chmod 237</kbd></dt>
<dd><code>--w--wxrwx</code></dd>
<dt><kbd>chmod 240</kbd></dt>
<dd><code>--w-r-----</code></dd>
<dt><kbd>chmod 241</kbd></dt>
<dd><code>--w-r----x</code></dd>
<dt><kbd>chmod 242</kbd></dt>
<dd><code>--w-r---w-</code></dd>
<dt><kbd>chmod 243</kbd></dt>
<dd><code>--w-r---wx</code></dd>
<dt><kbd>chmod 244</kbd></dt>
<dd><code>--w-r--r--</code></dd>
<dt><kbd>chmod 245</kbd></dt>
<dd><code>--w-r--r-x</code></dd>
<dt><kbd>chmod 246</kbd></dt>
<dd><code>--w-r--rw-</code></dd>
<dt><kbd>chmod 247</kbd></dt>
<dd><code>--w-r--rwx</code></dd>
<dt><kbd>chmod 250</kbd></dt>
<dd><code>--w-r-x---</code></dd>
<dt><kbd>chmod 251</kbd></dt>
<dd><code>--w-r-x--x</code></dd>
<dt><kbd>chmod 252</kbd></dt>
<dd><code>--w-r-x-w-</code></dd>
<dt><kbd>chmod 253</kbd></dt>
<dd><code>--w-r-x-wx</code></dd>
<dt><kbd>chmod 254</kbd></dt>
<dd><code>--w-r-xr--</code></dd>
<dt><kbd>chmod 255</kbd></dt>
<dd><code>--w-r-xr-x</code></dd>
<dt><kbd>chmod 256</kbd></dt>
<dd><code>--w-r-xrw-</code></dd>
<dt><kbd>chmod 257</kbd></dt>
<dd><code>--w-r-xrwx</code></dd>
<dt><kbd>chmod 260</kbd></dt>
<dd><code>--w-rw----</code></dd>
<dt><kbd>chmod 261</kbd></dt>
<dd><code>--w-rw---x</code></dd>
<dt><kbd>chmod 262</kbd></dt>
<dd><code>--w-rw--w-</code></dd>
<dt><kbd>chmod 263</kbd></dt>
<dd><code>--w-rw--wx</code></dd>
<dt><kbd>chmod 264</kbd></dt>
<dd><code>--w-rw-r--</code></dd>
<dt><kbd>chmod 265</kbd></dt>
<dd><code>--w-rw-r-x</code></dd>
<dt><kbd>chmod 266</kbd></dt>
<dd><code>--w-rw-rw-</code></dd>
<dt><kbd>chmod 267</kbd></dt>
<dd><code>--w-rw-rwx</code></dd>
<dt><kbd>chmod 270</kbd></dt>
<dd><code>--w-rwx---</code></dd>
<dt><kbd>chmod 271</kbd></dt>
<dd><code>--w-rwx--x</code></dd>
<dt><kbd>chmod 272</kbd></dt>
<dd><code>--w-rwx-w-</code></dd>
<dt><kbd>chmod 273</kbd></dt>
<dd><code>--w-rwx-wx</code></dd>
<dt><kbd>chmod 274</kbd></dt>
<dd><code>--w-rwxr--</code></dd>
<dt><kbd>chmod 275</kbd></dt>
<dd><code>--w-rwxr-x</code></dd>
<dt><kbd>chmod 276</kbd></dt>
<dd><code>--w-rwxrw-</code></dd>
<dt><kbd>chmod 277</kbd></dt>
<dd><code>--w-rwxrwx</code></dd>
<dt><kbd>chmod 300</kbd></dt>
<dd><code>--wx------</code></dd>
<dt><kbd>chmod 301</kbd></dt>
<dd><code>--wx-----x</code></dd>
<dt><kbd>chmod 302</kbd></dt>
<dd><code>--wx----w-</code></dd>
<dt><kbd>chmod 303</kbd></dt>
<dd><code>--wx----wx</code></dd>
<dt><kbd>chmod 304</kbd></dt>
<dd><code>--wx---r--</code></dd>
<dt><kbd>chmod 305</kbd></dt>
<dd><code>--wx---r-x</code></dd>
<dt><kbd>chmod 306</kbd></dt>
<dd><code>--wx---rw-</code></dd>
<dt><kbd>chmod 307</kbd></dt>
<dd><code>--wx---rwx</code></dd>
<dt><kbd>chmod 310</kbd></dt>
<dd><code>--wx--x---</code></dd>
<dt><kbd>chmod 311</kbd></dt>
<dd><code>--wx--x--x</code></dd>
<dt><kbd>chmod 312</kbd></dt>
<dd><code>--wx--x-w-</code></dd>
<dt><kbd>chmod 313</kbd></dt>
<dd><code>--wx--x-wx</code></dd>
<dt><kbd>chmod 314</kbd></dt>
<dd><code>--wx--xr--</code></dd>
<dt><kbd>chmod 315</kbd></dt>
<dd><code>--wx--xr-x</code></dd>
<dt><kbd>chmod 316</kbd></dt>
<dd><code>--wx--xrw-</code></dd>
<dt><kbd>chmod 317</kbd></dt>
<dd><code>--wx--xrwx</code></dd>
<dt><kbd>chmod 320</kbd></dt>
<dd><code>--wx-w----</code></dd>
<dt><kbd>chmod 321</kbd></dt>
<dd><code>--wx-w---x</code></dd>
<dt><kbd>chmod 322</kbd></dt>
<dd><code>--wx-w--w-</code></dd>
<dt><kbd>chmod 323</kbd></dt>
<dd><code>--wx-w--wx</code></dd>
<dt><kbd>chmod 324</kbd></dt>
<dd><code>--wx-w-r--</code></dd>
<dt><kbd>chmod 325</kbd></dt>
<dd><code>--wx-w-r-x</code></dd>
<dt><kbd>chmod 326</kbd></dt>
<dd><code>--wx-w-rw-</code></dd>
<dt><kbd>chmod 327</kbd></dt>
<dd><code>--wx-w-rwx</code></dd>
<dt><kbd>chmod 330</kbd></dt>
<dd><code>--wx-wx---</code></dd>
<dt><kbd>chmod 331</kbd></dt>
<dd><code>--wx-wx--x</code></dd>
<dt><kbd>chmod 332</kbd></dt>
<dd><code>--wx-wx-w-</code></dd>
<dt><kbd>chmod 333</kbd></dt>
<dd><code>--wx-wx-wx</code></dd>
<dt><kbd>chmod 334</kbd></dt>
<dd><code>--wx-wxr--</code></dd>
<dt><kbd>chmod 335</kbd></dt>
<dd><code>--wx-wxr-x</code></dd>
<dt><kbd>chmod 336</kbd></dt>
<dd><code>--wx-wxrw-</code></dd>
<dt><kbd>chmod 337</kbd></dt>
<dd><code>--wx-wxrwx</code></dd>
<dt><kbd>chmod 340</kbd></dt>
<dd><code>--wxr-----</code></dd>
<dt><kbd>chmod 341</kbd></dt>
<dd><code>--wxr----x</code></dd>
<dt><kbd>chmod 342</kbd></dt>
<dd><code>--wxr---w-</code></dd>
<dt><kbd>chmod 343</kbd></dt>
<dd><code>--wxr---wx</code></dd>
<dt><kbd>chmod 344</kbd></dt>
<dd><code>--wxr--r--</code></dd>
<dt><kbd>chmod 345</kbd></dt>
<dd><code>--wxr--r-x</code></dd>
<dt><kbd>chmod 346</kbd></dt>
<dd><code>--wxr--rw-</code></dd>
<dt><kbd>chmod 347</kbd></dt>
<dd><code>--wxr--rwx</code></dd>
<dt><kbd>chmod 350</kbd></dt>
<dd><code>--wxr-x---</code></dd>
<dt><kbd>chmod 351</kbd></dt>
<dd><code>--wxr-x--x</code></dd>
<dt><kbd>chmod 352</kbd></dt>
<dd><code>--wxr-x-w-</code></dd>
<dt><kbd>chmod 353</kbd></dt>
<dd><code>--wxr-x-wx</code></dd>
<dt><kbd>chmod 354</kbd></dt>
<dd><code>--wxr-xr--</code></dd>
<dt><kbd>chmod 355</kbd></dt>
<dd><code>--wxr-xr-x</code></dd>
<dt><kbd>chmod 356</kbd></dt>
<dd><code>--wxr-xrw-</code></dd>
<dt><kbd>chmod 357</kbd></dt>
<dd><code>--wxr-xrwx</code></dd>
<dt><kbd>chmod 360</kbd></dt>
<dd><code>--wxrw----</code></dd>
<dt><kbd>chmod 361</kbd></dt>
<dd><code>--wxrw---x</code></dd>
<dt><kbd>chmod 362</kbd></dt>
<dd><code>--wxrw--w-</code></dd>
<dt><kbd>chmod 363</kbd></dt>
<dd><code>--wxrw--wx</code></dd>
<dt><kbd>chmod 364</kbd></dt>
<dd><code>--wxrw-r--</code></dd>
<dt><kbd>chmod 365</kbd></dt>
<dd><code>--wxrw-r-x</code></dd>
<dt><kbd>chmod 366</kbd></dt>
<dd><code>--wxrw-rw-</code></dd>
<dt><kbd>chmod 367</kbd></dt>
<dd><code>--wxrw-rwx</code></dd>
<dt><kbd>chmod 370</kbd></dt>
<dd><code>--wxrwx---</code></dd>
<dt><kbd>chmod 371</kbd></dt>
<dd><code>--wxrwx--x</code></dd>
<dt><kbd>chmod 372</kbd></dt>
<dd><code>--wxrwx-w-</code></dd>
<dt><kbd>chmod 373</kbd></dt>
<dd><code>--wxrwx-wx</code></dd>
<dt><kbd>chmod 374</kbd></dt>
<dd><code>--wxrwxr--</code></dd>
<dt><kbd>chmod 375</kbd></dt>
<dd><code>--wxrwxr-x</code></dd>
<dt><kbd>chmod 376</kbd></dt>
<dd><code>--wxrwxrw-</code></dd>
<dt><kbd>chmod 377</kbd></dt>
<dd><code>--wxrwxrwx</code></dd>
<dt><kbd>chmod 400</kbd></dt>
<dd><code>-r--------</code></dd>
<dt><kbd>chmod 401</kbd></dt>
<dd><code>-r-------x</code></dd>
<dt><kbd>chmod 402</kbd></dt>
<dd><code>-r------w-</code></dd>
<dt><kbd>chmod 403</kbd></dt>
<dd><code>-r------wx</code></dd>
<dt><kbd>chmod 404</kbd></dt>
<dd><code>-r-----r--</code></dd>
<dt><kbd>chmod 405</kbd></dt>
<dd><code>-r-----r-x</code></dd>
<dt><kbd>chmod 406</kbd></dt>
<dd><code>-r-----rw-</code></dd>
<dt><kbd>chmod 407</kbd></dt>
<dd><code>-r-----rwx</code></dd>
<dt><kbd>chmod 410</kbd></dt>
<dd><code>-r----x---</code></dd>
<dt><kbd>chmod 411</kbd></dt>
<dd><code>-r----x--x</code></dd>
<dt><kbd>chmod 412</kbd></dt>
<dd><code>-r----x-w-</code></dd>
<dt><kbd>chmod 413</kbd></dt>
<dd><code>-r----x-wx</code></dd>
<dt><kbd>chmod 414</kbd></dt>
<dd><code>-r----xr--</code></dd>
<dt><kbd>chmod 415</kbd></dt>
<dd><code>-r----xr-x</code></dd>
<dt><kbd>chmod 416</kbd></dt>
<dd><code>-r----xrw-</code></dd>
<dt><kbd>chmod 417</kbd></dt>
<dd><code>-r----xrwx</code></dd>
<dt><kbd>chmod 420</kbd></dt>
<dd><code>-r---w----</code></dd>
<dt><kbd>chmod 421</kbd></dt>
<dd><code>-r---w---x</code></dd>
<dt><kbd>chmod 422</kbd></dt>
<dd><code>-r---w--w-</code></dd>
<dt><kbd>chmod 423</kbd></dt>
<dd><code>-r---w--wx</code></dd>
<dt><kbd>chmod 424</kbd></dt>
<dd><code>-r---w-r--</code></dd>
<dt><kbd>chmod 425</kbd></dt>
<dd><code>-r---w-r-x</code></dd>
<dt><kbd>chmod 426</kbd></dt>
<dd><code>-r---w-rw-</code></dd>
<dt><kbd>chmod 427</kbd></dt>
<dd><code>-r---w-rwx</code></dd>
<dt><kbd>chmod 430</kbd></dt>
<dd><code>-r---wx---</code></dd>
<dt><kbd>chmod 431</kbd></dt>
<dd><code>-r---wx--x</code></dd>
<dt><kbd>chmod 432</kbd></dt>
<dd><code>-r---wx-w-</code></dd>
<dt><kbd>chmod 433</kbd></dt>
<dd><code>-r---wx-wx</code></dd>
<dt><kbd>chmod 434</kbd></dt>
<dd><code>-r---wxr--</code></dd>
<dt><kbd>chmod 435</kbd></dt>
<dd><code>-r---wxr-x</code></dd>
<dt><kbd>chmod 436</kbd></dt>
<dd><code>-r---wxrw-</code></dd>
<dt><kbd>chmod 437</kbd></dt>
<dd><code>-r---wxrwx</code></dd>
<dt><kbd>chmod 440</kbd></dt>
<dd><code>-r--r-----</code></dd>
<dt><kbd>chmod 441</kbd></dt>
<dd><code>-r--r----x</code></dd>
<dt><kbd>chmod 442</kbd></dt>
<dd><code>-r--r---w-</code></dd>
<dt><kbd>chmod 443</kbd></dt>
<dd><code>-r--r---wx</code></dd>
<dt><kbd>chmod 444</kbd></dt>
<dd><code>-r--r--r--</code></dd>
<dt><kbd>chmod 445</kbd></dt>
<dd><code>-r--r--r-x</code></dd>
<dt><kbd>chmod 446</kbd></dt>
<dd><code>-r--r--rw-</code></dd>
<dt><kbd>chmod 447</kbd></dt>
<dd><code>-r--r--rwx</code></dd>
<dt><kbd>chmod 450</kbd></dt>
<dd><code>-r--r-x---</code></dd>
<dt><kbd>chmod 451</kbd></dt>
<dd><code>-r--r-x--x</code></dd>
<dt><kbd>chmod 452</kbd></dt>
<dd><code>-r--r-x-w-</code></dd>
<dt><kbd>chmod 453</kbd></dt>
<dd><code>-r--r-x-wx</code></dd>
<dt><kbd>chmod 454</kbd></dt>
<dd><code>-r--r-xr--</code></dd>
<dt><kbd>chmod 455</kbd></dt>
<dd><code>-r--r-xr-x</code></dd>
<dt><kbd>chmod 456</kbd></dt>
<dd><code>-r--r-xrw-</code></dd>
<dt><kbd>chmod 457</kbd></dt>
<dd><code>-r--r-xrwx</code></dd>
<dt><kbd>chmod 460</kbd></dt>
<dd><code>-r--rw----</code></dd>
<dt><kbd>chmod 461</kbd></dt>
<dd><code>-r--rw---x</code></dd>
<dt><kbd>chmod 462</kbd></dt>
<dd><code>-r--rw--w-</code></dd>
<dt><kbd>chmod 463</kbd></dt>
<dd><code>-r--rw--wx</code></dd>
<dt><kbd>chmod 464</kbd></dt>
<dd><code>-r--rw-r--</code></dd>
<dt><kbd>chmod 465</kbd></dt>
<dd><code>-r--rw-r-x</code></dd>
<dt><kbd>chmod 466</kbd></dt>
<dd><code>-r--rw-rw-</code></dd>
<dt><kbd>chmod 467</kbd></dt>
<dd><code>-r--rw-rwx</code></dd>
<dt><kbd>chmod 470</kbd></dt>
<dd><code>-r--rwx---</code></dd>
<dt><kbd>chmod 471</kbd></dt>
<dd><code>-r--rwx--x</code></dd>
<dt><kbd>chmod 472</kbd></dt>
<dd><code>-r--rwx-w-</code></dd>
<dt><kbd>chmod 473</kbd></dt>
<dd><code>-r--rwx-wx</code></dd>
<dt><kbd>chmod 474</kbd></dt>
<dd><code>-r--rwxr--</code></dd>
<dt><kbd>chmod 475</kbd></dt>
<dd><code>-r--rwxr-x</code></dd>
<dt><kbd>chmod 476</kbd></dt>
<dd><code>-r--rwxrw-</code></dd>
<dt><kbd>chmod 477</kbd></dt>
<dd><code>-r--rwxrwx</code></dd>
<dt><kbd>chmod 500</kbd></dt>
<dd><code>-r-x------</code></dd>
<dt><kbd>chmod 501</kbd></dt>
<dd><code>-r-x-----x</code></dd>
<dt><kbd>chmod 502</kbd></dt>
<dd><code>-r-x----w-</code></dd>
<dt><kbd>chmod 503</kbd></dt>
<dd><code>-r-x----wx</code></dd>
<dt><kbd>chmod 504</kbd></dt>
<dd><code>-r-x---r--</code></dd>
<dt><kbd>chmod 505</kbd></dt>
<dd><code>-r-x---r-x</code></dd>
<dt><kbd>chmod 506</kbd></dt>
<dd><code>-r-x---rw-</code></dd>
<dt><kbd>chmod 507</kbd></dt>
<dd><code>-r-x---rwx</code></dd>
<dt><kbd>chmod 510</kbd></dt>
<dd><code>-r-x--x---</code></dd>
<dt><kbd>chmod 511</kbd></dt>
<dd><code>-r-x--x--x</code></dd>
<dt><kbd>chmod 512</kbd></dt>
<dd><code>-r-x--x-w-</code></dd>
<dt><kbd>chmod 513</kbd></dt>
<dd><code>-r-x--x-wx</code></dd>
<dt><kbd>chmod 514</kbd></dt>
<dd><code>-r-x--xr--</code></dd>
<dt><kbd>chmod 515</kbd></dt>
<dd><code>-r-x--xr-x</code></dd>
<dt><kbd>chmod 516</kbd></dt>
<dd><code>-r-x--xrw-</code></dd>
<dt><kbd>chmod 517</kbd></dt>
<dd><code>-r-x--xrwx</code></dd>
<dt><kbd>chmod 520</kbd></dt>
<dd><code>-r-x-w----</code></dd>
<dt><kbd>chmod 521</kbd></dt>
<dd><code>-r-x-w---x</code></dd>
<dt><kbd>chmod 522</kbd></dt>
<dd><code>-r-x-w--w-</code></dd>
<dt><kbd>chmod 523</kbd></dt>
<dd><code>-r-x-w--wx</code></dd>
<dt><kbd>chmod 524</kbd></dt>
<dd><code>-r-x-w-r--</code></dd>
<dt><kbd>chmod 525</kbd></dt>
<dd><code>-r-x-w-r-x</code></dd>
<dt><kbd>chmod 526</kbd></dt>
<dd><code>-r-x-w-rw-</code></dd>
<dt><kbd>chmod 527</kbd></dt>
<dd><code>-r-x-w-rwx</code></dd>
<dt><kbd>chmod 530</kbd></dt>
<dd><code>-r-x-wx---</code></dd>
<dt><kbd>chmod 531</kbd></dt>
<dd><code>-r-x-wx--x</code></dd>
<dt><kbd>chmod 532</kbd></dt>
<dd><code>-r-x-wx-w-</code></dd>
<dt><kbd>chmod 533</kbd></dt>
<dd><code>-r-x-wx-wx</code></dd>
<dt><kbd>chmod 534</kbd></dt>
<dd><code>-r-x-wxr--</code></dd>
<dt><kbd>chmod 535</kbd></dt>
<dd><code>-r-x-wxr-x</code></dd>
<dt><kbd>chmod 536</kbd></dt>
<dd><code>-r-x-wxrw-</code></dd>
<dt><kbd>chmod 537</kbd></dt>
<dd><code>-r-x-wxrwx</code></dd>
<dt><kbd>chmod 540</kbd></dt>
<dd><code>-r-xr-----</code></dd>
<dt><kbd>chmod 541</kbd></dt>
<dd><code>-r-xr----x</code></dd>
<dt><kbd>chmod 542</kbd></dt>
<dd><code>-r-xr---w-</code></dd>
<dt><kbd>chmod 543</kbd></dt>
<dd><code>-r-xr---wx</code></dd>
<dt><kbd>chmod 544</kbd></dt>
<dd><code>-r-xr--r--</code></dd>
<dt><kbd>chmod 545</kbd></dt>
<dd><code>-r-xr--r-x</code></dd>
<dt><kbd>chmod 546</kbd></dt>
<dd><code>-r-xr--rw-</code></dd>
<dt><kbd>chmod 547</kbd></dt>
<dd><code>-r-xr--rwx</code></dd>
<dt><kbd>chmod 550</kbd></dt>
<dd><code>-r-xr-x---</code></dd>
<dt><kbd>chmod 551</kbd></dt>
<dd><code>-r-xr-x--x</code></dd>
<dt><kbd>chmod 552</kbd></dt>
<dd><code>-r-xr-x-w-</code></dd>
<dt><kbd>chmod 553</kbd></dt>
<dd><code>-r-xr-x-wx</code></dd>
<dt><kbd>chmod 554</kbd></dt>
<dd><code>-r-xr-xr--</code></dd>
<dt><kbd>chmod 555</kbd></dt>
<dd><code>-r-xr-xr-x</code></dd>
<dt><kbd>chmod 556</kbd></dt>
<dd><code>-r-xr-xrw-</code></dd>
<dt><kbd>chmod 557</kbd></dt>
<dd><code>-r-xr-xrwx</code></dd>
<dt><kbd>chmod 560</kbd></dt>
<dd><code>-r-xrw----</code></dd>
<dt><kbd>chmod 561</kbd></dt>
<dd><code>-r-xrw---x</code></dd>
<dt><kbd>chmod 562</kbd></dt>
<dd><code>-r-xrw--w-</code></dd>
<dt><kbd>chmod 563</kbd></dt>
<dd><code>-r-xrw--wx</code></dd>
<dt><kbd>chmod 564</kbd></dt>
<dd><code>-r-xrw-r--</code></dd>
<dt><kbd>chmod 565</kbd></dt>
<dd><code>-r-xrw-r-x</code></dd>
<dt><kbd>chmod 566</kbd></dt>
<dd><code>-r-xrw-rw-</code></dd>
<dt><kbd>chmod 567</kbd></dt>
<dd><code>-r-xrw-rwx</code></dd>
<dt><kbd>chmod 570</kbd></dt>
<dd><code>-r-xrwx---</code></dd>
<dt><kbd>chmod 571</kbd></dt>
<dd><code>-r-xrwx--x</code></dd>
<dt><kbd>chmod 572</kbd></dt>
<dd><code>-r-xrwx-w-</code></dd>
<dt><kbd>chmod 573</kbd></dt>
<dd><code>-r-xrwx-wx</code></dd>
<dt><kbd>chmod 574</kbd></dt>
<dd><code>-r-xrwxr--</code></dd>
<dt><kbd>chmod 575</kbd></dt>
<dd><code>-r-xrwxr-x</code></dd>
<dt><kbd>chmod 576</kbd></dt>
<dd><code>-r-xrwxrw-</code></dd>
<dt><kbd>chmod 577</kbd></dt>
<dd><code>-r-xrwxrwx</code></dd>
<dt><kbd>chmod 600</kbd></dt>
<dd><code>-rw-------</code></dd>
<dt><kbd>chmod 601</kbd></dt>
<dd><code>-rw------x</code></dd>
<dt><kbd>chmod 602</kbd></dt>
<dd><code>-rw-----w-</code></dd>
<dt><kbd>chmod 603</kbd></dt>
<dd><code>-rw-----wx</code></dd>
<dt><kbd>chmod 604</kbd></dt>
<dd><code>-rw----r--</code></dd>
<dt><kbd>chmod 605</kbd></dt>
<dd><code>-rw----r-x</code></dd>
<dt><kbd>chmod 606</kbd></dt>
<dd><code>-rw----rw-</code></dd>
<dt><kbd>chmod 607</kbd></dt>
<dd><code>-rw----rwx</code></dd>
<dt><kbd>chmod 610</kbd></dt>
<dd><code>-rw---x---</code></dd>
<dt><kbd>chmod 611</kbd></dt>
<dd><code>-rw---x--x</code></dd>
<dt><kbd>chmod 612</kbd></dt>
<dd><code>-rw---x-w-</code></dd>
<dt><kbd>chmod 613</kbd></dt>
<dd><code>-rw---x-wx</code></dd>
<dt><kbd>chmod 614</kbd></dt>
<dd><code>-rw---xr--</code></dd>
<dt><kbd>chmod 615</kbd></dt>
<dd><code>-rw---xr-x</code></dd>
<dt><kbd>chmod 616</kbd></dt>
<dd><code>-rw---xrw-</code></dd>
<dt><kbd>chmod 617</kbd></dt>
<dd><code>-rw---xrwx</code></dd>
<dt><kbd>chmod 620</kbd></dt>
<dd><code>-rw--w----</code></dd>
<dt><kbd>chmod 621</kbd></dt>
<dd><code>-rw--w---x</code></dd>
<dt><kbd>chmod 622</kbd></dt>
<dd><code>-rw--w--w-</code></dd>
<dt><kbd>chmod 623</kbd></dt>
<dd><code>-rw--w--wx</code></dd>
<dt><kbd>chmod 624</kbd></dt>
<dd><code>-rw--w-r--</code></dd>
<dt><kbd>chmod 625</kbd></dt>
<dd><code>-rw--w-r-x</code></dd>
<dt><kbd>chmod 626</kbd></dt>
<dd><code>-rw--w-rw-</code></dd>
<dt><kbd>chmod 627</kbd></dt>
<dd><code>-rw--w-rwx</code></dd>
<dt><kbd>chmod 630</kbd></dt>
<dd><code>-rw--wx---</code></dd>
<dt><kbd>chmod 631</kbd></dt>
<dd><code>-rw--wx--x</code></dd>
<dt><kbd>chmod 632</kbd></dt>
<dd><code>-rw--wx-w-</code></dd>
<dt><kbd>chmod 633</kbd></dt>
<dd><code>-rw--wx-wx</code></dd>
<dt><kbd>chmod 634</kbd></dt>
<dd><code>-rw--wxr--</code></dd>
<dt><kbd>chmod 635</kbd></dt>
<dd><code>-rw--wxr-x</code></dd>
<dt><kbd>chmod 636</kbd></dt>
<dd><code>-rw--wxrw-</code></dd>
<dt><kbd>chmod 637</kbd></dt>
<dd><code>-rw--wxrwx</code></dd>
<dt><kbd>chmod 640</kbd></dt>
<dd><code>-rw-r-----</code></dd>
<dt><kbd>chmod 641</kbd></dt>
<dd><code>-rw-r----x</code></dd>
<dt><kbd>chmod 642</kbd></dt>
<dd><code>-rw-r---w-</code></dd>
<dt><kbd>chmod 643</kbd></dt>
<dd><code>-rw-r---wx</code></dd>
<dt><kbd>chmod 644</kbd></dt>
<dd><code>-rw-r--r--</code></dd>
<dt><kbd>chmod 645</kbd></dt>
<dd><code>-rw-r--r-x</code></dd>
<dt><kbd>chmod 646</kbd></dt>
<dd><code>-rw-r--rw-</code></dd>
<dt><kbd>chmod 647</kbd></dt>
<dd><code>-rw-r--rwx</code></dd>
<dt><kbd>chmod 650</kbd></dt>
<dd><code>-rw-r-x---</code></dd>
<dt><kbd>chmod 651</kbd></dt>
<dd><code>-rw-r-x--x</code></dd>
<dt><kbd>chmod 652</kbd></dt>
<dd><code>-rw-r-x-w-</code></dd>
<dt><kbd>chmod 653</kbd></dt>
<dd><code>-rw-r-x-wx</code></dd>
<dt><kbd>chmod 654</kbd></dt>
<dd><code>-rw-r-xr--</code></dd>
<dt><kbd>chmod 655</kbd></dt>
<dd><code>-rw-r-xr-x</code></dd>
<dt><kbd>chmod 656</kbd></dt>
<dd><code>-rw-r-xrw-</code></dd>
<dt><kbd>chmod 657</kbd></dt>
<dd><code>-rw-r-xrwx</code></dd>
<dt><kbd>chmod 660</kbd></dt>
<dd><code>-rw-rw----</code></dd>
<dt><kbd>chmod 661</kbd></dt>
<dd><code>-rw-rw---x</code></dd>
<dt><kbd>chmod 662</kbd></dt>
<dd><code>-rw-rw--w-</code></dd>
<dt><kbd>chmod 663</kbd></dt>
<dd><code>-rw-rw--wx</code></dd>
<dt><kbd>chmod 664</kbd></dt>
<dd><code>-rw-rw-r--</code></dd>
<dt><kbd>chmod 665</kbd></dt>
<dd><code>-rw-rw-r-x</code></dd>
<dt><kbd>chmod 666</kbd></dt>
<dd><code>-rw-rw-rw-</code></dd>
<dt><kbd>chmod 667</kbd></dt>
<dd><code>-rw-rw-rwx</code></dd>
<dt><kbd>chmod 670</kbd></dt>
<dd><code>-rw-rwx---</code></dd>
<dt><kbd>chmod 671</kbd></dt>
<dd><code>-rw-rwx--x</code></dd>
<dt><kbd>chmod 672</kbd></dt>
<dd><code>-rw-rwx-w-</code></dd>
<dt><kbd>chmod 673</kbd></dt>
<dd><code>-rw-rwx-wx</code></dd>
<dt><kbd>chmod 674</kbd></dt>
<dd><code>-rw-rwxr--</code></dd>
<dt><kbd>chmod 675</kbd></dt>
<dd><code>-rw-rwxr-x</code></dd>
<dt><kbd>chmod 676</kbd></dt>
<dd><code>-rw-rwxrw-</code></dd>
<dt><kbd>chmod 677</kbd></dt>
<dd><code>-rw-rwxrwx</code></dd>
<dt><kbd>chmod 700</kbd></dt>
<dd><code>-rwx------</code></dd>
<dt><kbd>chmod 701</kbd></dt>
<dd><code>-rwx-----x</code></dd>
<dt><kbd>chmod 702</kbd></dt>
<dd><code>-rwx----w-</code></dd>
<dt><kbd>chmod 703</kbd></dt>
<dd><code>-rwx----wx</code></dd>
<dt><kbd>chmod 704</kbd></dt>
<dd><code>-rwx---r--</code></dd>
<dt><kbd>chmod 705</kbd></dt>
<dd><code>-rwx---r-x</code></dd>
<dt><kbd>chmod 706</kbd></dt>
<dd><code>-rwx---rw-</code></dd>
<dt><kbd>chmod 707</kbd></dt>
<dd><code>-rwx---rwx</code></dd>
<dt><kbd>chmod 710</kbd></dt>
<dd><code>-rwx--x---</code></dd>
<dt><kbd>chmod 711</kbd></dt>
<dd><code>-rwx--x--x</code></dd>
<dt><kbd>chmod 712</kbd></dt>
<dd><code>-rwx--x-w-</code></dd>
<dt><kbd>chmod 713</kbd></dt>
<dd><code>-rwx--x-wx</code></dd>
<dt><kbd>chmod 714</kbd></dt>
<dd><code>-rwx--xr--</code></dd>
<dt><kbd>chmod 715</kbd></dt>
<dd><code>-rwx--xr-x</code></dd>
<dt><kbd>chmod 716</kbd></dt>
<dd><code>-rwx--xrw-</code></dd>
<dt><kbd>chmod 717</kbd></dt>
<dd><code>-rwx--xrwx</code></dd>
<dt><kbd>chmod 720</kbd></dt>
<dd><code>-rwx-w----</code></dd>
<dt><kbd>chmod 721</kbd></dt>
<dd><code>-rwx-w---x</code></dd>
<dt><kbd>chmod 722</kbd></dt>
<dd><code>-rwx-w--w-</code></dd>
<dt><kbd>chmod 723</kbd></dt>
<dd><code>-rwx-w--wx</code></dd>
<dt><kbd>chmod 724</kbd></dt>
<dd><code>-rwx-w-r--</code></dd>
<dt><kbd>chmod 725</kbd></dt>
<dd><code>-rwx-w-r-x</code></dd>
<dt><kbd>chmod 726</kbd></dt>
<dd><code>-rwx-w-rw-</code></dd>
<dt><kbd>chmod 727</kbd></dt>
<dd><code>-rwx-w-rwx</code></dd>
<dt><kbd>chmod 730</kbd></dt>
<dd><code>-rwx-wx---</code></dd>
<dt><kbd>chmod 731</kbd></dt>
<dd><code>-rwx-wx--x</code></dd>
<dt><kbd>chmod 732</kbd></dt>
<dd><code>-rwx-wx-w-</code></dd>
<dt><kbd>chmod 733</kbd></dt>
<dd><code>-rwx-wx-wx</code></dd>
<dt><kbd>chmod 734</kbd></dt>
<dd><code>-rwx-wxr--</code></dd>
<dt><kbd>chmod 735</kbd></dt>
<dd><code>-rwx-wxr-x</code></dd>
<dt><kbd>chmod 736</kbd></dt>
<dd><code>-rwx-wxrw-</code></dd>
<dt><kbd>chmod 737</kbd></dt>
<dd><code>-rwx-wxrwx</code></dd>
<dt><kbd>chmod 740</kbd></dt>
<dd><code>-rwxr-----</code></dd>
<dt><kbd>chmod 741</kbd></dt>
<dd><code>-rwxr----x</code></dd>
<dt><kbd>chmod 742</kbd></dt>
<dd><code>-rwxr---w-</code></dd>
<dt><kbd>chmod 743</kbd></dt>
<dd><code>-rwxr---wx</code></dd>
<dt><kbd>chmod 744</kbd></dt>
<dd><code>-rwxr--r--</code></dd>
<dt><kbd>chmod 745</kbd></dt>
<dd><code>-rwxr--r-x</code></dd>
<dt><kbd>chmod 746</kbd></dt>
<dd><code>-rwxr--rw-</code></dd>
<dt><kbd>chmod 747</kbd></dt>
<dd><code>-rwxr--rwx</code></dd>
<dt><kbd>chmod 750</kbd></dt>
<dd><code>-rwxr-x---</code></dd>
<dt><kbd>chmod 751</kbd></dt>
<dd><code>-rwxr-x--x</code></dd>
<dt><kbd>chmod 752</kbd></dt>
<dd><code>-rwxr-x-w-</code></dd>
<dt><kbd>chmod 753</kbd></dt>
<dd><code>-rwxr-x-wx</code></dd>
<dt><kbd>chmod 754</kbd></dt>
<dd><code>-rwxr-xr--</code></dd>
<dt><kbd>chmod 755</kbd></dt>
<dd><code>-rwxr-xr-x</code></dd>
<dt><kbd>chmod 756</kbd></dt>
<dd><code>-rwxr-xrw-</code></dd>
<dt><kbd>chmod 757</kbd></dt>
<dd><code>-rwxr-xrwx</code></dd>
<dt><kbd>chmod 760</kbd></dt>
<dd><code>-rwxrw----</code></dd>
<dt><kbd>chmod 761</kbd></dt>
<dd><code>-rwxrw---x</code></dd>
<dt><kbd>chmod 762</kbd></dt>
<dd><code>-rwxrw--w-</code></dd>
<dt><kbd>chmod 763</kbd></dt>
<dd><code>-rwxrw--wx</code></dd>
<dt><kbd>chmod 764</kbd></dt>
<dd><code>-rwxrw-r--</code></dd>
<dt><kbd>chmod 765</kbd></dt>
<dd><code>-rwxrw-r-x</code></dd>
<dt><kbd>chmod 766</kbd></dt>
<dd><code>-rwxrw-rw-</code></dd>
<dt><kbd>chmod 767</kbd></dt>
<dd><code>-rwxrw-rwx</code></dd>
<dt><kbd>chmod 770</kbd></dt>
<dd><code>-rwxrwx---</code></dd>
<dt><kbd>chmod 771</kbd></dt>
<dd><code>-rwxrwx--x</code></dd>
<dt><kbd>chmod 772</kbd></dt>
<dd><code>-rwxrwx-w-</code></dd>
<dt><kbd>chmod 773</kbd></dt>
<dd><code>-rwxrwx-wx</code></dd>
<dt><kbd>chmod 774</kbd></dt>
<dd><code>-rwxrwxr--</code></dd>
<dt><kbd>chmod 775</kbd></dt>
<dd><code>-rwxrwxr-x</code></dd>
<dt><kbd>chmod 776</kbd></dt>
<dd><code>-rwxrwxrw-</code></dd>
<dt><kbd>chmod 777</kbd></dt>
<dd><code>-rwxrwxrwx</code></dd>
</dl>
<hr class="C" />




<h2>Congratulations!</h2>
<p>Here's my custom stat function, which I am definately not finished with, so check back in a couple days and if you find any improvements please hook me up with a comment!</p>

<pre>
function askapache_stat( $filename ) {
$p=@fileperms($filename);
$s=@stat($filename);
$str=&#039;&#039;;
$t=decoct($s[&#039;mode&#039;] &amp; 0170000);
&nbsp;
switch (octdec($t)) {
case 0140000: $str = &#039;s&#039;; $stat[&#039;type&#039;]=&#039;socket&#039;; break;
case 0120000: $str = &#039;l&#039;; $stat[&#039;type&#039;]=&#039;link&#039;; break;
case 0100000: $str = &#039;-&#039;; $stat[&#039;type&#039;]=&#039;file&#039;; break;
case 0060000: $str = &#039;b&#039;; $stat[&#039;type&#039;]=&#039;block&#039;; break;
case 0040000: $str = &#039;d&#039;; $stat[&#039;type&#039;]=&#039;dir&#039;; break;
case 0020000: $str = &#039;c&#039;; $stat[&#039;type&#039;]=&#039;char&#039;; break;
case 0010000: $str = &#039;p&#039;; $stat[&#039;type&#039;]=&#039;fifo&#039;; break;
default: $str = &#039;u&#039;; $stat[&#039;type&#039;]=&#039;unknown&#039;; break;
}
&nbsp;
$stat[&#039;type_octal&#039;] = sprintf("%07o", octdec($t));
&nbsp;
$str .= (($p&amp;0x0100)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0080)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0040)?(($p&amp;0x0800)?&#039;s&#039;:&#039;x&#039;):(($p&amp;0x0800)?&#039;S&#039;:&#039;-&#039;));
$str .= (($p&amp;0x0020)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0010)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0008)?(($p&amp;0x0400)?&#039;s&#039;:&#039;x&#039;):(($p&amp;0x0400)?&#039;S&#039;:&#039;-&#039;));
$str .= (($p&amp;0x0004)?&#039;r&#039;:&#039;-&#039;).(($p&amp;0x0002)?&#039;w&#039;:&#039;-&#039;).(($p&amp;0x0001)?(($p&amp;0x0200)?&#039;t&#039;:&#039;x&#039;):(($p&amp;0x0200)?&#039;T&#039;:&#039;-&#039;));
&nbsp;
$stat[&#039;default_umask&#039;]=sprintf("%04o",umask());
$stat[&#039;perm_human&#039;]=$str;
$stat[&#039;perm_octal1&#039;] = sprintf( "%o", ( $s[&#039;mode&#039;] &amp; 00777 ) );
$stat[&#039;perm_octal2&#039;] = sprintf("0%o", 0777 &amp; $p);
$stat[&#039;perm_dec&#039;] = sprintf("%04o", $p);
$stat[&#039;perm_mode&#039;]=$s[&#039;mode&#039;];   // File mode.
&nbsp;
$stat[&#039;file&#039;] = @realpath($filename);
$stat[&#039;basename&#039;] = basename( $filename );
&nbsp;
$stat[&#039;user_id&#039;] = $s[&#039;uid&#039;];
$stat[&#039;group_id&#039;] = $s[&#039;gid&#039;];
&nbsp;
$stat[&#039;device&#039;]=$s[&#039;dev&#039;];      // Device
$stat[&#039;device_number&#039;]=$s[&#039;rdev&#039;];    // Device number, if device.
$stat[&#039;inode&#039;]=$s[&#039;ino&#039;];      // File serial number
$stat[&#039;link_count&#039;]=$s[&#039;nlink&#039;];    // link count
if($stat[&#039;type&#039;]==&#039;link&#039;)$stat[&#039;link_to&#039;]=@readlink( $filename );
&nbsp;
$stat[&#039;size&#039;]=$s[&#039;size&#039;];    // Size of file, in bytes.
$stat[&#039;block_size&#039;]=$s[&#039;blksize&#039;];  // Optimal block size for I/O.
$stat[&#039;blocks&#039;]=$s[&#039;blocks&#039;];  // Number 512-byte blocks allocated
&nbsp;
$stat[&#039;time_access&#039;]=@date( &#039;Y M D H:i:s&#039;,$s[&#039;atime&#039;]);    // Time of last access.
$stat[&#039;time_modified&#039;]=@date( &#039;Y M D H:i:s&#039;,$s[&#039;mtime&#039;]);    // Time of last modification
$stat[&#039;time_created&#039;]=@date( &#039;Y M D H:i:s&#039;,$s[&#039;ctime&#039;]);    // Time of last status change
&nbsp;
clearstatcache();
return $stat;
}
&nbsp;
header(&#039;Content-Type: text/plain&#039;);
$stat=askapache_stat(__FILE__);
print_r($stat);
</pre>






<h3>Defining Permission Bits</h3>
<pre>
!defined(&#039;S_IFMT&#039;) &amp;&amp; define(&#039;S_IFMT&#039;, 0170000); //  mask for all types
!defined(&#039;S_IFSOCK&#039;) &amp;&amp; define(&#039;S_IFSOCK&#039;, 0140000); // type: socket
!defined(&#039;S_IFLNK&#039;) &amp;&amp; define(&#039;S_IFLNK&#039;, 0120000); // type:  symbolic link
!defined(&#039;S_IFREG&#039;) &amp;&amp; define(&#039;S_IFREG&#039;, 0100000); // type:  regular file
!defined(&#039;S_IFBLK&#039;) &amp;&amp; define(&#039;S_IFBLK&#039;, 0060000); // type:  block device
!defined(&#039;S_IFDIR&#039;) &amp;&amp; define(&#039;S_IFDIR&#039;, 0040000); // type:  directory
!defined(&#039;S_IFCHR&#039;) &amp;&amp; define(&#039;S_IFCHR&#039;, 0020000); // type:  character device
!defined(&#039;S_IFIFO&#039;) &amp;&amp; define(&#039;S_IFIFO&#039;, 0010000); // type:  fifo
&nbsp;
!defined(&#039;S_ISUID&#039;) &amp;&amp; define(&#039;S_ISUID&#039;, 0004000); // set-uid bit
!defined(&#039;S_ISGID&#039;) &amp;&amp; define(&#039;S_ISGID&#039;, 0002000); // set-gid bit
!defined(&#039;S_ISVTX&#039;) &amp;&amp; define(&#039;S_ISVTX&#039;, 0001000); // sticky bit
!defined(&#039;S_IRWXU&#039;) &amp;&amp; define(&#039;S_IRWXU&#039;, 00700); //  mask for owner permissions
!defined(&#039;S_IRUSR&#039;) &amp;&amp; define(&#039;S_IRUSR&#039;, 00400); //  owner: read permission
!defined(&#039;S_IWUSR&#039;) &amp;&amp; define(&#039;S_IWUSR&#039;, 00200); //  owner: write permission
!defined(&#039;S_IXUSR&#039;) &amp;&amp; define(&#039;S_IXUSR&#039;, 00100); //  owner: execute permission
!defined(&#039;S_IRWXG&#039;) &amp;&amp; define(&#039;S_IRWXG&#039;, 00070); //  mask for group permissions
!defined(&#039;S_IRGRP&#039;) &amp;&amp; define(&#039;S_IRGRP&#039;, 00040); //  group: read permission
!defined(&#039;S_IWGRP&#039;) &amp;&amp; define(&#039;S_IWGRP&#039;, 00020); //  group: write permission
!defined(&#039;S_IXGRP&#039;) &amp;&amp; define(&#039;S_IXGRP&#039;, 00010); //  group: execute permission
!defined(&#039;S_IRWXO&#039;) &amp;&amp; define(&#039;S_IRWXO&#039;, 00007); //  mask for others permissions
!defined(&#039;S_IROTH&#039;) &amp;&amp; define(&#039;S_IROTH&#039;, 00004); //  others:  read permission
!defined(&#039;S_IWOTH&#039;) &amp;&amp; define(&#039;S_IWOTH&#039;, 00002); //  others:  write permission
!defined(&#039;S_IXOTH&#039;) &amp;&amp; define(&#039;S_IXOTH&#039;, 00001); //  others:  execute permission
&nbsp;
!defined(&#039;S_IRWXUGO&#039;) &amp;&amp; define(&#039;S_IRWXUGO&#039;, (S_IRWXU | S_IRWXG | S_IRWXO));
!defined(&#039;S_IALLUGO&#039;) &amp;&amp; define(&#039;S_IALLUGO&#039;, (S_ISUID | S_ISGID | S_ISVTX | S_IRWXUGO));
!defined(&#039;S_IRUGO&#039;) &amp;&amp; define(&#039;S_IRUGO&#039;, (S_IRUSR | S_IRGRP | S_IROTH));
!defined(&#039;S_IWUGO&#039;) &amp;&amp; define(&#039;S_IWUGO&#039;, (S_IWUSR | S_IWGRP | S_IWOTH));
!defined(&#039;S_IXUGO&#039;) &amp;&amp; define(&#039;S_IXUGO&#039;, (S_IXUSR | S_IXGRP | S_IXOTH));
!defined(&#039;S_IRWUGO&#039;) &amp;&amp; define(&#039;S_IRWUGO&#039;, (S_IRUGO | S_IWUGO));
</pre>




<h2>How File Permissions Work</h2>
<p>When PHP is installed on your server by you or whoever runs the server, it uses the file permissions that are used by the Operating System running the server..  If you are smart or just lucky than you are running some type of BSD/Unix/Solaris/Linux/Sun based Operating system and PHP won't have any problems.  If you are running on a Locked, proprietary OS like Windows, PHP will still work but it has to use a lot of shortcuts and hacks to basically "Pretend" to act like the OS is BSD/Unix, and some key features just won't be available.</p>

<h2>The OS Permission Bits</h2>
<p>Here's the file permissions my Linux server uses, and which PHP automatically uses.  The code basically just defines the default permissions for files, and defines the file atributes for each file that you can access by using the stat function, which I've improved upon to make things easier.</p>
<p>Download: <a href='http://uploads.askapache.com/2008/11/stat.h' title="POSIX Standard: 5.6 File Characteristics">POSIX Standard: 5.6 File Characteristics<code>sys/stat.h</code></a></p>
<h3>Protection bits for File Owner</h3>
<pre>
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
</pre>

<h3>Protection bits for File Group</h3>
<pre>
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
</pre>

<h3>Protection bits for All Others</h3>
<pre>
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
</pre>


<h2>Some Example Permissions</h2>
<p><code>0477</code>  // owner has read only, other and group has rwx
<code>0677</code>  // owner has rw only, other and group has rwx</p>

<p><code>0444</code>  // all have read only
<code>0666</code>  // all have rw only</p>

<p><code>0400</code>  // owner has read only, group and others have no permission
<code>0600</code> // owner has rw only, group and others have no permission</p>

<p><code>0470</code>  // owner has read only, group has rwx, others have no permission
<code>0407</code>  // owner has read only, other has rwx, group has no permission</p>

<p><code>0670</code>  // owner has rw only, group has rwx, others have no permission
<code>0607</code>  // owner has rw only, group has no permission and others have rwx</p>


<h2>What's a File</h2>
<p>A file is not merely its contents, a name, and a file type. A file also has an owner (a user ID), a group (a group ID), permissions (what the owner can do with the file, what people in the group can do, and what everyone else can do), various timestamps, and other information. Collectively, we call these a file's attributes.</p>

<h2>Structure of File Mode Bits</h2>
<p>The file mode bits have two parts: the file permission bits, which control ordinary access to the file, and special mode bits, which affect only some files.</p>
<p>There are three kinds of permissions that a user can have for a file:</p>
<ol>
<li>permission to read the file. For directories, this means permission to list the contents of the directory.</li>
<li>permission to write to (change) the file. For directories, this means permission to create and remove files in the directory.</li>
<li>permission to execute the file (run it as a program). For directories, this means permission to access files in the directory.</li>
</ol>

<p>There are three categories of users who may have different permissions to perform any of the above operations on a file:</p>
<ol>
<li>the file's owner.</li>
<li>other users who are in the file's group</li>
<li>everyone else.</li>
</ol>

<p>Files are given an owner and group when they are created. Usually the owner is the current user and the group is the group of the directory the file is in, but this varies with the operating system, the file system the file is created on, and the way the file is created. You can change the owner and group of a file by using the <strong>chown</strong> and <strong>chgrp</strong> commands.</p>
<p>In addition to the three sets of three permissions listed above, the file mode bits have three special components, which affect only executable files (programs) and, on most systems, directories:</p>
<ol>
<li>Set the process's effective user ID to that of the file upon execution (called the set-user-ID bit, or sometimes the setuid bit). For directories on a few systems, give files created in the directory the same owner as the directory, no matter who creates them, and set the set-user-ID bit of newly-created subdirectories.</li>
<li>Set the process's effective group ID to that of the file upon execution (called the set-group-ID bit, or sometimes the setgid bit). For directories on most systems, give files created in the directory the same group as the directory, no matter what group the user who creates them is in, and set the set-group-ID bit of newly-created subdirectories.</li>
<li>Prevent unprivileged users from removing or renaming a file in a directory unless they own the file or the directory; this is called the restricted deletion flag for the directory, and is commonly found on world-writable directories like /tmp.</li>
</ol>

<p>For regular files on some older systems, save the program's text image on the swap device so it will load more quickly when run; this is called the <code>sticky bit</code>.</p>



<h2>Setting Permissions</h2>
<p>The basic symbolic operations on a file's permissions are adding, removing, and setting the permission that certain users have to read, write, and execute or search the file. These operations have the following format:</p>
<p><code>users operation permissions</code></p>

<p>The spaces between the three parts above are shown for readability only; symbolic modes cannot contain spaces.  The users part tells which users' access to the file is changed. It consists of one or more of the following letters (or it can be empty). When more than one of these letters is given, the order that they are in does not matter.</p>
<ul>
<li><strong>u</strong> - the user who owns the file.</li>
<li><strong>g</strong> - other users who are in the file's group.</li>
<li><strong>o</strong> - all other users.</li>
<li><strong>a</strong> - all users; the same as ugo.</li>
</ul>

<p>The operation part tells how to change the affected users' access to the file, and is one of the following symbols:</p>
<ul>
<li><strong>+</strong> - to add the permissions to whatever permissions the users already have for the file.</li>
<li><strong>-</strong> - to remove the permissions from whatever permissions the users already have for the file.</li>
<li><strong>=</strong> - to make the permissions the only permissions that the users have for the file.</li>
</ul>

<p>The permissions part tells what kind of access to the file should be changed; it is normally zero or more of the following letters. As with the users part, the order does not matter when more than one letter is given. Omitting the permissions part is useful only with the = operation, where it gives the specified users no access at all to the file.</p>

<ul>
<li><strong>r</strong> - the permission the users have to read the file.</li>
<li><strong>w</strong> - the permission the users have to write to the file.</li>
<li><strong>x</strong> - the permission the users have to execute the file, or search it if it is a directory.</li>
</ul>

<p>For example, to give everyone permission to read and write a regular file, but not to execute it, use:</p>
<pre>
a=rw
</pre>

<p>To remove write permission for all users other than the file's owner, use:</p>
<pre>
go-w
</pre>

<p>The above command does not affect the access that the owner of the file has to it, nor does it affect whether other users can read or execute the file.</p>

<p>To give everyone except a file's owner no permission to do anything with that file, use the mode below. Other users could still remove the file, if they have write permission on the directory it is in.</p>
<pre>
go=
</pre>

<p>Another way to specify the same thing is:</p>
<pre>
og-rwx
</pre>



<h2>Copying Existing Permissions</h2>
<p>You can base a file's permissions on its existing permissions. To do this, instead of using a series of <strong>r, w, or x</strong> letters after the operator, you use the letter <strong>u, g, or o</strong>. For example, the mode</p>
<pre>
o+g
</pre>

<p>adds the permissions for users who are in a file's group to the permissions that other users have for the file. Thus, if the file started out as mode 664 (rw-rw-r--), the above mode would change it to mode 666 (rw-rw-rw-). If the file had started out as mode 741 (rwxr----x), the above mode would change it to mode 745 (rwxr--r-x). The - and = operations work analogously.</p>






<h2>Umask and Protection</h2>
<p>If the users part of a symbolic mode is omitted, it defaults to a (affect all users), except that any permissions that are set in the system variable umask are not affected. The value of umask can be set using the umask command. Its default value varies from system to system.</p>

<p>Omitting the users part of a symbolic mode is generally not useful with operations other than +. It is useful with + because it allows you to use umask as an easily customizable protection against giving away more permission to files than you intended to.  As an example, if umask has the value 2, which removes write permission for users who are not in the file's group, then the mode:</p>
<pre>
+w
</pre>

<p>adds permission to write to the file to its owner and to other users who are in the file's group, but not to other users. In contrast, the mode:</p>
<pre>
a+w
</pre>

<p>ignores umask, and does give write permission for the file to all users.</p>




<h2>Directories, Set-User-ID and Set-Group-ID Bits</h2>
<p>On most systems, if a directory's set-group-ID bit is set, newly created subfiles inherit the same group as the directory, and newly created subdirectories inherit the set-group-ID bit of the parent directory. On a few systems, a directory's set-user-ID bit has a similar effect on the ownership of new subfiles and the set-user-ID bits of new subdirectories. These mechanisms let users share files more easily, by lessening the need to use chmod or chown to share new files.</p>

<p>These convenience mechanisms rely on the set-user-ID and set-group-ID bits of directories. If commands like chmod and mkdir routinely cleared these bits on directories, the mechanisms would be less convenient and it would be harder to share files. Therefore, a command like chmod does not affect the set-user-ID or set-group-ID bits of a directory unless the user specifically mentions them in a symbolic mode, or sets them in a numeric mode. For example, on systems that support set-group-ID inheritance:</p>

<pre>
# These commands leave the set-user-ID and
# set-group-ID bits of the subdirectories alone,
# so that they retain their default values.
mkdir A B C
chmod 755 A
chmod 0755 B
chmod u=rwx,go=rx C
mkdir -m 755 D
mkdir -m 0755 E
mkdir -m u=rwx,go=rx F
</pre>

<p>If you want to try to set these bits, you must mention them explicitly in the symbolic or numeric modes, e.g.:</p>
<pre>
# These commands try to set the set-user-ID
# and set-group-ID bits of the subdirectories.
mkdir G H
chmod 6755 G
chmod u=rwx,go=rx,a+s H
mkdir -m 6755 I
mkdir -m u=rwx,go=rx,a+s J
</pre>

<p>If you want to try to clear these bits, you must mention them explicitly in a symbolic mode, e.g.:</p>
<pre>
# This command tries to clear the set-user-ID
# and set-group-ID bits of the directory D.
chmod a-s D
</pre>











<h2>Numeric Modes</h2>
<p>The permissions granted to the user, to other users in the file's group, and to other users not in the file's group each require three bits, which are represented as one octal digit. The three special mode bits also require one bit each, and they are as a group represented as another octal digit. Here is how the bits are arranged, starting with the lowest valued bit:</p>

<h3>Other users not in the file's group:</h3>
<pre>
1 Execute/search
2 Write
4 Read
</pre>

<h3>Other users in the file's group:</h3>
<pre>
10 Execute/search
20 Write
40 Read
</pre>

<h3>The file's owner:</h3>
<pre>
100 Execute/search
200 Write
400 Read
</pre>

<h3>Special mode bits:</h3>
<pre>
1000 Restricted deletion flag or sticky bit
2000 Set group ID on execution
4000 Set user ID on execution
</pre>

<p>For example, numeric <code>mode 4755</code> corresponds to symbolic mode <code>u=rwxs,go=rx</code>, and numeric m<code>ode 664</code> corresponds to symbolic mode <code>ug=rw,o=r</code>. Numeric <code>mode 0</code> corresponds to symbolic mode <code>a=</code>.</p>




<h2>Apache's Internal Bits (hex)</h2>
<pre>
#define APR_FPROT_USETID   0x8000 /* Set user id */
#define APR_FPROT_UREAD   0x0400 /* Read by user */
#define APR_FPROT_UWRITE   0x0200 /* Write by user */
#define APR_FPROT_UEXECUTE 0x0100 /* Execute by user */
&nbsp;
#define APR_FPROT_GSETID   0x4000 /* Set group id */
#define APR_FPROT_GREAD   0x0040 /* Read by group */
#define APR_FPROT_GWRITE   0x0020 /* Write by group */
#define APR_FPROT_GEXECUTE 0x0010 /* Execute by group */
&nbsp;
#define APR_FPROT_WSTICKY 0x2000 /* Sticky bit */
#define APR_FPROT_WREAD   0x0004 /* Read by others */
#define APR_FPROT_WWRITE 0x0002 /* Write by others */
#define APR_FPROT_WEXECUTE 0x0001 /* Execute by others */
&nbsp;
#define APR_FPROT_OS_DEFAULT  0x0FFF /* use OS&#039;s default permissions */
&nbsp;
/* additional permission flags for apr_file_copy  and apr_file_append */
#define APR_FPROT_FILE_SOURCE_PERMS 0x1000 /* Copy source file&#039;s permissions */
</pre>


<p>Download: <a href='http://uploads.askapache.com/2008/11/fileacc.c' title="A file to put ALL of the accessor functions for apr_file_t types"><code>httpd-2.2.10/srclib/apr/file_io/unix/fileacc.c</code></a> Here's some interesting bitmasking done by Apache that uses the defined bits set earlier by stat.h</p>
<pre>
apr_unix_perms2mode(perms){
 mode=0;
 if (perms &amp; APR_USETID) mode |= S_ISUID;
 if (perms &amp; APR_UREAD)  mode |= S_IRUSR;
 if (perms &amp; APR_UWRITE) mode |= S_IWUSR;
 if (perms &amp; APR_UEXECUTE) mode |= S_IXUSR;
&nbsp;
 if (perms &amp; APR_GSETID) mode |= S_ISGID;
 if (perms &amp; APR_GREAD)  mode |= S_IRGRP;
 if (perms &amp; APR_GWRITE) mode |= S_IWGRP;
 if (perms &amp; APR_GEXECUTE) mode |= S_IXGRP;
&nbsp;
 if (perms &amp; APR_WSTICKY) mode |= S_ISVTX;
 if (perms &amp; APR_WREAD)  mode |= S_IROTH;
 if (perms &amp; APR_WWRITE) mode |= S_IWOTH;
 if (perms &amp; APR_WEXECUTE) mode |= S_IXOTH;
 return mode;
}
&nbsp;
apr_unix_mode2perms(mode){
 perms = 0;
 if (mode &amp; S_ISUID)perms |= APR_USETID;
 if (mode &amp; S_IRUSR)perms |= APR_UREAD;
 if (mode &amp; S_IWUSR)perms |= APR_UWRITE;
 if (mode &amp; S_IXUSR)perms |= APR_UEXECUTE;
&nbsp;
 if (mode &amp; S_ISGID)perms |= APR_GSETID;
 if (mode &amp; S_IRGRP)perms |= APR_GREAD;
 if (mode &amp; S_IWGRP)perms |= APR_GWRITE;
 if (mode &amp; S_IXGRP)perms |= APR_GEXECUTE;
&nbsp;
 if (mode &amp; S_ISVTX)perms |= APR_WSTICKY;
 if (mode &amp; S_IROTH)perms |= APR_WREAD;
 if (mode &amp; S_IWOTH)perms |= APR_WWRITE;
 if (mode &amp; S_IXOTH)perms |= APR_WEXECUTE;
 return perms;
}
</pre>





<h2>umask</h2>
<pre>
umask(int mask){
 arg1;
 int oldumask;
 int arg_count = ZEND_NUM_ARGS();
 oldumask = umask(077);
&nbsp;
 if (BG(umask) == -1) BG(umask) = oldumask;
 if (arg_count == 0) umask(oldumask);
&nbsp;
 convert_to_long_ex(arg1);
 umask(Z_LVAL_PP(arg1));
 RETURN_LONG(oldumask);
}
</pre>

















<h2>File Attributes</h2>
<p>Each file will have attributes based on the type of OS.. Using the stat command you can view them.</p>

<h3>Viewing stat results</h3>
<pre>
* %a - Access rights in octal
* %A - Access rights in human readable form
* %b - Number of blocks allocated (see %B)
* %B - The size in bytes of each block reported by %b
* %d - Device number in decimal
* %D - Device number in hex
* %f - Raw mode in hex
* %F - File type
* %g - Group ID of owner
* %G - Group name of owner
* %h - Number of hard links
* %i - Inode number
* %n - File name
* %N - Quoted file name with dereference if symbolic link
* %o - I/O block size
* %s - Total size, in bytes
* %t - Major device type in hex
* %T - Minor device type in hex
* %u - User ID of owner
* %U - User name of owner
* %x - Time of last access
* %X - Time of last access as seconds since Epoch
* %y - Time of last modification
* %Y - Time of last modification as seconds since Epoch
* %z - Time of last change
* %Z - Time of last change as seconds since Epoch
</pre>




<h2>The OS Attribute Bits</h2>
<p>These defined values are what allows your operating system to determine the type of file being accessed. </p>
<pre>
#define S_IFMT   00170000  /* These bits determine file type. */
#define S_IFSOCK 0140000  /* Socket file */
#define S_IFLNK   0120000  /* Symbolic Link */
#define S_IFREG   0100000  /* Regular file */
#define S_IFDIR   0040000  /* Directory */
#define S_IFIFO  0010000   /* FIFO first-in-first-out file */
&nbsp;
/* Such devices can be read either a character at a time or a "block" (many characters) at a time,
hence we say there are block special files and character special files. */
#define S_IFBLK   0060000  /* Block device */
#define S_IFCHR  0020000  /* Character device */
</pre>

<h3>Special Permission Bits</h3>
<pre>
#define S_ISUID  0004000  /* Set user ID on execution.  */
#define S_ISGID  0002000  /* Set group ID on execution.  */
#define S_ISVTX  0001000 /* Save swapped text after use (sticky).  */
</pre>

<h3>Bitmasking to determine Filetype</h3>
<pre>
#define S_ISLNK(m) (((m) &amp; S_IFMT) == S_IFLNK)
#define S_ISREG(m) (((m) &amp; S_IFMT) == S_IFREG)
#define S_ISDIR(m) (((m) &amp; S_IFMT) == S_IFDIR)
#define S_ISCHR(m) (((m) &amp; S_IFMT) == S_IFCHR)
#define S_ISBLK(m) (((m) &amp; S_IFMT) == S_IFBLK)
#define S_ISFIFO(m) (((m) &amp; S_IFMT) == S_IFIFO)
#define S_ISSOCK(m) (((m) &amp; S_IFMT) == S_IFSOCK)
</pre>

<h3>Default Permission Masks</h3>
<pre>
#define S_IRWXUGO (S_IRWXU|S_IRWXG|S_IRWXO)
#define S_IALLUGO (S_ISUID|S_ISGID|S_ISVTX|S_IRWXUGO)
#define S_IRUGO  (S_IRUSR|S_IRGRP|S_IROTH)
#define S_IWUGO  (S_IWUSR|S_IWGRP|S_IWOTH)
#define S_IXUGO  (S_IXUSR|S_IXGRP|S_IXOTH)
</pre>


<p>Download: <a href='http://uploads.askapache.com/2008/11/filestat.c' title="handles file stat"><code>httpd-2.2.10/srclib/apr/file_io/unix/filestat.c</code></a>, this file shows a simple way to determine the type of file.</p>
<pre>
filetype_from_mode(mode){
 type;
 switch (mode &amp; S_IFMT) {
  case S_IFREG:  type = APR_REG;  break;
  case S_IFDIR:  type = APR_DIR;  break;
  case S_IFLNK:  type = APR_LNK;  break;
&nbsp;
  case S_IFCHR:  type = APR_CHR;  break;
  case S_IFBLK:  type = APR_BLK;  break;
  case S_IFFIFO: type = APR_PIPE; break;
  case S_IFSOCK: type = APR_SOCK; break;
  default: type = APR_UNKFILE;
 }
 return type;
}
</pre>

<h3>Apache Stat Bits</h3>
<pre>
#define APR_FINFO_LINK  0x00000001 /* Stat the link not the file itself if it is a link */
#define APR_FINFO_MTIME  0x00000010 /* Modification Time */
#define APR_FINFO_CTIME  0x00000020 /* Creation or inode-changed time */
#define APR_FINFO_ATIME  0x00000040 /* Access Time */
#define APR_FINFO_SIZE  0x00000100 /* Size of the file */
#define APR_FINFO_CSIZE  0x00000200 /* Storage size consumed by the file */
#define APR_FINFO_DEV  0x00001000 /* Device */
#define APR_FINFO_INODE  0x00002000 /* Inode */
#define APR_FINFO_NLINK  0x00004000 /* Number of links */
#define APR_FINFO_TYPE  0x00008000 /* Type */
#define APR_FINFO_USER  0x00010000 /* User */
#define APR_FINFO_GROUP  0x00020000 /* Group */
#define APR_FINFO_UPROT  0x00100000 /* User protection bits */
#define APR_FINFO_GPROT  0x00200000 /* Group protection bits */
#define APR_FINFO_WPROT  0x00400000 /* World protection bits */
#define APR_FINFO_ICASE  0x01000000 /* if dev is case insensitive */
#define APR_FINFO_NAME  0x02000000 /* name in proper case */
#define APR_FINFO_MIN  0x00008170 /* type, mtime, ctime, atime, size */
#define APR_FINFO_IDENT  0x00003000 /* dev and inode */
#define APR_FINFO_OWNER  0x00030000 /* user and group */
#define APR_FINFO_PROT  0x00700000 /* all protections */
#define APR_FINFO_NORM  0x0073b170 /* an atomic unix apr_stat() */
#define APR_FINFO_DIRENT 0x02000000 /* an atomic unix apr_dir_read() */
</pre>

<h3>The Apache file information structure.</h3>
<pre>
apr_uid_t user;  /* The user id that owns the file */
apr_gid_t group;  /* The group id that owns the file */
apr_ino_t inode; /* The inode of the file. */
apr_dev_t device; /* The id of the device the file is on. */
apr_int32_t nlink; /* The number of hard links to the file. */
apr_off_t size;  /* The size of the file */
apr_off_t csize; /* The storage size consumed by the file */
apr_time_t atime; /* The time the file was last accessed */
apr_time_t mtime; /* The time the file was last modified */
apr_time_t ctime; /* The time the file was created, or the inode was last changed */
const char *fname; /* The pathname of the file (possibly unrooted) */
const char *name; /* The file&#039;s name (no path) in filesystem case */
</pre>



<h3>File Time Attributes</h3>
<blockquote><cite><a href="http://php.net/manual/en/function.touch.php">touch</a></cite>
<p>If changing both the access and modification times to the current time, touch can change the timestamps for files that the user running it does not own but has write permission for. Otherwise, the user must own the files.</p>
</blockquote>

<p>Although touch provides options for changing two of the times the times of last access and modification of a file, there is actually a third one as well: the inode change time. This is often referred to as a file's ctime. The inode change time represents the time when the file's meta-information last changed. One common example of this is when the permissions of a file change. Changing the permissions doesn't access the file, so the atime doesn't change, nor does it modify the file, so the mtime doesn't change. Yet, something about the file itself has changed, and this must be noted somewhere. This is the job of the ctime field. This is necessary, so that, for example, a backup program can make a fresh copy of the file, including the new permissions value. Another operation that modifies a file's ctime without affecting the others is renaming. In any case, it is not possible, in normal operations, for a user to change the ctime field to a user-specified value.</p>
</blockquote>













<a name="Shared_hosting_user_security"></a>
<h2>Shared hosting user security </h2>
<ul>
	<li><a href="#Shared_hosting_user_security">Shared hosting user security</a></li>
	<li><a href="#Apache_Security">Apache Security</a></li>
	<li><a href="#Multiuser_security_setup_example">Multiuser security setup example</a></li>
	<li><a href="#SSH_key_fingerprints">SSH key fingerprints</a></li>
	<li><a href="#External_Links">External Links</a></li>
</ul>
<p>WebHost allows you to create multiple users per account. Each user can have domain assigned to its home home directory accessible via FTP or SSH/SCP. The problem with multiple users on the same account is that they share the same default unix group, and default permissions allow their files to be easily modified by the members of this group. Usually this doesn't pose a problem as each user is probably trusted by account owner to not to mess with others files, but if one of the users have their web application hacked then all other users on the same account will be in danger. </p>
<p>By default all files in your account are created with 644 privileges and directories are with 775. That means any user can read your files and any user from the same account can move and add files in your freshly made directories. Your home directory is different, though. By default it carries 751 attribute meaning that only members of your group can see your files, but can't add any new. These group access schemes are possible, because every user in your account has its primary/default group set to "pgxxxxxx", which is assigned to every new file you create by default. The normal way to secure users from web-intrusion is to assign a separate group to the web-server user, removing it from default group. This way, exploited scripts will not be able to traverse into home directories of other users on your account. To allow account users to update centralized web-site they could be added to web-site group explicitly. But this "normal way" doesn't work with DreamHost, because you can't delete web-user from the default group and unless you set access for every new file explicitly, it will be possible for an intruder to read it. </p>
<p>To make managing privileges easier in interactive sessions "umask 007" command can be specified in your .bash_profile - this makes all new files carry xx0 mask. You also need to control your scripts (web based or cron/shell) so that they set mask for critical files explicitly. To secure account users from access by means of hacked user script you would also like to define another group for every user in your account and change group ownership of the user's home directory to that group with "set gid" bit set (and optional umask 007 in .bash_profile). </p>
<p>Therefore, to secure your users from web-intrusion you need to: </p>
<ol>
	<li>Add a separate user and group for every domain where apache will be running </li>
	<li>Add a separate group for other user accounts </li>
	<li>Change the default group for new files created by your users by changing the group of their home directory and setting "set gid" bit for it (it is impossible to do this with FTP accounts, therefore you will need to login in each account via SSH) </li>
	<li>Add users who need access to web-site into the web-user group </li>
	<li>Optionally set umask 007 in .bash_profile for every user to tweak default WebHost775/664 permissions to something like 770/660 for directories and files that are not meant to be read by Apache (660 could also be used for all web scripts including .php as they are not read by dhapache CGI, but merely executed) </li>
</ol>
<h2><a name="Apache_Security"></a>Apache Security </h2>
<p>All your web files that need to be read by Apache should be readable by everyone as Apache itself is run under dhapache user. However, executable scripts like .php are executed under your own user and do not have to be world readable as they are not actually read by Apache, but executed via <a href="http://en.wikipedia.org/wiki/suEXEC">suEXEC</a>. Quite the opposite - to prevent your code or database settings from being messed by any third-parties you SHOULD set permissions to these files explicitly to something like 640 or even 600 depending on who do you trust. </p>
<a name="Multiuser_security_setup_example"></a>
<h2>Multiuser security setup example </h2>
<p>For our example, we will create a <em>rainforce_www</em> user and a <em>aapp_www</em> group for serving web files with apache and setup a <em>rainforce</em> user with a 'aapp<em> group to manage mail and keep other files on DH privately. Since these records already exist, you will need to subsitute your own names.</em> </p>
<ul>
	<li>Login to create the users <em>rainforce_www</em> and <em>rainforce</em> with shell access. </li>
	<li>Create two groups - <em>aapp_www</em> and <em>aapp</em>. Note that users created in previous step are still members of the same default <em>pg</em>xxxxxx group. </li>
	<li>Add <em>rainforce_www</em> to 'the 'aapp_www<em> group and </em>rainforce<em> to both the </em>aapp_www<em> and </em>aapp<em> groups</em> </li>
	<li>Move your domain to <em>rainforce_www</em> account (mine is rainforce.org) </li>
	<li>Now login to SSH with your <em>rainforce_www</em> user and change the default group for your home directory with "sgid" bit set to make all current and new files/directories created in this directory have the same <em>aapp_www</em> group. </li>
</ul>
<pre>
 $ chgrp -R aapp_www .
 $ chmod 2751 .
 $ chmod 2771 rainforce.org
</pre>
<p>By setting 2771 the directory will be writable by the owner, the group and will be only executable by others. The contents of an executable only directory cannot be listed, but the files inside it can be read (if the permissions of the file allow it). It is important that the directory can be executable in order to allow static content (e.g. .html files) inside it to be read. Remember that directories you don't want anyone to have web access to, should be 0770 (writable by the owner and group, or 0750 writable by the owner and readable by group). Such strict permissions should by applied to password files, php include files or databases files (such as SQLite, BDB, etc). </p>
<ul>
	<li>Do the same for <em>rainforce</em> user, but specify <em>aapp</em> group instead. </li>
</ul>
<pre>
 $ chgrp -R aapp .
 $ chmod 2751 .
</pre>
<ul>
	<li>Optionally modify umask in .bash_profile in user's home to 007 to make all files created by this user have 660 permissions set by default. If you want that newly created files by accessible by the web, you need to manually setup it's permissions to 664. </li>
</ul>
<p>Now I can login as the user "rainforce" and update the web-site in the ../rainforce_www/rainforce.org directory. There is one more setup needed. Because files copied from other accounts can have 644 permissions set instead of 664, you need a script which will update permissions to 664 or 660 to allow other group members modify such files. </p>
<h2><a name="SSH_key_fingerprints"></a>SSH key fingerprints </h2>
<p>Just gen your own I guess </p>
<h2>External Links </h2>
<ul>
	<li><a href="http://oldfield.wattle.id.au/luv/permissions.html" title="http://oldfield.wattle.id.au/luv/permissions.html" rel="nofollow">Introduction to Unix file permissions</a> </li>
	<li><a href="http://www.perlfect.com/articles/chmod.shtml" title="http://www.perlfect.com/articles/chmod.shtml" rel="nofollow">Understanding UNIX permission and chmod</a> </li>
</ul>
<p>Original Article from <a href="http://wiki.dreamhost.com/index.php?title=Security">DreamHost Wiki</a></p>
<p>Content is available under <a href="http://www.gnu.org/copyleft/fdl.html" class="external " title="http://www.gnu.org/copyleft/fdl.html" rel="nofollow">GNU Free Documentation License 1.2</a>.</p>





<h2>Example File Permission Bits</h2>

<h3><code>/usr/lib/w3m/cgi-bin/dirlist.cgi</code></h3>
<pre>
sub utype {
  local($_) = @_;
  local(%T) = (
    0010000, &#039;PIPE&#039;,
    0020000, &#039;CHR&#039;,
    0040000, &#039;DIR&#039;,
    0060000, &#039;BLK&#039;,
    0100000, &#039;FILE&#039;,
    0120000, &#039;LINK&#039;,
    0140000, &#039;SOCK&#039;,
  );
  return $T{($_ &amp; 0170000)} || &#039;FILE&#039;;
}
&nbsp;
sub umode {
  local($_) = @_;
  local(%T) = (
    0010000, &#039;p&#039;,
    0020000, &#039;c&#039;,
    0040000, &#039;d&#039;,
    0060000, &#039;b&#039;,
    0100000, &#039;-&#039;,
    0120000, &#039;l&#039;,
    0140000, &#039;s&#039;,
  );
&nbsp;
  return ($T{($_ &amp; 0170000)} || &#039;-&#039;)
     . (($_ &amp; 00400) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00200) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 04000) ? &#039;s&#039; :
       (($_ &amp; 00100) ? &#039;x&#039; : &#039;-&#039;))
     . (($_ &amp; 00040) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00020) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 02000) ? &#039;s&#039; :
       (($_ &amp; 00010) ? &#039;x&#039; : &#039;-&#039;))
     . (($_ &amp; 00004) ? &#039;r&#039; : &#039;-&#039;)
     . (($_ &amp; 00002) ? &#039;w&#039; : &#039;-&#039;)
     . (($_ &amp; 01000) ? &#039;t&#039; :
       (($_ &amp; 00001) ? &#039;x&#039; : &#039;-&#039;));
}
</pre>

<h3><code>/usr/lib/perl/5.8.4/linux/stat.ph</code></h3>
<pre>
        eval &#039;sub S_IFMT () {00170000;}&#039; unless defined(&amp;S_IFMT);
        eval &#039;sub S_IFSOCK () {0140000;}&#039; unless defined(&amp;S_IFSOCK);
        eval &#039;sub S_IFLNK () {0120000;}&#039; unless defined(&amp;S_IFLNK);
        eval &#039;sub S_IFREG () {0100000;}&#039; unless defined(&amp;S_IFREG);
        eval &#039;sub S_IFBLK () {0060000;}&#039; unless defined(&amp;S_IFBLK);
        eval &#039;sub S_IFDIR () {0040000;}&#039; unless defined(&amp;S_IFDIR);
        eval &#039;sub S_IFCHR () {0020000;}&#039; unless defined(&amp;S_IFCHR);
        eval &#039;sub S_IFIFO () {0010000;}&#039; unless defined(&amp;S_IFIFO);
        eval &#039;sub S_ISUID () {0004000;}&#039; unless defined(&amp;S_ISUID);
        eval &#039;sub S_ISGID () {0002000;}&#039; unless defined(&amp;S_ISGID);
        eval &#039;sub S_ISVTX () {0001000;}&#039; unless defined(&amp;S_ISVTX);
        eval &#039;sub S_ISLNK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFLNK));
        }&#039; unless defined(&amp;S_ISLNK);
        eval &#039;sub S_ISREG {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFREG));
        }&#039; unless defined(&amp;S_ISREG);
        eval &#039;sub S_ISDIR {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFDIR));
        }&#039; unless defined(&amp;S_ISDIR);
        eval &#039;sub S_ISCHR {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFCHR));
        }&#039; unless defined(&amp;S_ISCHR);
        eval &#039;sub S_ISBLK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFBLK));
        }&#039; unless defined(&amp;S_ISBLK);
        eval &#039;sub S_ISFIFO {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFIFO));
        }&#039; unless defined(&amp;S_ISFIFO);
        eval &#039;sub S_ISSOCK {
            local($m) = @_;
            eval q(((($m) &amp;  &amp;S_IFMT) ==  &amp;S_IFSOCK));
        }&#039; unless defined(&amp;S_ISSOCK);
        eval &#039;sub S_IRWXU () {00700;}&#039; unless defined(&amp;S_IRWXU);
        eval &#039;sub S_IRUSR () {00400;}&#039; unless defined(&amp;S_IRUSR);
        eval &#039;sub S_IWUSR () {00200;}&#039; unless defined(&amp;S_IWUSR);
        eval &#039;sub S_IXUSR () {00100;}&#039; unless defined(&amp;S_IXUSR);
        eval &#039;sub S_IRWXG () {00070;}&#039; unless defined(&amp;S_IRWXG);
        eval &#039;sub S_IRGRP () {00040;}&#039; unless defined(&amp;S_IRGRP);
        eval &#039;sub S_IWGRP () {00020;}&#039; unless defined(&amp;S_IWGRP);
        eval &#039;sub S_IXGRP () {00010;}&#039; unless defined(&amp;S_IXGRP);
        eval &#039;sub S_IRWXO () {00007;}&#039; unless defined(&amp;S_IRWXO);
        eval &#039;sub S_IROTH () {00004;}&#039; unless defined(&amp;S_IROTH);
        eval &#039;sub S_IWOTH () {00002;}&#039; unless defined(&amp;S_IWOTH);
        eval &#039;sub S_IXOTH () {00001;}&#039; unless defined(&amp;S_IXOTH);
    }
    if(defined(&amp;__KERNEL__)) {
        eval &#039;sub S_IRWXUGO () {( &amp;S_IRWXU| &amp;S_IRWXG| &amp;S_IRWXO);}&#039; unless defined(&amp;S_IRWXUGO);
        eval &#039;sub S_IALLUGO () {( &amp;S_ISUID| &amp;S_ISGID| &amp;S_ISVTX| &amp;S_IRWXUGO);}&#039; unless defined(&amp;S_IALLUGO);
        eval &#039;sub S_IRUGO () {( &amp;S_IRUSR| &amp;S_IRGRP| &amp;S_IROTH);}&#039; unless defined(&amp;S_IRUGO);
        eval &#039;sub S_IWUGO () {( &amp;S_IWUSR| &amp;S_IWGRP| &amp;S_IWOTH);}&#039; unless defined(&amp;S_IWUGO);
        eval &#039;sub S_IXUGO () {( &amp;S_IXUSR| &amp;S_IXGRP| &amp;S_IXOTH);}&#039; unless defined(&amp;S_IXUGO);
        require &#039;linux/types.ph&#039;;
        require &#039;linux/time.ph&#039;;
    }
&nbsp;
</pre>

<p><a href="http://ftp.mozilla.org/pub/mozilla.org/mozilla/releases/mozilla1.8a2/src/mozilla-source-1.8a2.tar.bz2 ">Mozilla-Source 1.8a2</a></p>
<pre>
/* notice that these valuse are octal. */
const PERM_IRWXU = 00700;  /* read, write, execute/search by owner */
const PERM_IRUSR = 00400;  /* read permission, owner */
const PERM_IWUSR = 00200;  /* write permission, owner */
const PERM_IXUSR = 00100;  /* execute/search permission, owner */
const PERM_IRWXG = 00070;  /* read, write, execute/search by group */
const PERM_IRGRP = 00040;  /* read permission, group */
const PERM_IWGRP = 00020;  /* write permission, group */
const PERM_IXGRP = 00010;  /* execute/search permission, group */
const PERM_IRWXO = 00007;  /* read, write, execute/search by others */
const PERM_IROTH = 00004;  /* read permission, others */
const PERM_IWOTH = 00002;  /* write permission, others */
const PERM_IXOTH = 00001;  /* execute/search permission, others */
&nbsp;
const MODE_RDONLY   = 0x01;
const MODE_WRONLY   = 0x02;
const MODE_RDWR     = 0x04;
const MODE_CREATE   = 0x08;
const MODE_APPEND   = 0x10;
const MODE_TRUNCATE = 0x20;
const MODE_SYNC     = 0x40;
const MODE_EXCL     = 0x80;
</pre>


<h3><code>/usr/include/libpng12/png.h</code></h3>
<pre>
/* Transform masks for the high-level interface */
#define PNG_TRANSFORM_IDENTITY       0x0000    /* read and write */
#define PNG_TRANSFORM_STRIP_16       0x0001    /* read only */
#define PNG_TRANSFORM_STRIP_ALPHA    0x0002    /* read only */
#define PNG_TRANSFORM_PACKING        0x0004    /* read and write */
#define PNG_TRANSFORM_PACKSWAP       0x0008    /* read and write */
#define PNG_TRANSFORM_EXPAND         0x0010    /* read only */
#define PNG_TRANSFORM_INVERT_MONO    0x0020    /* read and write */
#define PNG_TRANSFORM_SHIFT          0x0040    /* read and write */
#define PNG_TRANSFORM_BGR            0x0080    /* read and write */
#define PNG_TRANSFORM_SWAP_ALPHA     0x0100    /* read and write */
#define PNG_TRANSFORM_SWAP_ENDIAN    0x0200    /* read and write */
#define PNG_TRANSFORM_INVERT_ALPHA   0x0400    /* read and write */
#define PNG_TRANSFORM_STRIP_FILLER   0x0800    /* WRITE only */
</pre>


<h3><code>/usr/lib/python2.4/stat.py</code></h3>
<pre>
# Extract bits from the mode
&nbsp;
def S_IMODE(mode):
    return mode &amp; 07777
&nbsp;
def S_IFMT(mode):
    return mode &amp; 0170000
&nbsp;
# Constants used as S_IFMT() for various file types
# (not all are implemented on all systems)
&nbsp;
S_IFDIR  = 0040000
S_IFCHR  = 0020000
S_IFBLK  = 0060000
S_IFREG  = 0100000
S_IFIFO  = 0010000
S_IFLNK  = 0120000
S_IFSOCK = 0140000
&nbsp;
# Functions to test for each file type
&nbsp;
def S_ISDIR(mode):
    return S_IFMT(mode) == S_IFDIR
&nbsp;
def S_ISCHR(mode):
    return S_IFMT(mode) == S_IFCHR
&nbsp;
def S_ISBLK(mode):
    return S_IFMT(mode) == S_IFBLK
&nbsp;
def S_ISREG(mode):
    return S_IFMT(mode) == S_IFREG
&nbsp;
def S_ISFIFO(mode):
    return S_IFMT(mode) == S_IFIFO
&nbsp;
def S_ISLNK(mode):
    return S_IFMT(mode) == S_IFLNK
&nbsp;
def S_ISSOCK(mode):
    return S_IFMT(mode) == S_IFSOCK
&nbsp;
# Names for permission bits
&nbsp;
S_ISUID = 04000
S_ISGID = 02000
S_ENFMT = S_ISGID
S_ISVTX = 01000
S_IREAD = 00400
S_IWRITE = 00200
S_IEXEC = 00100
S_IRWXU = 00700
S_IRUSR = 00400
S_IWUSR = 00200
S_IXUSR = 00100
S_IRWXG = 00070
S_IRGRP = 00040
S_IWGRP = 00020
S_IXGRP = 00010
S_IRWXO = 00007
S_IROTH = 00004
S_IWOTH = 00002
S_IXOTH = 00001
</pre>


<h3><code>/usr/include/bits/stat.h</code></h3>
<pre>
/* Encoding of the file mode.  */
&nbsp;
#define __S_IFMT        0170000 /* These bits determine file type.  */
&nbsp;
/* File types.  */
#define __S_IFDIR       0040000 /* Directory.  */
#define __S_IFCHR       0020000 /* Character device.  */
#define __S_IFBLK       0060000 /* Block device.  */
#define __S_IFREG       0100000 /* Regular file.  */
#define __S_IFIFO       0010000 /* FIFO.  */
#define __S_IFLNK       0120000 /* Symbolic link.  */
#define __S_IFSOCK      0140000 /* Socket.  */
&nbsp;
/* POSIX.1b objects.  Note that these macros always evaluate to zero.  But
   they do it by enforcing the correct use of the macros.  */
#define __S_TYPEISMQ(buf)  ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
#define __S_TYPEISSEM(buf) ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
#define __S_TYPEISSHM(buf) ((buf)-&gt;st_mode - (buf)-&gt;st_mode)
&nbsp;
/* Protection bits.  */
&nbsp;
#define __S_ISUID       04000   /* Set user ID on execution.  */
#define __S_ISGID       02000   /* Set group ID on execution.  */
#define __S_ISVTX       01000   /* Save swapped text after use (sticky).  */
#define __S_IREAD       0400    /* Read by owner.  */
#define __S_IWRITE      0200    /* Write by owner.  */
#define __S_IEXEC       0100    /* Execute by owner.  */
</pre>



<h3><code>/usr/include/linux/nfs.h</code></h3>
<pre>
#define NFS_FIFO_DEV    (-1)
#define NFSMODE_FMT     0170000
#define NFSMODE_DIR     0040000
#define NFSMODE_CHR     0020000
#define NFSMODE_BLK     0060000
#define NFSMODE_REG     0100000
#define NFSMODE_LNK     0120000
#define NFSMODE_SOCK    0140000
#define NFSMODE_FIFO    0010000
</pre>


<h3><code>/usr/include/linux/nfs3.h</code></h3>
<pre>
#define NFS3_FIFO_DEV           (-1)
#define NFS3MODE_FMT            0170000
#define NFS3MODE_DIR            0040000
#define NFS3MODE_CHR            0020000
#define NFS3MODE_BLK            0060000
#define NFS3MODE_REG            0100000
#define NFS3MODE_LNK            0120000
#define NFS3MODE_SOCK           0140000
#define NFS3MODE_FIFO           0010000
&nbsp;
/* Flags for access() call */
#define NFS3_ACCESS_READ        0x0001
#define NFS3_ACCESS_LOOKUP      0x0002
#define NFS3_ACCESS_MODIFY      0x0004
#define NFS3_ACCESS_EXTEND      0x0008
#define NFS3_ACCESS_DELETE      0x0010
#define NFS3_ACCESS_EXECUTE     0x0020
#define NFS3_ACCESS_FULL        0x003f
</pre>


<h3><code>/usr/include/linux/stat.h</code></h3>
<pre>
#define S_IFMT  00170000
#define S_IFSOCK 0140000
#define S_IFLNK  0120000
#define S_IFREG  0100000
#define S_IFBLK  0060000
#define S_IFDIR  0040000
#define S_IFCHR  0020000
#define S_IFIFO  0010000
#define S_ISUID  0004000
#define S_ISGID  0002000
#define S_ISVTX  0001000
&nbsp;
#define S_ISLNK(m)      (((m) &amp; S_IFMT) == S_IFLNK)
#define S_ISREG(m)      (((m) &amp; S_IFMT) == S_IFREG)
#define S_ISDIR(m)      (((m) &amp; S_IFMT) == S_IFDIR)
#define S_ISCHR(m)      (((m) &amp; S_IFMT) == S_IFCHR)
#define S_ISBLK(m)      (((m) &amp; S_IFMT) == S_IFBLK)
#define S_ISFIFO(m)     (((m) &amp; S_IFMT) == S_IFIFO)
#define S_ISSOCK(m)     (((m) &amp; S_IFMT) == S_IFSOCK)
&nbsp;
#define S_IRWXU 00700
#define S_IRUSR 00400
#define S_IWUSR 00200
#define S_IXUSR 00100
&nbsp;
#define S_IRWXG 00070
#define S_IRGRP 00040
#define S_IWGRP 00020
#define S_IXGRP 00010
&nbsp;
#define S_IRWXO 00007
#define S_IROTH 00004
#define S_IWOTH 00002
#define S_IXOTH 00001
</pre>











<h2>Further File Permissions Reading</h2>
<h3>Related PHP Functions</h3>
<ul>
<li><a href="http://php.net/manual/en/function.fileperms.php">fileperms</a></li>
<li><a href="http://php.net/manual/en/function.stat.php">stat</a></li>
<li><a href="http://php.net/manual/en/function.chmod.php">chmod</a></li>
<li><a href="http://php.net/manual/en/function.clearstatcache.php">clearstatcache</a></li>
<li><a href="http://php.net/manual/en/function.chown.php">chown</a></li>
<li><a href="http://php.net/manual/en/function.chgrp.php">chgrp</a></li>
<li><a href="http://php.net/manual/en/function.lchown.php">lchown</a></li>
<li><a href="http://php.net/manual/en/function.lchgrp.php">lchgrp</a></li>
<li><a href="http://php.net/manual/en/function.touch.php">touch</a></li>
<li><a href="http://php.net/manual/en/function.lstat.php">lstat</a></li>
<li><a href="http://php.net/manual/en/function.fstat.php">filestat</a></li>
<li><a href="http://php.net/manual/en/function.fileatime.php">fileatime</a></li>
<li><a href="http://php.net/manual/en/function.filectime.php">filectime</a></li>
<li><a href="http://php.net/manual/en/function.filegroup.php">filegroup</a></li>
<li><a href="http://php.net/manual/en/function.fileinode.php">fileinode</a></li>
<li><a href="http://php.net/manual/en/function.filemtime.php">filemtime</a></li>
<li><a href="http://php.net/manual/en/function.fileowner.php">fileowner</a></li>
<li><a href="http://php.net/manual/en/function.filesize.php">filesize</a></li>
<li><a href="http://php.net/manual/en/function.filetype.php">filetype</a></li>
<li><a href="http://php.net/manual/en/function.is-writable.php">is_writable</a></li>
<li><a href="http://php.net/manual/en/function.is-readable.php">is_readable</a></li>
<li><a href="http://php.net/manual/en/function.is-executable.php">is_executable</a></li>
<li><a href="http://php.net/manual/en/function.is-file.php">is_file</a></li>
<li><a href="http://php.net/manual/en/function.is-dir.php">is_dir</a></li>
<li><a href="http://php.net/manual/en/function.is-link.php">is_link</a></li>
<li><a href="http://php.net/manual/en/function.file-exists.php">file_exists</a></li>
<li><a href="http://php.net/manual/en/function.disk-total-space.php">disk_total_space</a></li>
<li><a href="http://php.net/manual/en/function.disk-free-space.php">disk_free_space</a></li>
</ul>


<h3>Special file types</h3>
<ul>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#link-invocation">link invocation</a>:  Make a hard link via the link syscall</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#ln-invocation">ln invocation</a>: Make links between files</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mkdir-invocation">mkdir invocation</a>: Make directories</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mkfifo-invocation">mkfifo invocation</a>: Make FIFOs (named pipes)</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#mknod-invocation">mknod invocation</a>: Make block or character special files</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#readlink-invocation">readlink invocation</a>: Print the referent of a symbolic link</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#rmdir-invocation">rmdir invocation</a>: Remove empty directories</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#unlink-invocation">unlink invocation</a>: Remove files via unlink syscall</li>
</ul>


<h3>Changing file attributes</h3>
<ul>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chown-invocation">chown invocation</a>: Change file owner and group</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chgrp-invocation">chgrp invocation</a>: Change group ownership</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#chmod-invocation">chmod invocation</a>: Change access permissions</li>
<li><a href="http://www.gnu.org/software/coreutils/manual/coreutils.html#touch-invocation">touch invocation</a>: Change file timestamps</li>
</ul><p><a href="http://www.askapache.com/security/chmod-stat.html"></a><a href="http://www.askapache.com/security/chmod-stat.html">Chmod, Umask, Stat, Fileperms, and File Permissions</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/security/chmod-stat.html/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Programming Fonts for the Web</title>
		<link>http://www.askapache.com/css/programming-fonts-code.html</link>
		<comments>http://www.askapache.com/css/programming-fonts-code.html#comments</comments>
		<pubDate>Sat, 29 Oct 2011 09:37:43 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[CSS]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4809</guid>
		<description><![CDATA[<p>The idea is to use CSS to have the browser display programming and code similar to the high-quality look of a developers machine, like this older screenshot of my VIM.</p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/css/programming-fonts-code.html"></a><a href="http://www.askapache.com/css/programming-fonts-code.html"><cite>AskApache.com</cite></a></p><p>The idea is to have the browser display programming and code similar to the high-quality found on a developers machine, like this older screenshot of my vim. <br /><a href="http://www.askapache.com/linux/bash-power-prompt.html/bash-prompt-screenshot/" rel="attachment wp-att-4177"><img src="http://uploads.askapache.com/2010/03/bash-prompt-screenshot.png" alt="Custom Power Prompt" title="Custom Power Prompt" width="795" height="596" /></a></p>
<p>The most important step is to figure out the font-family and the basic font-attributes.  You want to show the best font for those visitors (like me) who have all these extra console fonts, but fallback to a font that anyone in the world can view.</p>

<h2>Monospace is the fallback</h2>
<blockquote cite="http://www.w3.org/TR/CSS2/fonts.html">
<h4><a href="http://www.w3.org/TR/CSS2/fonts.html">15.3.1.5 <dfn>monospace</dfn></a></h4>
<p><p>The sole criterion of a monospace font is that all glyphs have the same fixed width. (This can make some scripts, such as Arabic, look most peculiar.) The effect is similar to a manual typewriter, and is often used to set samples of computer code.</p>
</blockquote>



<h2>CSS Rules for Code</h2>
<p>Here are a few css rules I use.  That is my ultimate font-family heirarchy of console-type fonts, though not many people have them installed.  The fallback is usually Andale Mono, Monaco, or DejaVu Sans Mono, Lucida Console, Bitstream, then Courier.</p>
<pre>kbd, samp, tt, pre, code, var,
.code, .pre {
   font-family: Terminus,Consolas,Profont,"Andale Mono",Monaco,Inconsolata,Inconsolata-g,
      Unifont,Lime,"ClearlyU PUA",Clean,"DejaVu Sans Mono","Lucida Console",
      "Bitstream Vera Sans Mono",Freemono,"Liberation Mono",Dina,Anka,Droid Sans Mono,
      Anonymous Pro,Proggy fonts,Envy Code R,Gamow,Courier,"Courier New",Terminal,monospace;
}</pre>

<p>This is just some basic pre attributes, useful as a reset or to force the issue.  You may just want to do <code>.pre {...}</code> to apply to elements with <code>class="pre"</code> instead of applying to all pre elements sitewide.</p>
<pre>pre { letter-spacing:normal; word-spacing:normal; text-transform:none; max-width:100%; overflow:auto; white-space:pre-wrap; }
pre.normal { white-space:normal }</pre>


<h2>Live Font Examples</h2>
<p>What you see is what you get, so experiment with different browsers.</p>
<ul>
<li><a id="font-Courier" name="font-Courier">Courier</a><br />
<pre style='font-family:Courier,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Courier-New" name="font-Courier-New">Courier New</a><br />
<pre style='font-family:Courier New,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Terminal" name="font-Terminal">Terminal</a><br />
<pre style='font-family:Terminal,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Agency-FB-Bold" name="Agency-FB-Bold">Agency FB Bold</a><br />
<pre style='font-family:Agency FB Bold,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Consolas" name="font-Consolas">Consolas</a><br />
<pre style='font-family:Consolas,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Terminus" name="font-Terminus">Terminus</a><br />
<pre style='font-family:Terminus,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Profont" name="font-Profont">Profont</a><br />
<pre style='font-family:Profont,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Andale-Mono" name="font-Andale-Mono">Andale Mono</a><br />
<pre style='font-family:Andale Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Monaco" name="font-Monaco">Monaco</a><br />
<pre style='font-family:Monaco,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Inconsolata" name="font-Inconsolata">Inconsolata</a><br />
<pre style='font-family:Inconsolata,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Inconsolata-g" name="font-Inconsolata-g">Inconsolata-g</a><br />
<pre style='font-family:Inconsolata-g,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Unifont" name="font-Unifont">Unifont</a><br />
<pre style='font-family:Unifont,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Lime" name="font-Lime">Lime</a><br />
<pre style='font-family:Lime,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-ClearlyU-PUA" name="font-ClearlyU-PUA">ClearlyU PUA</a><br />
<pre style='font-family:ClearlyU PUA,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Clean" name="font-Clean">Clean</a><br />
<pre style='font-family:Clean,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-DejaVu-Sans-Mono" name="font-DejaVu-Sans-Mono">DejaVu Sans Mono</a><br />
<pre style='font-family:DejaVu Sans Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Lucida-Console" name="font-Lucida-Console">Lucida Console</a><br />
<pre style='font-family:Lucida Console,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Bitstream-Vera-Sans-Mono" name="font-Bitstream-Vera-Sans-Mono">Bitstream Vera Sans Mono</a><br />
<pre style='font-family:Bitstream Vera Sans Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Freemono" name="font-Freemono">Freemono</a><br />

<pre style='font-family:Freemono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Liberation-Mono" name="font-Liberation-Mono">Liberation Mono</a><br />
<pre style='font-family:Liberation Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Dina" name="font-Dina">Dina</a><br />
<pre style='font-family:Dina,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Anka" name="font-Anka">Anka</a><br />
<pre style='font-family:Anka,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Droid-Sans-Mono" name="font-Droid-Sans-Mono">Droid Sans Mono</a><br />
<pre style='font-family:Droid Sans Mono,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Anonymous-Pro" name="font-Anonymous-Pro">Anonymous Pro</a><br />
<pre style='font-family:Anonymous Pro,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Proggy-fonts" name="font-Proggy-fonts">Proggy fonts</a><br />
<pre style='font-family:Proggy fonts,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Envy-Code-R" name="font-Envy-Code-R">Envy-Code-R</a><br />
<pre style='font-family:Envy Code R,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
<li><a id="font-Gamow" name="font-Gamow">Gamow</a><br />
<pre style='font-family:Gamow,Open Symbol,Webdings,Wingdings,SWMacro,Haettenschweiler,Wide Latin,Marlett,Parchment,fantasy'>+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 |
|     Type      |      Code     |          A B C D E F G H      |</pre></li>
</ul>



<h2>More Info and Software</h2>
<ul>
<li><a href="http://www.w3.org/Style/Examples/007/fonts#font-family">CSS Font Families Example at W3</a></li>
<li><a href="http://www.lowing.org/fonts/">Monospace/Fixed Width Programmer's Fonts</a></li>
<li><a href="http://www.nirsoft.net/utils/windows_fonts_viewer.html">WinFontsView v1.10 - View samples of Windows fonts installed on your system </a></li>
</ul>



<p><a class="hs hs13" href="http://www.askapache.com/servers/mod_rewrite.c.html"></a></p><p><a href="http://www.askapache.com/css/programming-fonts-code.html"></a><a href="http://www.askapache.com/css/programming-fonts-code.html">Programming Fonts for the Web</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/css/programming-fonts-code.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Raw HTTP Header Debugger</title>
		<link>http://www.askapache.com/online-tools/http-headers-tool</link>
		<comments>http://www.askapache.com/online-tools/http-headers-tool#comments</comments>
		<pubDate>Wed, 26 Oct 2011 15:14:08 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
		
		<guid isPermaLink="false">http://www.askapache.com/online-tools/http-headers-tool/</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/online-tools/http-headers-tool"></a><a href="http://www.askapache.com/online-tools/http-headers-tool"><cite>AskApache.com</cite></a></p><hr class="C" />
<h2>HTTP Headers</h2>
<table>
    <thead>
        <tr>
            <td><strong>HTTP Header Name</strong></td>
            <td><strong>Header Description</strong></td>
            <td><strong>Example HTTP Header</strong></td>
        </tr>
    </thead>
    <tr>
        <td>Accept</td>
        <td>Content-Types that are acceptable</td>
        <td><code>Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5</code></td>
    </tr>
    <tr>
        <td>Accept-Charset</td>
        <td>Character sets that are acceptable</td>
        <td><code>Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7</code></td>
    </tr>
    <tr>
        <td>Accept-Encoding</td>
        <td>Acceptable encodings</td>
        <td><code>Accept-Encoding: gzip,deflate</code></td>
    </tr>
    <tr>
        <td>Accept-Language</td>
        <td>Acceptable languages for response</td>
        <td><code>Accept-Language: en-us,en</code></td>
    </tr>
    <tr>
        <td>Accept-Ranges</td>
        <td>What partial content range types this server supports</td>
        <td><code>Accept-Ranges: bytes</code></td>
    </tr>
    <tr>
        <td>Age</td>
        <td>The age the object has been in a proxy cache in seconds</td>
        <td><code>Age: 7200</code></td>
    </tr>
    <tr>
        <td>Allow</td>
        <td>Valid actions for a specified resource. To be used for a 405 Method not allowed</td>
        <td><code>Allow: GET,HEAD,POST,OPTIONS,TRACE</code></td>
    </tr>
    <tr>
        <td>Authorization</td>
        <td>Authentication credentials for HTTP authentication</td>
        <td><code>Authorization: Basic UXNrYXBhggRfoopc5NteWFzcw==</code></td>
    </tr>
    <tr>
        <td>Cache-Control</td>
        <td>Controls how proxies may cache this object</td>
        <td><code>Cache-Control: max-age=7200, public</code></td>
    </tr>
    <tr>
        <td>Connection</td>
        <td>What type of connection the user-agent would prefer</td>
        <td><code>Connection: Keep-Alive</code></td>
    </tr>
    <tr>
        <td>Content-Encoding</td>
        <td>The type of encoding used on the data</td>
        <td><code>Content-Encoding: gzip</code></td>
    </tr>
    <tr>
        <td>Content-Language</td>
        <td>The language the content is in</td>
        <td><code>Content-Language: en-us</code></td>
    </tr>
    <tr>
        <td>Content-Length</td>
        <td>The length of the content in bytes</td>
        <td><code>Content-Length: 5356</code></td>
    </tr>
    <tr>
        <td>Content-Location</td>
        <td>An alternate location for the returned data</td>
        <td><code>Content-Location: /index.html</code></td>
    </tr>
    <tr>
        <td>Content-MD5</td>
        <td>An MD5 sum of the content of the response</td>
        <td><code>Content-MD5: 1167b9c13ad2b6d3694493fc47976c8</code></td>
    </tr>
    <tr>
        <td>Content-Range</td>
        <td>Where in a full body message this partial message belongs</td>
        <td><code>Content-Range: bytes 110-2034/2035</code></td>
    </tr>
    <tr>
        <td>Content-Type</td>
        <td>The mime type of this content</td>
        <td><code>Content-Type: text/html; charset=UTF-8</code></td>
    </tr>
    <tr>
        <td>Date</td>
        <td>The date and time that the message was sent</td>
        <td><code>Date: Sat, 05 Jan 2008 09:27:35 GMT</code></td>
    </tr>
    <tr>
        <td>Host</td>
        <td>The domain name of the server (for virtual hosting)</td>
        <td><code>Host: www.askapache.com</code></td>
    </tr>
    <tr>
        <td>If-Modified-Since</td>
        <td>Allows a 304 Not Modified to be returned</td>
        <td><code>If-Modified-Since: Sat, 05 Jan 2007 09:26:12 GMT</code></td>
    </tr>
    <tr>
        <td>Last-Modified</td>
        <td>The last modified date for the requested object</td>
        <td><code>Last-Modified: Sat, 05 Jan 2008 09:26:12 GMT</code></td>
    </tr>
    <tr>
        <td>Location</td>
        <td>Used in redirection</td>
        <td><code>Location: http://www.askapache.com/</code></td>
    </tr>
    <tr>
        <td>Server</td>
        <td>A name for the server</td>
        <td><code>Server: Apache/2.0.61 (Unix) PHP/4.4.7 mod_ssl/2.0.61 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2</code></td>
    </tr>
    <tr>
        <td>User-Agent</td>
        <td>The user agent string of the user agent</td>
        <td><code>User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7</code></td>
    </tr>
</table>
<hr class="C" />


<address>part of <a rev='Section' href='http://www.w3.org/Protocols/rfc2616/rfc2616.html'>Hypertext Transfer Protocol -- HTTP/1.1</a><br />RFC 2616 Fielding, et al.</address>
<h2><a id='sec9'>9</a> Method Definitions</h2>
<p>The set of common methods for HTTP/1.1 is defined below. Although this set can be expanded, additional methods cannot be assumed to share the same semantics for separately extended clients and servers.</p>
<p>The Host request-header field (section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.23'>14.23</a>) MUST accompany all HTTP/1.1 requests.</p>
<h3><a id='sec9.1'>9.1</a> Safe and Idempotent Methods</h3>
<h3><a id='sec9.1.1'>9.1.1</a> Safe Methods</h3>
<p>Implementors should be aware that the software represents the user in their interactions over the Internet, and should be careful to allow the user to be aware of any actions they might take which may have an unexpected significance to themselves or others.</p>
<p>In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.</p>
<p>Naturally, it is not possible to ensure that the server does not generate side-effects as a result of performing a GET request; in fact, some dynamic resources consider that a feature. The important distinction here is that the user did not request the side-effects, so therefore cannot be held accountable for them.</p>
<h3><a id='sec9.1.2'>9.1.2</a> Idempotent Methods</h3>
<p>Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent.</p>
<p>However, it is possible that a sequence of several requests is non- idempotent, even if all of the methods executed in that sequence are idempotent. (A sequence is idempotent if a single execution of the entire sequence always yields a result that is not changed by a reexecution of all, or part, of that sequence.) For example, a sequence is non-idempotent if its result depends on a value that is later modified in the same sequence.</p>
<p>A sequence that never has side effects is idempotent, by definition (provided that no concurrent operations are being executed on the same set of resources).</p>
<h3><a id='sec9.2'>9.2</a> OPTIONS</h3>
<p>The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval.</p>
<p>Responses to this method are not cacheable.</p>
<p>If the OPTIONS request includes an entity-body (as indicated by the presence of Content-Length or Transfer-Encoding), then the media type MUST be indicated by a Content-Type field. Although this specification does not define any use for such a body, future extensions to HTTP might use the OPTIONS body to make more detailed queries on the server. A server that does not support such an extension MAY discard the request body.</p>
<p>If the Request-URI is an asterisk ("*"), the OPTIONS request is intended to apply to the server in general rather than to a specific resource. Since a server's communication options typically depend on the resource, the "*" request is only useful as a "ping" or "no-op" type of method; it does nothing beyond allowing the client to test the capabilities of the server. For example, this can be used to test a proxy for HTTP/1.1 compliance (or lack thereof).</p>
<p>If the Request-URI is not an asterisk, the OPTIONS request applies only to the options that are available when communicating with that resource.</p>
<p>A 200 response SHOULD include any header fields that indicate optional features implemented by the server and applicable to that resource (e.g., Allow), possibly including extensions not defined by this specification. The response body, if any, SHOULD also include information about the communication options. The format for such a</p>
<p>body is not defined by this specification, but might be defined by future extensions to HTTP. Content negotiation MAY be used to select the appropriate response format. If no response body is included, the response MUST include a Content-Length field with a field-value of "0".</p>
<p>The Max-Forwards request-header field MAY be used to target a specific proxy in the request chain. When a proxy receives an OPTIONS request on an absoluteURI for which request forwarding is permitted, the proxy MUST check for a Max-Forwards field. If the Max-Forwards field-value is zero ("0"), the proxy MUST NOT forward the message; instead, the proxy SHOULD respond with its own communication options. If the Max-Forwards field-value is an integer greater than zero, the proxy MUST decrement the field-value when it forwards the request. If no Max-Forwards field is present in the request, then the forwarded request MUST NOT include a Max-Forwards field.</p>
<h3><a id='sec9.3'>9.3</a> GET</h3>
<p>The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.</p>
<p>The semantics of the GET method change to a "conditional GET" if the request message includes an If-Modified-Since, If-Unmodified-Since, If-Match, If-None-Match, or If-Range header field. A conditional GET method requests that the entity be transferred only under the circumstances described by the conditional header field(s). The conditional GET method is intended to reduce unnecessary network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring data already held by the client.</p>
<p>The semantics of the GET method change to a "partial GET" if the request message includes a Range header field. A partial GET requests that only part of the entity be transferred, as described in section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35'>14.35</a>. The partial GET method is intended to reduce unnecessary network usage by allowing partially-retrieved entities to be completed without transferring data already held by the client.</p>
<p>The response to a GET request is cacheable if and only if it meets the requirements for HTTP caching described in section 13.</p>
<p>See section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3'>15.1.3</a> for security considerations when used for forms.</p>
<h3><a id='sec9.4'>9.4</a> HEAD</h3>
<p>The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.</p>
<p>The response to a HEAD request MAY be cacheable in the sense that the information contained in the response MAY be used to update a previously cached entity from that resource. If the new field values indicate that the cached entity differs from the current entity (as would be indicated by a change in Content-Length, Content-MD5, ETag or Last-Modified), then the cache MUST treat the cache entry as stale.</p>
<h3><a id='sec9.5'>9.5</a> POST</h3>
<p>The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line. POST is designed to allow a uniform method to cover the following functions:</p>
<pre>      - Annotation of existing resources; </pre>
<pre>      - Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles; </pre>
<pre>      - Providing a block of data, such as the result of submitting a form, to a data-handling process; </pre>
<pre>      - Extending a database through an append operation. </pre>
<p>The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI. The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.</p>
<p>The action performed by the POST method might not result in a resource that can be identified by a URI. In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.</p>
<p>If a resource has been created on the origin server, the response SHOULD be 201 (Created) and contain an entity which describes the status of the request and refers to the new resource, and a Location header (see section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.30'>14.30</a>).</p>
<p>Responses to this method are not cacheable, unless the response includes appropriate Cache-Control or Expires header fields. However, the 303 (See Other) response can be used to direct the user agent to retrieve a cacheable resource.</p>
<p>POST requests MUST obey the message transmission requirements set out in section 8.2.</p>
<p>See section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec15.html#sec15.1.3'>15.1.3</a> for security considerations.</p>
<h3><a id='sec9.6'>9.6</a> PUT</h3>
<p>The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request. If the resource could not be created or modified with the Request-URI, an appropriate error response SHOULD be given that reflects the nature of the problem. The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.</p>
<p>If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.</p>
<p>The fundamental difference between the POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in a POST request identifies the resource that will handle the enclosed entity. That resource might be a data-accepting process, a gateway to some other protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed with the request -- the user agent knows what URI is intended and the server MUST NOT attempt to apply the request to some other resource. If the server desires that the request be applied to a different URI,</p>
<p>it MUST send a 301 (Moved Permanently) response; the user agent MAY then make its own decision regarding whether or not to redirect the request.</p>
<p>A single resource MAY be identified by many different URIs. For example, an article might have a URI for identifying "the current version" which is separate from the URI identifying each particular version. In this case, a PUT request on a general URI might result in several other URIs being defined by the origin server.</p>
<p>HTTP/1.1 does not define how a PUT method affects the state of an origin server.</p>
<p>PUT requests MUST obey the message transmission requirements set out in section 8.2.</p>
<p>Unless otherwise specified for a particular entity-header, the entity-headers in the PUT request SHOULD be applied to the resource created or modified by the PUT.</p>
<h3><a id='sec9.7'>9.7</a> DELETE</h3>
<p>The DELETE method requests that the origin server delete the resource identified by the Request-URI. This method MAY be overridden by human intervention (or other means) on the origin server. The client cannot be guaranteed that the operation has been carried out, even if the status code returned from the origin server indicates that the action has been completed successfully. However, the server SHOULD NOT indicate success unless, at the time the response is given, it intends to delete the resource or move it to an inaccessible location.</p>
<p>A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.</p>
<p>If the request passes through a cache and the Request-URI identifies one or more currently cached entities, those entries SHOULD be treated as stale. Responses to this method are not cacheable.</p>
<h3><a id='sec9.8'>9.8</a> TRACE</h3>
<p>The TRACE method is used to invoke a remote, application-layer loop- back of the request message. The final recipient of the request SHOULD reflect the message received back to the client as the entity-body of a 200 (OK) response. The final recipient is either the</p>
<p>origin server or the first proxy or gateway to receive a Max-Forwards value of zero (0) in the request (see section 14.31). A TRACE request MUST NOT include an entity.</p>
<p>TRACE allows the client to see what is being received at the other end of the request chain and use that data for testing or diagnostic information. The value of the Via header field (section <a rel='xref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.45'>14.45</a>) is of particular interest, since it acts as a trace of the request chain. Use of the Max-Forwards header field allows the client to limit the length of the request chain, which is useful for testing a chain of proxies forwarding messages in an infinite loop.</p>
<p>If the request is valid, the response SHOULD contain the entire request message in the entity-body, with a Content-Type of "message/http". Responses to this method MUST NOT be cached.</p>
<h3><a id='sec9.9'>9.9</a> CONNECT</h3>
<p>This specification reserves the method name CONNECT for use with a proxy that can dynamically switch to being a tunnel (e.g. SSL tunneling <a rel='bibref' href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec17.html#bib44'>[44]</a>).</p>


<h2><a href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html">List of HTTP Response Status Codes</a></h2>
<h3>1xx Info / Informational</h3>
<h4><code>HTTP_INFO</code> - Request received, continuing process.</h4>
<p>Indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.</p>
<ul>
    <li><strong>100 Continue</strong> - <code>HTTP_CONTINUE</code></li>
    <li><strong>101 Switching Protocols</strong> - <code>HTTP_SWITCHING_PROTOCOLS</code></li>
    <li><strong>102 Processing</strong> - <code>HTTP_PROCESSING</code></li>
</ul>
<h3>2xx Success / OK</h3>
<h4><code>HTTP_SUCCESS</code> - The action was successfully received, understood, and accepted.</h4>
<p>Indicates that the client's request was successfully received, understood, and accepted.</p>
<ul>
    <li><strong>200 OK</strong> - <code>HTTP_OK</code></li>
    <li><strong>201 Created</strong> - <code>HTTP_CREATED</code></li>
    <li><strong>202 Accepted</strong> - <code>HTTP_ACCEPTED</code></li>
    <li><strong>203 Non-Authoritative Information</strong> - <code>HTTP_NON_AUTHORITATIVE</code></li>
    <li><strong>204 No Content</strong> - <code>HTTP_NO_CONTENT</code></li>
    <li><strong>205 Reset Content</strong> - <code>HTTP_RESET_CONTENT</code></li>
    <li><strong>206 Partial Content</strong> - <code>HTTP_PARTIAL_CONTENT</code></li>
    <li><strong>207 Multi-Status</strong> - <code>HTTP_MULTI_STATUS</code></li>
</ul>
<h3>3xx Redirect</h3>
<h4><code>HTTP_REDIRECT</code> - The client must take additional action to complete the request.</h4>
<p>Indicates that further action needs to be taken by the user-agent in order to fulfill the request. The action required may be carried out by the user agent without interaction with the user if and only if the method used in the second request is GET or HEAD. A user agent should not automatically <em>redirect a request more than 5 times</em>, since such redirections usually indicate an <strong>infinite loop</strong>.</p>
<ul>
    <li><strong>300 Multiple Choices</strong> - <code>HTTP_MULTIPLE_CHOICES</code></li>
    <li><strong>301 Moved Permanently</strong> - <code>HTTP_MOVED_PERMANENTLY</code></li>
    <li><strong>302 Found</strong> - <code>HTTP_MOVED_TEMPORARILY</code></li>
    <li><strong>303 See Other</strong> - <code>HTTP_SEE_OTHER</code></li>
    <li><strong>304 Not Modified</strong> - <code>HTTP_NOT_MODIFIED</code></li>
    <li><strong>305 Use Proxy</strong> - <code>HTTP_USE_PROXY</code></li>
    <li><strong>306 unused</strong> - <code>UNUSED</code></li>
    <li><strong>307 Temporary Redirect</strong> - <code>HTTP_TEMPORARY_REDIRECT</code></li>
</ul>
<h3>4xx Client Error</h3>
<h4><code>HTTP_CLIENT_ERROR</code> - The request contains bad syntax or cannot be fulfilled.</h4>
<p>Indicates case where client seems to have erred. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition.</p>
<ul>
    <li><strong>400 Bad Request</strong> - <code>HTTP_BAD_REQUEST</code></li>
    <li><strong>401 Authorization Required</strong> - <code>HTTP_UNAUTHORIZED</code></li>
    <li><strong>402 Payment Required</strong> - <code>HTTP_PAYMENT_REQUIRED</code></li>
    <li><strong>403 Forbidden</strong> - <code>HTTP_FORBIDDEN</code></li>
    <li><strong>404 Not Found</strong> - <code>HTTP_NOT_FOUND</code></li>
    <li><strong>405 Method Not Allowed</strong> - <code>HTTP_METHOD_NOT_ALLOWED</code></li>
    <li><strong>406 Not Acceptable</strong> - <code>HTTP_NOT_ACCEPTABLE</code></li>
    <li><strong>407 Proxy Authentication Required</strong> - <code>HTTP_PROXY_AUTHENTICATION_REQUIRED</code></li>
    <li><strong>408 Request Time-out</strong> - <code>HTTP_REQUEST_TIME_OUT</code></li>
    <li><strong>409 Conflict</strong> - <code>HTTP_CONFLICT</code></li>
    <li><strong>410 Gone</strong> - <code>HTTP_GONE</code></li>
    <li><strong>411 Length Required</strong> - <code>HTTP_LENGTH_REQUIRED</code></li>
    <li><strong>412 Precondition Failed</strong> - <code>HTTP_PRECONDITION_FAILED</code></li>
    <li><strong>413 Request Entity Too Large</strong> - <code>HTTP_REQUEST_ENTITY_TOO_LARGE</code></li>
    <li><strong>414 Request-URI Too Large</strong> - <code>HTTP_REQUEST_URI_TOO_LARGE</code></li>
    <li><strong>415 Unsupported Media Type</strong> - <code>HTTP_UNSUPPORTED_MEDIA_TYPE</code></li>
    <li><strong>416 Requested Range Not Satisfiable</strong> - <code>HTTP_RANGE_NOT_SATISFIABLE</code></li>
    <li><strong>417 Expectation Failed</strong> - <code>HTTP_EXPECTATION_FAILED</code></li>
    <li><strong>418 unused</strong> - <code>UNUSED</code></li>
    <li><strong>419 unused</strong> - <code>UNUSED</code></li>
    <li><strong>420 unused</strong> - <code>UNUSED</code></li>
    <li><strong>421 unused</strong> - <code>UNUSED</code></li>
    <li><strong>422 Unprocessable Entity</strong> - <code>HTTP_UNPROCESSABLE_ENTITY</code></li>
    <li><strong>423 Locked</strong> - <code>HTTP_LOCKED</code></li>
    <li><strong>424 Failed Dependency</strong> - <code>HTTP_FAILED_DEPENDENCY</code></li>
    <li><strong>425 No code</strong> - <code>HTTP_NO_CODE</code></li>
    <li><strong>426 Upgrade Required</strong> - <code>HTTP_UPGRADE_REQUIRED</code></li>
</ul>
<h3>5xx Server Error</h3>
<h4><code>HTTP_SERVER_ERROR</code> - The server failed to fulfill an apparently valid request.</h4>
<p>Indicate cases in which the server is aware that it has erred or is incapable of performing the request. Except when responding to a HEAD request, the server should include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition. User agents should display any included entity to the user. These response codes are applicable to any request method.</p>
<ul>
    <li><strong>500 Internal Server Error</strong> - <code>HTTP_INTERNAL_SERVER_ERROR</code></li>
    <li><strong>501 Method Not Implemented</strong> - <code>HTTP_NOT_IMPLEMENTED</code></li>
    <li><strong>502 Bad Gateway</strong> - <code>HTTP_BAD_GATEWAY</code></li>
    <li><strong>503 Service Temporarily Unavailable</strong> - <code>HTTP_SERVICE_UNAVAILABLE</code></li>
    <li><strong>504 Gateway Time-out</strong> - <code>HTTP_GATEWAY_TIME_OUT</code></li>
    <li><strong>505 HTTP Version Not Supported</strong> - <code>HTTP_VERSION_NOT_SUPPORTED</code></li>
    <li><strong>506 Variant Also Negotiates</strong> - <code>HTTP_VARIANT_ALSO_VARIES</code></li>
    <li><strong>507 Insufficient Storage</strong> - <code>HTTP_INSUFFICIENT_STORAGE</code></li>
    <li><strong>508 unused</strong> - <code>UNUSED</code></li>
    <li><strong>509 unused</strong> - <code>UNUSED</code></li>
    <li><strong>510 Not Extended</strong> - <code>HTTP_NOT_EXTENDED</code></li>
</ul>
<h2>Helpful HTTP Links</h2>
<ol>
    <li><a href="http://rfc.askapache.com/rfc2616.html#section-10">HTTP specification, Section 10</a></li>
    <li><a href="http://rfc.askapache.com/rfc2817.html#section-4">TLS Upgrade within HTTP specification, Section 4</a></li>
    <li><a href="http://rfc.askapache.com/rfc2817.html#section-7.1">HTTP Status Code Registry</a></li>
    <li><a href="http://rfc.askapache.com/rfc4918.html#section-11">WebDAV specification, Section 11</a></li>
    <li><a href="http://www.iana.org/assignments/http-status-codes">IANA registry</a></li>
    <li><a href="http://livedocs.adobe.com/fms/2/docs/00000338.html">Adobe Flash status code definitions (ie 408)</a></li>
    <li><a href="http://support.microsoft.com/?id=318380">Microsoft Internet Information Server Status Codes and Sub-Codes</a></li>
    <li>httplint</li>
    <li><a href="http://www.w3.org/Protocols/HTTP/HTRQ_Headers.html">HTTP Headers, brief intro.</a></li>
    <li><a href="http://www.w3.org/TR/cuap">Common User-Agent Issues</a></li>
</ol>
<hr class="C" />
<dl>
    <dt>DRP</dt>
    <dd><a href="http://www.w3.org/TR/NOTE-drp-19970825">"The HTTP Distribution and Replication Protocol"</a></dd>
    <dt>DupSup</dt>
    <dd><a href="http://www3.ietf.org/proceedings/98dec/I-D/draft-mogul-http-dupsup-00.txt">"Duplicate Suppression in HTTP"</a></dd>
    <dt>EARL Schema</dt>
    <dd><a href="http://www.w3.org/WAI/ER/EARL10/WD-EARL10-Schema-20060101">"Evaluation and Report Language (EARL) 1.0 Schema"</a></dd>
    <dt>EDD</dt>
    <dd><a href="http://wp.netscape.com/assist/net_sites/pushpull.html">"An exploration of dynamic documents"</a></dd>
    <dt>EdgeArch</dt>
    <dd><a href="http://www.w3.org/TR/2001/NOTE-edge-arch-20010804">"Edge Architecture Specification"</a></dd>
    <dt>HttpClient</dt>
    <dd><a href="http://jakarta.apache.org/commons/httpclient/">Jakarta Commons HttpClient</a></dd>
    <dt>HTML4</dt>
    <dd><a href="http://www.w3.org/TR/1999/REC-html401-19991224/">"HTML 4.01 Specification"</a></dd>
    <dt>JEPI</dt>
    <dd><a href="http://www.w3.org/TR/NOTE-jepi-970519">"White Paper: Joint Electronic Payment Initiative"</a></dd>
    <dt>ObjectHeaders</dt>
    <dd><a href="http://www.w3.org/Protocols/HTTP/Object_Headers.html">"Object Header lines in HTTP"</a></dd>
    <dt>OPS-OverHTTP</dt>
    <dd><a href="http://www.w3.org/TR/NOTE-OPS-OverHTTP">"Implementation of OPS Over HTTP"</a></dd>
    <dt>OPTIONS messages</dt>
    <dd>"Specification of HTTP/1.1 OPTIONS messages"</dd>
    <dt>P3P</dt>
    <dd><a href="http://www.w3.org/TR/2002/REC-P3P-20020416/">"The Platform for Privacy Preferences 1.0 (P3P1.0) Specification"</a></dd>
    <dt>PEP</dt>
    <dd><a href="http://www.w3.org/TR/WD-http-pep-970526">"PEP - an Extension Mechanism for HTTP"</a></dd>
    <dt>PICSLabels</dt>
    <dd><a href="http://www.w3.org/TR/REC-PICS-labels-961031">"PICS Label Distribution Label Syntax and Communication Protocols, Version 1.1"</a></dd>
    <dt>Proxy Notification</dt>
    <dd><a href="http://www.w3.org/TR/WD-proxy-960221">"Notification for Proxy Caches"</a></dd>
    <dt>RDF</dt>
    <dd><a href="http://www.w3.org/TR/rdf-concepts/">"Resource Description Framework (RDF): Concepts and Abstract Syntax"</a></dd>
    <dt>RDF-PRIMER</dt>
    <dd><a href="http://www.w3.org/TR/rdf-primer/"> <acronym title="Resource Description Framework">RDF</acronym> Primer</a></dd>
    <dt>RFC2068</dt>
    <dd><a href="http://rfc.askapache.com/rfc2068/">"Hypertext Transfer Protocol -- HTTP/1.1"</a></dd>
    <dt>RFC2109</dt>
    <dd><a href="http://rfc.askapache.com/rfc2109/">"HTTP State Management Mechanism"</a></dd>
    <dt>RFC2183</dt>
    <dd><a href="http://rfc.askapache.com/rfc2183/">"Communicating Presentation Information in Internet Messages: The Content-Disposition Header Field"</a></dd>
    <dt>RFC2227</dt>
    <dd><a href="http://rfc.askapache.com/rfc2227/">"Simple Hit-Metering and Usage-Limiting for HTTP"</a></dd>
    <dt>RFC2295</dt>
    <dd><a href="http://rfc.askapache.com/rfc2295/">"Transparent Content Negotiation in HTTP"</a></dd>
    <dt>RFC2310</dt>
    <dd><a href="http://rfc.askapache.com/rfc2310/">"The Safe Response Header Field"</a></dd>
    <dt>RFC2324</dt>
    <dd><a href="http://rfc.askapache.com/rfc2324/">"Hyper Text Coffee Pot Control Protocol (HTCPCP/1.0)"</a></dd>
    <dt>RFC2397</dt>
    <dd><a href="http://rfc.askapache.com/rfc2397/">"The 'data' URL scheme"</a></dd>
    <dt>RFC2518</dt>
    <dd><a href="http://rfc.askapache.com/rfc2518/">"HTTP Extensions for Distributed Authoring -- WEBDAV"</a></dd>
    <dt>RFC2616</dt>
    <dd><a href="http://rfc.askapache.com/rfc2616/">"Hypertext Transfer Protocol -- HTTP/1.1"</a></dd>
    <dt>RFC2617</dt>
    <dd><a href="http://rfc.askapache.com/rfc2617/">"HTTP Authentication: Basic and Digest Access Authentication"</a></dd>
    <dt>RFC2660</dt>
    <dd><a href="http://rfc.askapache.com/rfc2660/">"The Secure HyperText Transfer Protocol"</a></dd>
    <dt>RFC2774</dt>
    <dd><a href="http://rfc.askapache.com/rfc2774/">"An HTTP Extension Framework"</a></dd>
    <dt>RFC2965</dt>
    <dd><a href="http://rfc.askapache.com/rfc2965/">"HTTP State Management Mechanism"</a></dd>
    <dt>RFC3229</dt>
    <dd><a href="http://rfc.askapache.com/rfc3229/">"Delta encoding in HTTP"</a></dd>
    <dt>RFC3230</dt>
    <dd><a href="http://rfc.askapache.com/rfc3230/">"Instance Digests in HTTP"</a></dd>
    <dt>RFC3253</dt>
    <dd><a href="http://rfc.askapache.com/rfc3253/">"Versioning Extensions to WebDAV (Web Distributed Authoring and Versioning)"</a></dd>
    <dt>RFC3648</dt>
    <dd><a href="http://rfc.askapache.com/rfc3648/">"Web Distributed Authoring and Versioning (WebDAV) Ordered Collections Protocol"</a></dd>
    <dt>RFC3986</dt>
    <dd><a href="http://rfc.askapache.com/rfc3648/">"Uniform Resource Identifier (URI): Generic Syntax"</a></dd>
    <dt>RFC4229</dt>
    <dd><a href="http://rfc.askapache.com/rfc4229/">"HTTP Header Field Registrations"</a></dd>
    <dt>SOAP1.1</dt>
    <dd><a href="http://www.w3.org/TR/2000/NOTE-SOAP-20000508">"Simple Object Access Protocol (SOAP) 1.1"</a></dd>
    <dt>UA Attributes</dt>
    <dd>"User-Agent Display Attributes Headers"</dd>
    <dt>WIRE</dt>
    <dd><a href="http://www3.ietf.org/proceedings/98dec/I-D/draft-girod-w3-id-res-ext-00.txt">"WIRE - W3 Identifier Resolution Extensions"</a></dd>
</dl><p><a href="http://www.askapache.com/online-tools/http-headers-tool"></a><a href="http://www.askapache.com/online-tools/http-headers-tool">Raw HTTP Header Debugger</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/online-tools/http-headers-tool/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>HOWTO: Uninstall CPANEL over SSH</title>
		<link>http://www.askapache.com/hacking/uninstall-cpanel.html</link>
		<comments>http://www.askapache.com/hacking/uninstall-cpanel.html#comments</comments>
		<pubDate>Mon, 04 Jul 2011 18:55:40 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Hacking]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4404</guid>
		<description><![CDATA[<p>The following is just a quick reference of some of the commands I used to successfully uninstall cpanel.  This is for advanced users of the shell.  If you aren't that advanced and you run a single one of these commands without fully understanding it, you will probably kill your server, probably lose everything on it permanently, probably not have a website or email for weeks..  So backup all your data FIRST.  Also, if you aren't 100% sure you won't run into problems, you should contact your hosts technical support - but be prepared for some MAJOR negativity..  cpanel makes things very easy for hosts, you are just a drop in their bucket.</p>

<blockquote cite="http://www.askapache.com/server-administration/uninstall-cpanel.html#comment-168222">
<p><strong>Wow!</strong></p>
<p>You sure gotta bigger set that *I* do. . . . - for real! I've been known to do some abysmally stupid things in my day - and actually had them work the way I wanted them to! - but this takes the <strong>titanium, gadolinium, rhodium alloy cake</strong>!</p>
<p>Me, I'd try something like that and find out later that the fire-trucks showed up right after I hit the "Enter" key. It's a REALLY interesting post, and a real eye-opener - especially for someone who is relatively new to the whole web-hosting-service paradigm.  I know, no guts, no glory - but THIS is WAY over the top!  I'm reading this and thinking <em>"Why not just put a couple of sticks of dynamite under the thing?"</em></p>
<p>Seriously now, this was an excellent read - and for someone who is just now looking into the whole web-hosting paradigm, it's a real eye-opener.  Though I think I'll just tiptoe past this <strong>REAL QUIETLY</strong> for now. . . .  (laughing!)</p>
<p><a href="http://www.qatechtips.com/">Jim</a></p>
</blockquote>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"></a><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"><cite>AskApache.com</cite></a></p><p><strong>WARNING!</strong> This is for advanced users of the shell, this is NOT a howto or tutorial.  The thing is, I googled <strong>how to uninstall cpanel</strong> and for once in my life I came up empty.. And certainly the cpanel official sites themselves don't provide any instructions other than to say "Dont uninstall it, reinstall your entire operating system without it."..   they sure don't seem confident that they know exactly what their code is doing.  Cpanel is great for most people, perfect for many situations, so don't get me wrong.. this is just for fun.</p>

<h2>Why Uninstall?</h2>
<p>Why?  Because I have always built my servers, php installations, perl installs, ruby, iptables, everything from source.  I read the INSTALL/README docs, I read the man pages, and I read the info pages as well.  I google for configuration advice, I google for tips, and I don't need a web-based perl script messing my stuff up!</p>
<p>The main problems I had with cpanel, which really is a great bit of software for millions of website developers, is that it was incredibly sneaky!  I used it for about 6 months and spent that entire time trying to figure out what the heck it was doing.  A couple issues that I really disliked, it takes over your bind install, it takes over your apache install, it takes over your php install.  And although it does let you configure some things (very few) for custom configurations and the like, I just don't need any of that.  By removing the darn thing I am saving GIGS of space on my server, tons of bandwidth, and most importantly to me I am saving CPU and processing time along with RAM and IO speed.</p>
<h3>Anything Else</h3>
<p>Please.. I could go on for DAYS!  Another reason I have wanted to be rid of cpanel is that I like my servers to be as lean and mean as possible.  This means I like as few files and processes as possible.  There are many benefits to this, like it's much easier for my integrity checking software and rootkit/antivirus software to run and drastically reduces the false positives.  And there is that glaring security issue of constantly having cpanel run it's own software to create the WHM/Cpanel web interface, which is accessible online.  I haven't researched cpanel security at all, it's possible that it never has security problems that are published, but for me, why take the chance?</p>


<h2>Warning - Caution!</h2>
<p>The following is just a quick reference of some of the commands I used to uninstall cpanel.  This is for advanced users of the shell.  If you aren't that advanced and you run a single one of these commands without fully understanding it, you will probably kill your server, probably lose everything on it permanently, probably not have a website or email for weeks..  So backup all your data FIRST.  Also, if you aren't 100% sure you won't run into problems, you should contact your hosts technical support - but be prepared for some MAJOR negativity..  cpanel makes things very easy for hosts, and the last thing tech support wants is to fix a server broken by someone who doesn't know what they are doing.</p>

<h2>Last Warning!</h2>
<p>Unless you understand what theses commands do and the purpose they serve, do not try any of this.  These are not the exact commands I used verbatim, they are also not in order.  I only put them up here because I was so amazed that google didn't have any uninstall cpanel intructions.  Hopefully it's not a conspiracy that will get my site taken down.. ;)</p>
<p>That said and out of the way, it really only took me about 10 minutes to uninstall cpanel completely.  But keep in mind I have been closely monitoring and debugging cpanel for 6 months, so I knew what I was doing.  And finally, I do apologize for not having better instructions.. but hey, if you don't get this then you have no business trying to figure out how to uninstall cpanel!  It's great software and shouldn't be removed unless you are fully capable of managing email/dns/www/ftp and any/all other servers and services on your machine by hand.</p>

<h2>Do This First</h2>
<p>I have a few drafts I'm working on at the moment with specifics, but for now you will have to figure it out with google.  Basically you want to make sure you don't totally knock your machine offline without being able to reconnect.  What I do is compile a static version of openssh and a few other security-type shell tools, and configure this binary sshd to run by using inittab, which is the file run by init (pid 1) and makes sure if it dies it is restarted.  Here is my /etc/inittab to run the static sshd binary:</p>
<pre>hh:12345:respawn:/failover/os/sbin/aassh -D -q -u0 -f /failover/os/etc/aassh</pre>

<p>Another trick is to keep a detached screen logged in to root.  That way if you mess up your sudoers or securetty or pam or whatever, you can just reattach and fix it.</p>
<p>Finally, you may want to setup your syslog to start earlier than usual, and set up more than normal verbosity.  ( I take it to the max ).  Then you should setup a 2nd server or machine somewhere to act as a syslog server.  Lastly, configure your web server syslog to copy all messages to the remote syslog you set up.  I use a reverse ssh tunnel to encrypt the syslog packets, but when I do something serious like reboot after uninstalling cpanel, I prepare for it by adding additional networking routes on my machine to make sure I will get some logs even if sshd cant start or even if my network addresses aren't brought up correctly.</p>
<p>If that sounds easy to you, please continue.   If you are saying: Wha??? Continue in read-only mode.</p>

<p class="cnote">Also, you can't just uninstall cpanel, I have replaced a lot of cpanel already, like building my own bind, apache, php, syslog and making sure they work and aren't being tampered with by cpanel.  Basically cpanel runs everything on your server in most cases, so you should prepare by creating your own static software to replace cpanel, and make sure it works.</p>


<h2>Find files Accessing /var/cpanel</h2>
<p>More than likely these will need to be killed.</p>
<pre>lsof +w -Rg -nP +c15 -x f +D /var/cpanel
lsof +w -Rg -nP +c15 -x f +D /usr/local/cpanel</pre>

<h2>Killing cpanel</h2>
<p>Just an example, your machine may have a lot more than these, I have been slowly taking control of my machine back from cpanel for 6 months, so it was easier for me.</p>
<pre>for P in tailwatchd queueprocd cpanellogd exim; do pkill -9 $P; done</pre>

<h2>Commands and Shortcuts</h2>
<pre>alias NF=&#039;nice find $PWD -mount -depth ! -type d&#039;
alias NFF=&#039;nice find $PWD -mount -depth ! -type d | xargs -IF87 file F87&#039;
alias NA=&#039;nice find $PWD -mount -depth&#039;
alias NAF=&#039;nice find $PWD -mount -depth | xargs -IF87 file F87&#039;</pre>


<h2>Watch out for crontab</h2>
<p>An example of the sneakiness (from my POV, from most it's called builtin robustness) that cpanel does is automagically adding crontab entries that make it behave similarly to a self-propagating virus.  If you don't disable the cronjobs and kill the right processes within a short period of time, be prepared for a magic resurrection.</p>

<p>Here's my awesome crontab information function, you will need to check every file, it lists the default crons on my box, and every users crontab, but it can't account for other cron software like at and other crons.</p>
<pre>function askapache_crontab()
{
  local GG i;
  for i in `getent passwd|cut -d ":" -f1`;
  do
    GG=$(sudo crontab -u $i -l 2&gt;$N6 | tr -s &#039;\n\000&#039; | sed &#039;/^#/d&#039;);
    [[ ${#GG} -gt 3 ]] &amp;&amp; sleep 1 &amp;&amp; echo -e "$i \n\n${GG}"
  done;
   sleep 4;
   ls -aLls1ch --color=always /etc/cron.{hourly,daily,weekly,monthly,d} | sed &#039;/^total/d; /\ drwxr-xr-x/d&#039;;
}</pre>



<pre>grep -ir /var/spool cpan</pre>
<pre>#6 3 * * * /scripts/upcp
#0 1 * * * /scripts/cpbackup
#0 2 * * * /scripts/mailman_chown_archives
#35 * * * * /usr/bin/test -x /usr/local/cpanel/bin/tail-check &amp;&amp; /usr/local/cpanel/bin/tail-check
#11,26,41,56 * * * * /usr/local/cpanel/whostmgr/bin/dnsqueue &gt; /dev/null 2&gt;&amp;1
#30 */4 * * * /usr/bin/test -x /scripts/update_db_cache &amp;&amp; /scripts/update_db_cache
#45 */8 * * * /usr/bin/test -x /usr/local/cpanel/bin/optimizefs &amp;&amp; /usr/local/cpanel/bin/optimizefs
#*/5 * * * * /usr/local/cpanel/bin/dcpumon &gt;/dev/null 2&gt;&amp;1
#25 1 * * * /usr/local/cpanel/whostmgr/docroot/cgi/cpaddons_report.pl --notify</pre>



<h2>Delete Crontabs</h2>
<pre>sudo crontab -u mailman -r</pre>


<h2>Find INIT scripts with cpanel</h2>
<p>This is the main startup script: <code>/usr/local/cpanel/etc/init/startup</code></p>
<p>I had no idea ruby-on-rails was being controlled by cpanel.. sneaky bugger.  You can tell by all of these advanced unix commands just how difficult it would be to uninstall cpanel, its totally like the Alien!</p>
<pre>(1:3744)# find . ! -type d -print0|xargs -0 -I&#039;F87&#039; grep -Hi "cpan\|tailwat\|chkser" F87
./fastmail:# Author:       cPanel, Inc. &lt;nick@cpanel.net&gt;
./httpd:        HTTPD=/usr/local/cpanel/bin/chroothttpd
./cpanel:# cpanel8       Start Cpanel Services
./cpanel:# Author:       cPanel, Inc. &lt;nick@cpanel.net&gt;
./cpanel:# description: This is the cpanel webserver and chat.
./cpanel:# processname: cpaneld
./cpanel:# pidfile: /var/run/cpanel.pid
./cpanel:[ -f /usr/local/cpanel/etc/init/startup ] || exit 0
./cpanel:       if [ -f "/var/cpanel/smtpgidonlytweak" ]; then
./cpanel:       echo -n "Starting cPanel services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcpsrvd
./cpanel:       echo -n "Starting cPanel brute force detector services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcphulkd
./cpanel:    echo -n "Starting cPanel dav services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startcpdavd
./cpanel:               daemon /usr/local/cpanel/etc/init/startcppop
./cpanel:       echo -n "Starting cPanel Chat services: "
./cpanel:               daemon /usr/local/cpanel/entropychat/entropychat
./cpanel:               daemon /usr/local/cpanel/bin/startmelange
./cpanel:                       /usr/local/cpanel/bin/startinterchange
./cpanel:       echo -n "Starting cPanel ssl services: "
./cpanel:       daemon /usr/local/cpanel/startstunnel
./cpanel:    echo -n "Starting cPanel Queue services: "
./cpanel:       daemon /usr/local/cpanel/etc/init/startqueueprocd
./cpanel:    echo -n "Starting tailwatchd: "
./cpanel:    daemon /usr/local/cpanel/libexec/tailwatchd --start
./cpanel:       echo -n "Starting cPanel Log services: "
./cpanel:       daemon /usr/local/cpanel/cpanellogd
./cpanel:    action "Starting mailman services: " /usr/local/cpanel/etc/init/startmailman
./cpanel:    action "Stopping tailwatchd: " /usr/local/cpanel/libexec/tailwatchd --stop
./cpanel:    action "Stopping cPanel services: " /usr/local/cpanel/etc/init/stopcpsrvd
./cpanel:       action "Stopping cPanel dav services: " /usr/local/cpanel/etc/init/stopcpdavd
./cpanel:       action "Stopping cPanel queue services: " /usr/local/cpanel/etc/init/stopqueueprocd
./cpanel:       action "Stopping cPanel brute force detector services: " /usr/local/cpanel/etc/init/stopcphulkd
./cpanel:               action "Stopping pop3 services: " /usr/local/cpanel/etc/init/stopcppop
./cpanel:       echo -n "Stopping cPanel log services: "
./cpanel:       killproc cpanellogd
./cpanel:       echo -n "Stopping cPanel Chat services: "
./cpanel:       action "Stopping cPanel ssl services: " /usr/local/cpanel/etc/init/stopstunnel
./cpanel:       action "Stopping mailman services: " /usr/local/cpanel/etc/init/stopmailman
./cpanel:       if [ -e "/usr/local/cpanel/3rdparty/mailman/bin/mailmanctl" ]; then
./exim:if [ -e "/etc/chkserv.d" ]; then
./exim:        for file in `ls /etc/chkserv.d`
./exim:            if [ ! -e "/usr/local/cpanel/libexec/tailwatchd" ]; then
./exim:    if [ -x "/usr/local/cpanel/etc/init/startspamd" ]; then
./exim:        /usr/local/cpanel/etc/init/startspamd
./exim:        if [ ! -e "/usr/local/cpanel/libexec/tailwatchd" ]; then
./ror:  /usr/local/cpanel/bin/rormgr --startboot
./ror:  /usr/local/cpanel/bin/rormgr --stopall
./ror:  /usr/local/cpanel/bin/rormgr --stopall
./ror:  /usr/local/cpanel/bin/rormgr --startboot
./ror:  /usr/local/cpanel/bin/rormgr --statusall
./securetmp:# Author:       cPanel, Inc. &lt;copyright@cpanel.net&gt;</pre>

<h3>Turn off cpanel services</h3>
<p>You should remove the below delete command and start by just disabling the inits by turning them off.  Then reboot. Then delete.  If your machine won't reboot, I told you so, Cpanel told you so, and likely your host told you so.</p>
<pre>for S in cpanel ror securetmp fastmail exim; do R=$(command chkconfig --level 123456 $S off ||echo); R=$(command chkconfig --del $S ||echo); done</pre>


<h4>HTTPD</h4>
<p>If you are running chrooted httpd then you'll need to make sure you don't delete your entire webserver on accident.  Here's a relevant part from the /etc/init.d/httpd script.</p>
<pre># the path to your httpd binary, including options if necessary
if [ -e "/etc/chroothttpd" ]; then
        HTTPD=/usr/local/cpanel/bin/chroothttpd
else
        HTTPD=/usr/local/apache/bin/httpd
fi</pre>




<h2>Finding files owned by cpanel</h2>
<p>Some super cool bash commands in this post.. let's start with one to find all the files and folders on your machine owned by cpanel.  Check your /etc/passwd file for your machines specific usernames and groups.  This command saves all the filenames to ~/cpanel-files-backup.txt, which is used by tar next to create a backup of all of them.</p>
<pre>{ find / -mount -depth -maxdepth 150 \( -group cpanel -o   -group cpanel-phpmyadmin -o -group cpanel-phppgadmin   -o -group cpanelphpmyadmin   -o -group cpanelphppgadmin   -o -group cpanelhorde   -o -group cpanelroundcube \) -print; find / -mount -depth -maxdepth 150 \( -user cpanel -o   -user cpanel-phpmyadmin -o -user cpanel-phppgadmin   -o -user cpanelphpmyadmin   -o -user cpanelphppgadmin   -o -user cpanelhorde   -o -user cpanelroundcube \) -print; } &gt; ~/cpanel-files-backup.txt</pre>

<p>Here's another way to search directories.</p>
<pre> grep --color=always -Hir cpanel /var</pre>

<h2>Create the Backup</h2>
<p>Note that you must have the latest version of tar for this exact command, also you should backup /var/cpanel and /usr/local/cpanel and /etc and heck the whole machine why dontcha!</p>
<pre>tar -T ~/cpanel-files-backup.txt -cvz --checkpoint=1000 --checkpoint-action="ttyout=\rHit %s checkpoint #%u" -f /cpanel-files-backup.tgz --totals</pre>


<h2>Remove Files</h2>
<p>Once you do this your upstream without a paddle, you better make sure you know what you're doing with this.  This removes all those files.</p>
<pre>cat ~/cpanel-files-backup.txt | xargs -I&#039;F87&#039; rm -vfr F87</pre>

<p>Additionally you will want to remove /usr/local/cpanel and /var/cpanel - What I always do when running as root is alias my rm command to instead simply move the files to a .trash folder.  That way if something goes bork you have a better chance at fixing it.</p>


<h2>Find Group-Owned Files</h2>
<pre>find / -mount -depth -maxdepth 150 \
\(  -group cpanel -o \
  -group cpanel-phpmyadmin \
  -o -group cpanel-phppgadmin \
  -o -group cpanelphpmyadmin \
  -o -group cpanelphppgadmin \
  -o -group mailman \
  -o -group cpanelhorde \
  -o -group cpanelroundcube \
\) -fprintf /root/cpanel-group-files.log &#039;%#8k %#5m %11M %#10u:%-10g %-5U:%-5G %p %f %Y %F\n&#039;</pre>

<h2>Find User-Owned Files</h2>
<pre>find / -mount -depth -maxdepth 150 \(
  -user cpanel \
  -o -user cpanel-phpmyadmin \
  -o -user cpanel-phppgadmin \
  -o -user cpanelphpmyadmin \
  -o -user cpanelphppgadmin \
  -o -user mailman \
  -o -user cpanelhorde \
  -o -user cpanelroundcube
\) -fprintf /root/cpanel-users-files.log &#039;%#8k %#5m %11M %#10u:%-10g %-5U:%-5G %p %f %Y %F\n&#039;</pre>



<pre>       4  0755  drwxr-xr-x     cpanel:cpanel     32002:32004 /var/cpanel/userhomes/cpanel cpanel d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/tmp tmp d reiserfs
       4  0644  -rw-r--r-- cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel/caches caches d reiserfs
       4  0700  drwx------ cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/.cpanel .cpanel d reiserfs
       4  0750  drwxr-x--- cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin/mail mail d reiserfs
       4  0711  drwx--x--x cpanel-phpmyadmin:cpanel-phpmyadmin 32005:32007 /var/cpanel/userhomes/cpanel-phpmyadmin cpanel-phpmyadmin d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/sessions sessions d reiserfs
       4  0644  -rw-r--r-- cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel/caches caches d reiserfs
       4  0700  drwx------ cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/.cpanel .cpanel d reiserfs
       4  0750  drwxr-x--- cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin/mail mail d reiserfs
       4  0711  drwx--x--x cpanelphppgadmin:cpanelphppgadmin 32009:32011 /var/cpanel/userhomes/cpanelphppgadmin cpanelphppgadmin d reiserfs
       4  0750  drwxr-x--- cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube/mail mail d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube/sessions sessions d reiserfs
       4  0711  drwx--x--x cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/userhomes/cpanelroundcube cpanelroundcube d reiserfs
       4  0644  -rw-r--r--     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches/featurelists/default.cache default.cache f reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches/featurelists featurelists d reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel/caches caches d reiserfs
       4  0700  drwx------     cpanel:cpanel     32002:32004 /var/cpanel/.cpanel .cpanel d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/roundcube/tmp tmp d reiserfs
       4  0700  drwx------ cpanelroundcube:cpanelroundcube 514  :514   /var/cpanel/roundcube/log log d reiserfs</pre>


<h3>Find Permissions</h3>
<pre>cat ~/cpanel-group-files.log ~/cpanel-users-files.log |tr -s &#039;\000 \t&#039;|cut -d&#039; &#039; -f3|sort -u</pre>






<h3>Find files tailwatchd</h3>
<pre>(1:3732)# $NICE find ${1:-`pwd`} -mount -name &#039;*tailwatch*&#039;
/usr/local/cpanel/libexec/tailwatchd
/usr/local/cpanel/libexec/tailwatch
/usr/local/cpanel/libexec/tailwatch/tailwatchd
/usr/local/cpanel/etc/init/scripts/freebsd/tailwatchd.sh
/usr/local/cpanel/etc/init/scripts/trustix/tailwatchd
/usr/local/cpanel/etc/init/scripts/centos/tailwatchd
/usr/local/cpanel/etc/init/scripts/suse/tailwatchd
/usr/local/cpanel/etc/init/scripts/caos/tailwatchd
/usr/local/cpanel/etc/init/scripts/whitebox/tailwatchd
/usr/local/cpanel/etc/init/scripts/mandrake/tailwatchd
/usr/local/cpanel/etc/init/scripts/debian/tailwatchd
/usr/local/cpanel/etc/init/scripts/redhat/tailwatchd
/usr/local/cpanel/etc/init/scripts/fedora/tailwatchd
/usr/local/cpanel/etc/init/stoptailwatchd
/usr/local/cpanel/etc/init/starttailwatchd
/usr/local/cpanel/bin/tailwatchd
/usr/local/cpanel/logs/tailwatchd_log
/var/log/cpanel/tailwatchd_log
/var/cpanel/log_rotation/cp_tailwatchd_log.cpanellogd
/var/cpanel/tailwatch.positions
/var/run/tailwatchd.pid
/etc/chkserv.d/tailwatchd
/scripts/restartsrv_tailwatchd</pre>


<h2>Delete cpanel Users/Groups</h2>
<pre>for U in cpanel-phpmyadmin cpanel-phppgadmin cpanelphpmyadmin cpanelphppgadmin cpanelhorde cpanelroundcube machbuild; do userdel -fr $U; groupdel $U; done</pre>

<h2>Check for broken symlinks</h2>
<pre>find / -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039;</pre>
<p>Especially check /etc</p>
<pre>$ find /etc -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039;
/etc/ftpd-rsa.pem                   broken symbolic link to `/var/cpanel/ssl/ftp/ftpd-rsa.pem&#039;
/etc/rc.d/rc1.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc1.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc1.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc3.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc3.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc3.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc6.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc6.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc6.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc5.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc5.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc5.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc2.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc2.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc2.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc4.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/rc.d/rc4.d/S80chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc4.d/S80antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc0.d/K10chkservd         broken symbolic link to `../init.d/chkservd&#039;
/etc/rc.d/rc0.d/K30antirelayd       broken symbolic link to `../init.d/antirelayd&#039;
/etc/rc.d/rc0.d/K80dcc              broken symbolic link to `../init.d/dcc&#039;
/etc/authlib/authProg               broken symbolic link to `/usr/local/cpanel/bin/courier-auth&#039;</pre>

<p>And delete if you are sure</p>
<pre>find /etc -mount -depth -type l -print0 |xargs -0 -P0 -I&#039;F87&#039; file -s &#039;F87&#039; | sed -n &#039;/: broken symbolic link to/p&#039; |cut -d&#039; &#039; -f1|xargs -I&#039;F87&#039; rm -rvf &#039;F87&#039;</pre>


<h2>Reinstall CSF</h2>
<p>The only thing I actually used that came with cpanel is the CSF/LFD Firewall package, which is a fantastic piece of software.  I had to reinstall this, and to get it working without cpanel add the following line to the csf.conf</p>
<pre>GENERIC = "1"</pre>

<h2>Thats It</h2>
<p>Now once you've cleaned up everything, you should try everything conceivable to get an error before rebooting.  Like you should start and stop every service in /etc/init.d/, you should use telinit to check various runlevels (which keeps your sshd connection still live).  Go all out, should take at least a full hour.</p>
<p>Another thing I like to do is rebuild alot of my source-built software again in case anything got messed up.  I upgrade perl from cpanels 5.8.8 to 5.10, which is pretty thorough, and you know, reinstall anything else I think I might need.  One of the benefits of compiling your own software is all I have to do is cd to the source directory and type <code>make -B &amp;&amp; ( { make test || make check || make checks || make tests; } || echo  ) &amp;&amp; sudo make install</code> and that's it.  The tests/checks are optional of course.</p>


<p>If anyone actually ever reads this and does it, please share your advice here.. everybody knows we need it!  Good Luck</p><p><a href="http://www.askapache.com/hacking/uninstall-cpanel.html"></a><a href="http://www.askapache.com/hacking/uninstall-cpanel.html">HOWTO: Uninstall CPANEL over SSH</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/hacking/uninstall-cpanel.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Enhanced printenv Script for Server Debugging</title>
		<link>http://www.askapache.com/hosting/enhanced-printenv.html</link>
		<comments>http://www.askapache.com/hosting/enhanced-printenv.html#comments</comments>
		<pubDate>Thu, 14 Apr 2011 19:05:17 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Hosting]]></category>

		<guid isPermaLink="false">http://www.askapache.com/?p=4920</guid>
		<description><![CDATA[<p>A souped-up version of the Apache printenv script for hard-core server environment debuggery.</p>
<pre>#!/bin/sh
echo -e "Content-type: text/plain\n\n"
...
  __T "CURRENT PROCESS CMDLINE"
  {
   for p in `echo /proc/[0-9]*/cmdline`;
   do
    pid=${p:6:$((${#p}-13))}
    [[ $pid == $PPID &#124;&#124; $pid == $$ ]] &#38;amp;&#38;amp; continue;
    __M "[ /proc/$pid ]";
    sed &#039;s/\x00/ /g;G&#039; $p 2&#62;/dev/null
   done
  }
 fi</pre>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/hosting/enhanced-printenv.html"></a><a href="http://www.askapache.com/hosting/enhanced-printenv.html"><cite>AskApache.com</cite></a></p><p>Every Apache server comes pre-shipped with an old cgi script named <tt>printenv</tt>.  It's useful and used for printing out the environment variables from your servers point of view.  Basically you save this file where you can then call it from your browser, like <code>site.com/printenv.cgi</code> -- then it will be executing as the user running the web server, <tt>nobody</tt>, <tt>apache</tt>, etc..   So this tells you all sorts of interesting things about your server, especially if you want/need to know about the users, groups, and file permissions.</p>

<h2>Enabling CGI</h2>
<p>You need to do 1 of 2 things to use this:</p>
<ol><li>Make it executable and in your server directory</li>
<li>Use a trick to cause your server to execute it regardless</li></ol>

<h2>Htaccess CGI</h2>
<p>If you have htaccess then you most likely can get this to work by giving it an execute bit with chmod or from your ftp client, and then use htaccess like this:</p>
<pre>Options +ExecCGI Indexes +FollowSymLinks
AddHandler cgi-script .cgi .pl .sh
&nbsp;
Order Deny,Allow
Deny from All
Allow from 127.0.0.1 ADDYOURIPHERE env=REDIRECT_STATUS
Satisfy All</pre>
<p>Search around on this site for php.cgi tricks if you can't seem to get it.  Basically you can try stuff like making it an errordocument, using other directives like forcetype, AddType, and even try stuff like mod_security's upload binary setting.</p>

<p class="cnote">You do not want anyone other than you ever looking at the output of this.  It's so full of details about your machine that it would be a huge security problem.</p>

<h2>The AskApache Printenv</h2>
<pre>#!/bin/sh
echo -e "Content-type: text/plain\n\n"
&nbsp;
# FUNCTIONS
################################################################################################################
function __A ()
{ local __a __i __z;for __a;do __z=\${!${__a}*};for __i in `eval echo "${__z}"`;do echo -e "$__i: ${!__i}";done;done; }
&nbsp;
function __S ()
{ local L IFS=&#039;;&#039;;while read -r L;do builtin printf "${#L}@%s\n" "$L";done|sort -n|sed -u &#039;s/^[^@]*//&#039;; }
&nbsp;
function __P ()
{ local l=`builtin printf %${2:-$__WIDTH}s` &amp;&amp; echo -e "${l// /${1:-=}}"; }
&nbsp;
function __T ()
{ echo -e "\n\n+`__P -`+\n| $*\n+`__P &#039;=&#039;`+"; }
&nbsp;
function __M ()
{ echo -e " &gt;&gt;&gt; $M" $*; }
&nbsp;
function __H ()
{ command builtin type $1 &amp;&gt;/dev/null &amp;&amp; local a="yes" || return 1; }
&nbsp;
function LE ()
{
 [[ ! -r /proc/${1:-$$}/limits ]] &amp;&amp; return;
 sed -e &#039;1z;s/ *$//;:a;$!N;s/\nM.. [a-z]* [a-z]* [a-z]* \{1,\}\([^ ]*\) *\([^ ]*\) *[a-z]* */\1:\2 /;ta;s/u\w\+d/u/g;s/ *$//;s/ / | /g;s/\([^:]\+\):\1/\1:=/g&#039; /proc/${1:-$$}/limits;
}
function LH ()
{
 [[ ! -r /proc/${1:-$$}/limits ]] &amp;&amp; return;
 sed -e &#039;1z;s/ *$//;:a;$!N;s/\nM.. \([a-z]\+ [a-z]* [a-z]*\) \{1,\}\([^ ]*\) *\([^ ]*\) *\([a-z]*\) */:\1/;ta;s/ *:/:/g;s/size/sz/g;s/file/f/g;s/ p\w\+y/ pri/g;s/memory/mem/g;s/p\w\+s/procs/g;s/^://;s/:/ | /g&#039; /proc/${1:-$$}/limits
}
&nbsp;
# CUSTOM SETTINGS
################################################################################################################
__WIDTH=170
LC_COLLATE=C LC_CTYPE=C LC_ALL=C
&nbsp;
# RUNTIME SETUP
#################################################################################################################
shopt -s dotglob nocaseglob extglob
&nbsp;
# -C If set, disallow existing regular files to be overwritte
# -f Disable file name generation (globbing
# -e Exit immediately if a command exits with a non-zero status
# -B enable brace expansion
# +H disable History
set -C +f +H -B
&nbsp;
# make sure we dont create any files
umask 0177
&nbsp;
# redirect everything to output (no logs or stderr is used)
exec 2&gt;/dev/null
&nbsp;
# MAIN EXECUTION
#################################################################################################################
{
 __T "EXPANDING PATH"
 {
  __M "ORIG PATH:$PATH"
  PATH=$PATH:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/libexec:/usr/local/apache/bin
  for t in ${PATH//:/ };
  do
   [[ -d "$t" ]] &amp;&amp; sed -n -e "/:${t//\//\\/}:/Q1" &lt;&lt;&lt; ":${p:=}:" &amp;&amp; p=$p:$t || continue;
  done
  PATH=${p/:/}:.
  __M "NEW PATH:$PATH"
 }
&nbsp;
 __T "USER INFO"
 {
  __M "UMASK: `(umask 2&gt;/dev/null)` ( `(umask -S 2&gt;/dev/null)` )"
  __H uname &amp;&amp; __M "UNAME: `eval echo $(uname -a 2&gt;/dev/null)`"
  __H whoami &amp;&amp; __M "WHOAMI: `(whoami 2&gt;/dev/null)`"
  __H id &amp;&amp; __M "ID: `(id 2&gt;/dev/null)`"
  __H logname &amp;&amp; __M "LOGNAME: `(logname 2&gt;/dev/null)`"
  __H groups &amp;&amp; __M "GROUPS: `(groups 2&gt;/dev/null)`"
  echo -e "\n\n"
 }
&nbsp;
 if __H who;
 then
  __T "LOGGED ON USERS"
  {
   (who -a 2&gt;/dev/null)
  }
 fi;
&nbsp;
 if [[ -r /etc/passwd ]];
 then
  __T "/etc/passwd"
  {
   (cat /etc/passwd)
  }
 fi;
&nbsp;
 if __H ulimit;
 then
  __T "USER LIMITS"
  {
   ulimit -a
  }
 fi
&nbsp;
 if [[ -d /dev ]] &amp;&amp; __H ls;
 then
  __T "/dev Directory"
  {
   ( ls -vlaph /dev 2&gt;/dev/null )
  }
 fi;
&nbsp;
 if [[ -d /proc ]];
 then
  __T "CURRENT PROCESS LIMITS"
  {
   for p in `echo /proc/[0-9]*/limits`
   do
    pid=${p:6:$((${#p}-13))}
    [[ $pid == $PPID || $pid == $$ ]] &amp;&amp; continue;
    echo -e "\n/proc/$pid:"
    sed &#039;1s/\x00/ /g;n;s/\x00/\n/g;/.\{2,\}/!d&#039; /proc/$pid/cmdline $p 2&gt;/dev/null
   done
  }
&nbsp;
  __T "CURRENT PROCESS CMDLINE"
  {
   for p in `echo /proc/[0-9]*/cmdline`;
   do
    pid=${p:6:$((${#p}-13))}
    [[ $pid == $PPID || $pid == $$ ]] &amp;&amp; continue;
    __M "[ /proc/$pid ]";
    sed &#039;s/\x00/ /g;G&#039; $p 2&gt;/dev/null
   done
  }
 fi
&nbsp;
 __T "IP INFORMATION"
 {
  __H ip &amp;&amp; __M "IP:" &amp;&amp; (ip -o -f inet addr 2&gt;/dev/null) | sed &#039;s/^.*inet \([0-9.]*\).*$/\1/g&#039;;
  __H nmap &amp;&amp; __M "NMAP:" &amp;&amp; (nmap --iflist 2&gt;/dev/null) | sed 1,4d | sed -n &#039;/ethernet/s/^.*) \([0-9.]*\).*$/\1/gp&#039;;
  __H ifconfig &amp;&amp; __M "IFCONFIG:" &amp;&amp; (ifconfig -a 2&gt;/dev/null) | sed -n &#039;/inet a/s/^.*addr:\([0-9.]*\).*$/\1/gp&#039;;
  [[ -f "$HOME/.cpanel/datastore/_sbin_ifconfig_-a" ]] &amp;&amp; __M "CPANEL CACHE:" &amp;&amp; sed -e &#039;/inet/!d; s/.*addr:\([0-9\.]*\).*/\1/g&#039; "$HOME/.cpanel/datastore/_sbin_ifconfig_-a" | sort -u
 }
&nbsp;
 __T "ROUTE / INTERFACE INFO"
 {
  __H route &amp;&amp; __M "ROUTE" &amp;&amp; (route -nv 2&gt;/dev/null)
  __H ip &amp;&amp; ( ip rule &amp;&amp; ip route &amp;&amp; ip address ) 2&gt;/dev/null
  __H ifconfig &amp;&amp; (ifconfig -a 2&gt;/dev/null)
 }
&nbsp;
 __T "CGI/1.0 test script report:"
 {
  __A SERVER REQUEST GET SERVER PATH REMOTE AUTH CONTENT HTTP TZ GATEWAY QUERY MO
  echo -e "\n\n"
 }
&nbsp;
 __T "HIDDEN VARIABLES"
 {
  __A {a..z} {A..Z} _{0..9} _{A..Z} _{a..z} | cat -Tsv 2&gt;/dev/null
  echo -e "\n\n"
 }
&nbsp;
 __T "DECLARE INFO"
 {
  for i in "r" "i" "a" "x" "t" "-";
  do
   builtin eval declare -$i &amp;&amp; echo;
  done | sed &#039;s/^declare //&#039; | cat -Tsv 2&gt;/dev/null
  echo -e "\n\n"
 }
&nbsp;
 __T "SHELL OPTIONS"
 {
  __A SHELLOPTS BASHOPTS
  echo -e "\$-: $-"
  __P &#039;-&#039; &amp;&amp; builtin shopt -s -p
  __P &#039;-&#039; &amp;&amp; builtin shopt -u -p
  echo -e "\n\n"
 }
&nbsp;
 __T "ENV AND EXPORT"
 {
  __H env &amp;&amp; command env | cat -Tsv 2&gt;/dev/null &amp;&amp; __P &#039;-&#039;
  builtin export | cat -Tsv 2&gt;/dev/null
  echo -e "\n\n"
 }
&nbsp;
 if __H perl;
 then
  __T "PERL VARIABLES"
  {
   perl -e&#039;foreach $v (sort(keys(%ENV))) {$vv = $ENV{$v};$vv =~ s|\n|\\n|g;$vv =~ s|"|\\"|g;print "${v}=\"${vv}\"\n"}&#039; | cat -Tsv 2&gt;/dev/null
   echo -e "\n\n"
  }
 fi
&nbsp;
} | fold - -w$(($__WIDTH+3))
exit $?</pre><p><a href="http://www.askapache.com/hosting/enhanced-printenv.html"></a><a href="http://www.askapache.com/hosting/enhanced-printenv.html">Enhanced printenv Script for Server Debugging</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/hosting/enhanced-printenv.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Htaccess Rewrites &#8211; Rewrite Tricks and Tips</title>
		<link>http://www.askapache.com/htaccess/modrewrite-tips-tricks.html</link>
		<comments>http://www.askapache.com/htaccess/modrewrite-tips-tricks.html#comments</comments>
		<pubDate>Sun, 10 Apr 2011 14:05:00 +0000</pubDate>
		<dc:creator>AskApache</dc:creator>
				<category><![CDATA[Htaccess]]></category>

		<guid isPermaLink="false">http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html</guid>
		<description><![CDATA[<p><strong>htaccess rewrite</strong> / Mod_Rewrite Tips and Tricks is as glamorous as it sounds!  htaccess rewrite mod_rewrite is just possibly one of the most useful Apache modules and features.  The ability to rewrite requests internally as well as externally is extremely powerful.</p>
<p><a class="hs hs13" href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html"></a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.askapache.com/htaccess/modrewrite-tips-tricks.html"></a><a href="http://www.askapache.com/htaccess/modrewrite-tips-tricks.html"><cite>AskApache.com</cite></a></p><p><strong>Htaccess Rewrites</strong> are enabled by using the Apache module <a href="http://www.askapache.com/servers/mod_rewrite.c.html">mod_rewrite</a>, which is one of the most powerful Apache modules and features availale.  Htaccess Rewrites through mod_rewrite provide the special ability to <strong>Rewrite requests internally</strong> as well as <em>Redirect request externally</em>.<br class="C" /></p>
<p><a class="hs hs13" href="http://www.askapache.com/servers/mod_rewrite.c.html"></a></p>

<p>When the url in your browser's location bar stays the same for a request it is an internal rewrite, when the url changes an external redirection is taking place.  This is one of the first, and one of the biggest mental-blocks people have when learning about mod_rewrite...  But I have a secret weapon for you to use, a new discovery from years of research that makes learning mod_rewrite drastically quicker and easier.  It truly does or I wouldn't be saying so in the introduction of this article.</p>

<blockquote><p>Despite the tons of examples and docs, <strong>mod_rewrite is voodoo</strong>.
Damned cool voodoo, but still voodoo.<br />-- <cite>Brian Moore</cite></p></blockquote>

<p class="anote"><strong>Note:</strong>  After years of fighting to learn my way through rewriting urls with mod_rewrite, I finally had a breakthrough and found a way to outsmart the difficulty of mod_rewrite that I just couldn't seem to master.  The <a href="http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html">Mod_Rewrite RewriteCond/RewriteRule Variable Value Cheatsheet</a> is the one-of-a-kind tool that changed the game for me and made mod_rewriting no-harder than anything else.</p>

<p>So keep that mod_rewrite reference bookmarked and you will be able to figure out any RewriteRule or RewriteCond, an amazing feat considering it took me a LONG time to figure this stuff out on my own.  But that was before <a href="http://www.askapache.com/htaccess/crazy-advanced-mod_rewrite-tutorial.html">the craziness</a>, one of the most challenging and productive .htaccess experiments I've done... An experiment so <strong>ILL</strong> it's sick like a diamond disease on your wrist! $$$.  That mod_rewrite experiment/tutorial was the culmination of many different advanced mod_rewrite experiments I had done in the past and included most of my very best .htaccess tricks.  With the cheatsheet it's no longer Voodoo.. Its just what you do.  Now lets dig in!</p>


<!--
<h2>Htaccess rewrites TOC</h2>
        <ul>
            <li><a href="#default-mod-rewrite-hint" title=".htaccess mod rewrite should use Options +FollowSymLinks">.htaccess rewrite examples should begin with:</a></li>
            <li><a href="#require-the-www-in-htaccess" title="Use mod_rewrite in Apache htaccess to Require the www for SEO">Require the www</a></li>
            <li><a href="#require-no-www-in-htaccess" title="Use mod_rewrite in Apache htaccess to Require no www for SEO">Require no www</a></li>
            <li><a href="#check-for-key-in-query-string" title="Search for a key in the query string">Check for a key in QUERY_STRING</a></li>
            <li><a href="#delete-query-string" title="Remove the query string from url">Removes the QUERY_STRING from the URL</a></li>
            <li><a href="#fix-infinite-loop-redirects" title="Stop internal redirect looping">Fix for infinite loops</a></li>
            <li><a href="#external-redirect-php-files-to-html" title="Redirecting .php file extensions to .html">Redirect .php files to .html files (SEO friendly)</a></li>
            <li><a href="#internal-redirect-php-files-to-html" title="Redirecting .html file extensions to .php">Redirect .html files to actual .php files (SEO friendly)</a></li>
            <li><a href="#time-based-access" title="Deny access with Apache htaccess during certain hours of the day">block access to files during certain hours of the day</a></li>
            <li><a href="#convert-underscore-hyphen" title="Change underscores to hyphens for SEO URL">Rewrite underscores to hyphens for SEO URL</a></li>
            <li><a href="#require-www-no-hardcoding" title="mod_rewrite example of SEO 301 redirecting non-www to www">Require the www without hardcoding</a></li>
            <li><a href="#require-no-subdomain-1" title="mod_rewrite subdomain usage example of SEO 301 redirecting">Require no subdomain</a></li>
            <li><a href="#require-no-subdomain-2" title="Apache htaccess htaccess rewrite ~without slash">Require no subdomain</a></li>
            <li><a href="#redirect-wordpress-feed" title="Rewriting WordPress RSS feeds to Feedburner in SEO friendly method">Redirecting WordPress Feeds to Feedburner</a></li>
            <li><a href="#only-allow-get-and-put-requests" title="Deny Request Methods other than GET or PUT">Only allow GET and PUT request methods</a></li>
            <li><a href="#prevent-hotlinking" title="hotlinking and bandwidth stealing with mod_rewrite, hotlinking example">Prevent Files image/file hotlinking and bandwidth stealing</a></li>
            <li><a href="#stop-browser-prefetching" title="Fix prefetching in browsers">Stop browser prefetching</a></li>
        </ul>

<hr />
-->
<p>If you really want to take a look, check out the <a href="http://www.askapache.com/servers/mod_rewrite.c.html">mod_rewrite.c</a> and <a href="http://www.askapache.com/servers/mod_rewrite.h.html">mod_rewrite.h</a> files.</p>

<p>Be aware that mod_rewrite (<em>RewriteRule, RewriteBase, and RewriteCond</em>) code is executed for each and every HTTP request that accesses a file in or below the directory where the code resides, so it's always good to limit the code to certain circumstances if readily identifiable.</p>
<p><strong>For example</strong>, to limit the next 5 RewriteRules to only be applied to .html and .php files, you can use the following code, which tests if the url does not end in .html or .php and if it doesn't, it will skip the next 5 RewriteRules.</p><hr />
<pre>
RewriteRule !\.(html|php)$ - [S=5]
RewriteRule ^.*-(vf12|vf13|vf5|vf35|vf1|vf10|vf33|vf8).+$ - [S=1]
</pre>

<h2><a href="#default-mod-rewrite-hint" name="default-mod-rewrite-hint" id="default-mod-rewrite-hint" title="Mostly .htaccess rewrite examples should begin with:" class="acd">.htaccess rewrite examples should begin with:</a></h2>
<pre>
Options +FollowSymLinks
&nbsp;
RewriteEngine On
RewriteBase /
</pre>


<h2><a href="#require-the-www-in-htaccess" name="require-the-www-in-htaccess" id="require-the-www-in-htaccess" title="Require the www" class="acd">Require the www</a></h2>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
RewriteRule ^(.*)$ http://www.askapache.com/$1 [R=301,L]
</pre>


<h2>Loop Stopping Code</h2>
<p>Sometimes your rewrites cause infinite loops, stop it with one of these rewrite code snippets.</p>
<pre>
RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC]
RewriteRule .* - [L]
&nbsp;
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
</pre>

<h2>Cache-Friendly File Names</h2>
<p>This is probably my favorite, and I use it on every site I work on.  It allows me to update my javascript and css files in my visitors cache's simply by naming them differently in the html, on the server they stay the same name.  This rewrites all files for <code>/zap/j/anything-anynumber.js to /zap/j/anything.js and /zap/c/anything-anynumber.css to /zap/c/anything.css</code></p>
<pre>
RewriteRule ^zap/(j|c)/([a-z]+)-([0-9]+)\.(js|css)$ /zap/$1/$2.$4 [L]
</pre>




<h2>SEO friendly link for non-flash browsers</h2>
<p>When you use flash on your site and you properly supply a link to download flash that shows up for non-flash aware browsers, it is nice to use a shortcut to keep your code clean and your external links to a minimum.  This code allows me to link to <code>site.com/getflash/</code> for non-flash aware browsers.</p>
<pre>
RewriteRule ^getflash/?$ http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash [NC,L,R=307]
</pre>

<h2>Removing the Query_String</h2>
<p>On many sites, the page will be displayed for both page.html and page.html?anything=anything, which hurts your SEO with duplicate content.  An easy way to fix this issue is to redirect external requests containing a query string to the same uri without the query_string.</p>
<pre>
RewriteCond %{THE_REQUEST} ^GET\ /.*\;.*\ HTTP/
RewriteCond %{QUERY_STRING} !^$
RewriteRule .* http://www.askapache.com%{REQUEST_URI}? [R=301,L]
</pre>


<h2>Sending requests to a php script</h2>
<p>This .htaccess rewrite example invisibly rewrites requests for all Adobe pdf files to be handled by <code>/cgi-bin/pdf-script.php</code></p>
<pre>
RewriteRule ^(.+)\.pdf$  /cgi-bin/pdf-script.php?file=$1.pdf [L,NC,QSA]
</pre>


<h2>Setting the language variable based on Client</h2>
<p>For sites using multiviews or with multiple language capabilities, it is nice to be able to send the correct language automatically based on the clients preferred language.</p>
<pre>
RewriteCond %{HTTP:Accept-Language} ^.*(de|es|fr|it|ja|ru|en).*$ [NC]
RewriteRule ^(.*)$ - [env=prefer-language:%1]
</pre>



<h2>Deny Access To Everyone Except PHP fopen</h2>
<p>This allows access to all files by php fopen, but denies anyone else.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^.+$ [NC]
RewriteRule .* - [F,L]
</pre>


<p class="cnote">If you are looking for ways to block or deny specific requests/visitors, then you should definately read <a href="http://perishablepress.com/press/2009/02/03/eight-ways-to-blacklist-with-apaches-mod_rewrite/" title="Eight Ways to Blacklist with Apache’s mod_rewrite">Blacklist with mod_rewrite</a>.  I give it a 10/10</p>


<h2>Deny access to anything in a subfolder except php fopen</h2>
<p>This can be very handy if you want to serve media files or special downloads but only through a php proxy script.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+)/.*\ HTTP [NC]
RewriteRule .* - [F,L]
</pre>





<h2><a href="#require-no-www-in-htaccess" name="require-no-www-in-htaccess" id="require-no-www-in-htaccess" title="Require no www" class="acd">Require no www</a></h2>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^askapache\.com$ [NC]
RewriteRule ^(.*)$ http://askapache.com/$1 [R=301,L]
</pre>


<h2><a href="#check-for-key-in-query-string" name="check-for-key-in-query-string" id="check-for-key-in-query-string" title="Search for a key in the query string" class="acd">Check for a key in QUERY_STRING</a></h2>
<p>Uses a <a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritecond" title="RewriteCond Directive Use in htaccess">RewriteCond</a> Directive to check QUERY_STRING for passkey, if it doesn't find it it redirects all requests for anything in the /logged-in/ directory to the /login.php script.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !passkey
RewriteRule ^/logged-in/(.*)$ /login.php [L]
</pre>


<h2><a href="#delete-query-string" name="delete-query-string" id="delete-query-string" title="Remove the query string from url" class="acd">Removes the QUERY_STRING from the URL</a></h2>
<p>If the QUERY_STRING has any value at all besides blank than the<code>?</code>at the end of /login.php? tells mod_rewrite to remove the QUERY_STRING from login.php and redirect.</p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} .
RewriteRule ^login.php /login.php? [L]
</pre>


<h2><a href="#fix-infinite-loop-redirects" name="fix-infinite-loop-redirects" id="fix-infinite-loop-redirects" title="Fix for infinite loops" class="acd">Fix for infinite loops</a></h2>
<p>An error message related to this is<code>Request exceeded the limit of 10 internal redirects due to probable configuration error. Use &#039;LimitInternalRecursion&#039; to increase the limit if necessary. Use &#039;LogLevel debug&#039; to get a backtrace.</code>or you may see<code>Request exceeded the limit</code>,<code>probable configuration error</code>,<code>Use &#039;LogLevel debug&#039; to get a backtrace</code>, or<code>Use &#039;LimitInternalRecursion&#039; to increase the limit if necessary</code></p>
<pre>
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
</pre>


<h2><a href="#external-redirect-php-files-to-html" name="external-redirect-php-files-to-html" id="external-redirect-php-files-to-html" title="External Redirect .php files to .html files (SEO friendly)" class="acd">External Redirect .php files to .html files (SEO friendly)</a></h2>
<pre>
RewriteRule ^(.*)\.php$ /$1.html [R=301,L]
</pre>


<h2><a href="#internal-redirect-php-files-to-html" name="internal-redirect-php-files-to-html" id="internal-redirect-php-files-to-html" title="Internal Redirect .php files to .html files (SEO friendly)" class="acd">Internal Redirect .php files to .html files (SEO friendly)</a></h2>
<p>Redirects all files that end in .html to be served from filename.php  so it looks like all your pages are .html but really they are .php</p>
<pre>
RewriteRule ^(.*)\.html$ $1.php [R=301,L]
</pre>


<h2><a href="#time-based-access" name="time-based-access" id="time-based-access" title="block access to files during certain hours of the day" class="acd">block access to files during certain hours of the day</a></h2>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# If the hour is 16 (4 PM) Then deny all access
RewriteCond %{TIME_HOUR} ^16$
RewriteRule ^.*$ - [F,L]
</pre>


<h2><a href="#convert-underscore-hyphen" name="convert-underscore-hyphen" id="convert-underscore-hyphen" title="Change underscores to hyphens for SEO URL" class="acd">Rewrite underscores to hyphens for SEO URL</a></h2>
<p>Converts all underscores "_" in urls to hyphens "-" for SEO benefits...  See the <a href="http://www.askapache.com/htaccess/rewrite-underscores-to-hyphens-for-seo-url.html">full article</a> for more info.</p>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
&nbsp;
RewriteRule !\.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
&nbsp;
RewriteCond %{ENV:uscor} ^Yes$
RewriteRule (.*) http://d.com/$1 [R=301,L]
</pre>


<h2><a href="#require-www-no-hardcoding" name="require-www-no-hardcoding" id="require-www-no-hardcoding" title="Require the www without hardcoding" class="acd">Require the www without hardcoding</a></h2>
<pre>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.[a-z]{2,6} [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+\.[a-z]{2,6})$     [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
</pre>


<h2><a href="#require-no-subdomain-1" name="require-no-subdomain-1" id="require-no-subdomain-1" title="Require no subdomain" class="acd">Require no subdomain</a></h2>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([a-z-]+\.[a-z]{2,6})$ [NC]
RewriteRule ^/(.*)$ http://%1/$1 [R=301,L]
</pre>


<h2><a href="#require-no-subdomain-2" name="require-no-subdomain-2" id="require-no-subdomain-2" title="Require no subdomain" class="acd">Require no subdomain</a></h2>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} \.([^\.]+\.[^\.0-9]+)$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</pre>


<h2><a href="#redirect-wordpress-feed" name="redirect-wordpress-feed" id="redirect-wordpress-feed" title="Redirecting WordPress Feeds to Feedburner" class="acd">Redirecting WordPress Feeds to Feedburner</a></h2>
<p>Full article:<a href="http://www.askapache.com/htaccess/redirecting-wordpress-feeds-to-feedburner.html" title="Redirecting WordPress Feeds to Feedburner">Redirecting WordPress Feeds to Feedburner</a></p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/feed\.gif$
RewriteRule .* - [L]
&nbsp;
RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator) [NC]
RewriteRule ^feed/?.*$ http://feeds.feedburner.com/apache/htaccess [L,R=302]
&nbsp;
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</pre>


<h2><a href="#only-allow-get-and-put-requests" name="only-allow-get-and-put-requests" id="only-allow-get-and-put-requests" title="Only allow GET and PUT request methods" class="acd">Only allow GET and PUT Request Methods</a></h2>
<p>Article: <a class="acd" href="http://www.askapache.com/htaccess/apache-status-code-headers-errordocument.html#http-methods-recognized" title="List of Apache Recognized Request Methods">Request Methods</a></p>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_METHOD} !^(GET|PUT)
RewriteRule .* - [F]
</pre>


<h2><a href="#prevent-hotlinking" name="prevent-hotlinking" id="prevent-hotlinking" title="Prevent Files image/file hotlinking and bandwidth stealing" class="acd">Prevent Files image/file hotlinking and bandwidth stealing</a></h2>
<pre>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ /feed/ [R=302,L]
</pre>


<h2><a href="#stop-browser-prefetching" name="stop-browser-prefetching" id="stop-browser-prefetching" title="Stop browser prefetching" class="acd">Stop browser prefetching</a></h2>
<pre>
RewriteEngine On
SetEnvIfNoCase X-Forwarded-For .+ proxy=yes
SetEnvIfNoCase X-moz prefetch no_access=yes
&nbsp;
# block pre-fetch requests with X-moz headers
RewriteCond %{ENV:no_access} yes
RewriteRule .* - [F,L]
</pre>



<blockquote cite="http://askapache.info/trunk/mod/mod_rewrite.html#rewritebase">
<p>This module uses a rule-based rewriting engine (based on a regular-expression parser) to rewrite requested URLs on the fly. It supports an unlimited number of rules and an unlimited number of attached rule conditions for each rule, to provide a really flexible and powerful URL manipulation mechanism. The URL manipulations can depend on various tests, of server variables, environment variables, HTTP headers, or time stamps. Even external database lookups in various formats can be used to achieve highly granular URL matching.</p>
<p>This module operates on the full URLs (including the path-info part) both in per-server context (<code>httpd.conf</code>) and per-directory context (<code>.htaccess</code>) and can generate query-string parts on result. The rewritten result can lead to internal sub-processing, external request redirection or even to an internal proxy throughput.</p>
<p>Further details, discussion, and examples, are provided in the <a href="http://askapache.info/trunk/rewrite/index.html">detailed mod_rewrite documentation</a>.</p>
</blockquote>
<h2>Directives</h2>
<ul>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritebase">RewriteBase</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritecond">RewriteCond</a></li>
    <li><a href="http://askapache.info/2.2/mod/mod_rewrite.html#rewriteengine">RewriteEngine</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritelock">RewriteLock</a></li>
    <li><a href="http://askapache.info/2.0/mod/mod_rewrite.html#rewritelog">RewriteLog</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewriteloglevel">RewriteLogLevel</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewritemap">RewriteMap</a></li>
    <li><a href="http://askapache.info/1.3/mod/mod_rewrite.html#rewriteoptions">RewriteOptions</a></li>
    <li><a href="http://askapache.info/trunk/mod/mod_rewrite.html#rewriterule">RewriteRule</a></li>
</ul>



<p>If you aren't already comfortable using mod_rewrite then I recommend this <a href="http://check-these.info/mod_rewrite-basic.html">excellent mod_rewrite guide</a> by one of my favorite mod_rewrite gurus that I've met.</p>



<hr />
<h2>htaccess Guide Sections</h2>
<ul class="ou">
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/htaccess-for-webmasters.html" title="Apache HTTP Web Server htaccess tips and tricks">htaccess tricks for Webmasters</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html" title="Creating and using HTTP Headers with htaccess">HTTP Header control with htaccess</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/php-htaccess-tips-and-tricks.html" title="mod_php or php as a cgi with htaccess tips, htaccess php tricks">PHP on Apache tips and tricks</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html" title="SEO-Friendly 301 Redirects without mod_rewrite">SEO Redirects without mod_rewrite</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html" title="mod_rewrite tips and tricks with RewriteEngine, RewriteBase, RewriteRule, and RewriteCond">mod_rewrite examples, tips, and tricks</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html" title="Caching, cache-control, cache, expires, and optimizing htaccess">HTTP Caching and Site Speedups</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html" title="htaccess and Apache authentication with htpasswd, 401, and 403">Authentication on Apache</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/security-with-htaccess.html" title="Security, hacking, and anti-hacking tips and tricks for htaccess">htaccess Security Tricks and Tips</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html" title="Apache SSL examples">SSL tips and examples</a></li>
    <li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/apache-variable-fun-in-htaccess.html" title="Apache variables info, tricks, and tips">Variable Fun (mod_env) Section</a></li><li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/mod_security-htaccess-tricks.html" title="mod_security Guide and sample mod_Security diretive usage in .htaccess">.htaccess Security with MOD_SECURITY</a></li><li><a rel="chapter bookmark" href="http://www.askapache.com/htaccess/setenvif.html" title="SetEnvIf and SetEnvIfNoCase Examples for conditionally setting variables in Apache .htaccess">SetEnvIf and SetEnvIfNoCase Examples</a></li>
</ul>


<p class="ment"><a rel="prev" href="http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html" title="Use htaccess to create SEO-Friendly 301 Redirects without mod_rewrite">&laquo;  Search Engine Friendly Redirects</a> | <a href="http://www.askapache.com/htaccess/htaccess.html" class="acd1" rel="Contents Index Start" title=".htaccess tutorial">.htaccess Tutorial Index</a> | <a rel="next" href="http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html" title="The Apache method for speeding up sites with Caching, cache-control, cache, expires, and optimizing htaccess">&raquo;  Speed up your site with Caching and cache-control</a></p><p><a href="http://www.askapache.com/htaccess/modrewrite-tips-tricks.html"></a><a href="http://www.askapache.com/htaccess/modrewrite-tips-tricks.html">Htaccess Rewrites &#8211; Rewrite Tricks and Tips</a> originally appeared on <cite>AskApache.com</cite> </p>]]></content:encoded>
			<wfw:commentRss>http://www.askapache.com/htaccess/modrewrite-tips-tricks.html/feed</wfw:commentRss>
		<slash:comments>130</slash:comments>
		</item>
	</channel>
</rss>

