<?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/"
	xmlns:creativeCommons="http://backend.userland.com/creativeCommonsRssModule"
>
<channel>
	<title>G-Loaded Journal &#187; Web Applications</title>
	<atom:link href="http://www.g-loaded.eu/tag/web-applications/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.g-loaded.eu</link>
	<description>An open-source software and technology related journal</description>
	<lastBuildDate>Mon, 05 Dec 2011 19:55:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
		<item>
		<title>Issues with the feeds are now resolved</title>
		<link>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/</link>
		<comments>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 06:06:46 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Errors]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Snippet]]></category>
		<category><![CDATA[System]]></category>
		<category><![CDATA[Web Applications]]></category>
		<category><![CDATA[Wordpress]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=1634</guid>
		<description><![CDATA[This is just a quick notice that during the last five days there was a problem with the website feeds. The web server returned a 500 Internal Server Error to almost all requests for /feed/ URLs. Also, there was a big increase of the server&#8217;s CPU load behind the scenes, which was caused by php-cgi [...]]]></description>
			<content:encoded><![CDATA[<p>This is just a quick notice that during the last five days there was a problem with the website feeds. The web server returned a <em>500 Internal Server Error</em> to almost all requests for <code>/feed/</code> URLs. Also, there was a big increase of the server&#8217;s <strong>CPU load</strong> behind the scenes, which was caused by <em>php-cgi</em> processes. It turned out that a custom plugin (unpublished) I had written for WordPress in the past was the cause of all the trouble, but, before coming to that conclusion, the fact that the problems had started without me doing anything on the blog during the last weeks together with a series of other random observations led me do a thorough examination of the whole server just in case.<br />
<span id="more-1634"></span><br />
So, after spending two days in front of a Linux terminal, I came to the conclusion that the following code had been problematic from the beginning and it was like a time-bomb for which the time had come to cause issues to the web site and the server that hosted it.</p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> rsse_add_related_posts<span style="color: #009900;">&#40;</span><span style="color: #000088;">$PostBody</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>rsse_verify_feed<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #b1b100;">return</span> <span style="color: #000088;">$PostBody</span><span style="color: #339933;">;</span> <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'yarpp_related'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$PostBody</span> <span style="color: #339933;">.=</span> yarpp_related<span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'post'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'rss'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
  <span style="color: #b1b100;">return</span> <span style="color: #000088;">$PostBody</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
add_filter<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'the_content'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'rsse_add_related_posts'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">252</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>
<p>This code used a function of another plugin to attach a &#8216;<em>related posts</em>&#8216; section at the end of the full content of each feed entry. As soon as I commented out the above filter and started attaching the related-posts section to the feed content through the <a href="http://mitcho.com/code/yarpp/">YARPP</a> plugin&#8217;s administration interface, everything was normal again. No more php-cgi processes timing-out or over-consuming the CPU cycles.</p>
<p>The following graph shows clearly the problematic period:</p>
<div id="attachment_1639" class="wp-caption aligncenter" style="width: 650px"><a href="http://www.g-loaded.eu/wp-content/uploads/phpcgi-cpu-time.png"><img src="http://www.g-loaded.eu/wp-content/uploads/phpcgi-cpu-time.png" alt="php-cgi processes consuming the CPU" title="phpcgi-cpu-time" width="640" class="size-full wp-image-1639" /></a><p class="wp-caption-text">php-cgi processes consuming the CPU</p></div>
<p>The httpd error_log included many errors like the following:</p>
<pre class="codesnp">
[...]
Allowed memory size of 33554432 bytes exhausted (tried to allocate 18893 bytes)
[...]
mod_fcgid: process ... exit(communication error), terminated by calling exit(), return code: 1
[...]
[warn] (104)Connection reset by peer: mod_fcgid: read data from fastcgi server error.
[...]
[warn] mod_fcgid: stderr: PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 4864 bytes)
[...]
Premature end of script headers: index.php
[...]
</pre>
<p>Note that these errors might appear in several occasions.</p>
<p>In my case, finding that faulty piece of code was a huge relief, I can tell you.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/">Issues with the feeds are now resolved</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2007/01/12/wordpress-206-feed-issues-resolved/" rel="bookmark">WordPress 2.0.6 &#8211; Feed Issues Resolved</a></li>
<li><a href="http://www.g-loaded.eu/2009/11/19/g-loaded-feeds/" rel="bookmark">G-Loaded Feeds</a></li>
<li><a href="http://www.g-loaded.eu/2009/10/08/redmine-deployment-delayed/" rel="bookmark">Redmine deployment delayed</a></li>
<li><a href="http://www.g-loaded.eu/2007/07/12/issue-addressed-author-feeds-deliver-full-content/" rel="bookmark">Issue addressed: Author feeds deliver full content</a></li>
<li><a href="http://www.g-loaded.eu/2008/10/17/status-of-content-availability-via-feeds/" rel="bookmark">Status of content availability via feeds</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
		<item>
		<title>Making a directory writable by the webserver</title>
		<link>http://www.g-loaded.eu/2008/12/09/making-a-directory-writable-by-the-webserver/</link>
		<comments>http://www.g-loaded.eu/2008/12/09/making-a-directory-writable-by-the-webserver/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 13:21:02 +0000</pubDate>
		<dc:creator>George Notaras</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Administration]]></category>
		<category><![CDATA[Filesystem]]></category>
		<category><![CDATA[Servers]]></category>
		<category><![CDATA[Web Applications]]></category>
		<guid isPermaLink="false">http://www.g-loaded.eu/?p=751</guid>
		<description><![CDATA[I&#8217;ve used the phrase &#8220;writable by the webserver&#8221; numerous times throughout this blog, without ever bothering to explain in detail what this means. Yesterday, I received an email asking me exactly that, so I decided to finally write a post about it and use it as a reference whenever I use the aforementioned phrase. I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve used the phrase &#8220;<em>writable by the webserver</em>&#8221; numerous times throughout this blog, without ever bothering to explain in detail what this means. Yesterday, I received an email asking me exactly that, so I decided to finally write a post about it and use it as a reference whenever I use the aforementioned phrase. I&#8217;ll use <a href="http://httpd.apache.org/">Apache</a> as an example webserver and a filesystem with <a href="http://assela.pathirana.net/UNIX_file_system_permissions_tutorial">Unix-like permissions</a>. I&#8217;ll also try to keep the article as short as possible.<br />
<span id="more-751"></span><br />
First of all, the webserver, Apache in our case, is a program running in the <em>background</em>. Apache is originally started by user <strong>root</strong>. We will call this initial process the &#8220;<strong>root-process</strong>&#8220;. The &#8220;root-process&#8221; launches several <strong>child processes</strong> which handle the client requests. For security reasons, <em>the child processes are not run by user &#8220;root&#8221;</em> but as a user with minimal privileges. Usually this user is named <code>apache</code> or <code>www-data</code> etc. To find out how this is called in your system, issue the following command:</p>
<pre class="console">
$ ps -ef | grep httpd | grep -v grep
root      1926     1  0 Dec03 ?        00:00:55 /usr/sbin/httpd.worker
apache    2608  1926  0 14:31 ?        00:00:06 /usr/sbin/httpd.worker
apache   22192  1926  0 01:05 ?        00:00:02 /usr/sbin/httpd.worker
</pre>
<p>So, in my case the child processes are run by user &#8220;<code>apache</code>&#8220;. This could also be determined by the user and group directives inside Apache&#8217;s configuration file, <code>/etc/httpd/conf/httpd.conf</code>:</p>
<pre class="codesnp">
User apache
Group apache
</pre>
<p>So, in order to <strong>make a directory writable by the webserver</strong> we have to set the directory&#8217;s owner or group to Apache&#8217;s owner or group and enable the write permission for it. Usually, we set the directory to belong to the Apache group (<code>apache</code> or <code>www-data</code> or whatever user is used to launch the child processes) and enable the write permission for the group.</p>
<pre class="console">
chgrp apache /path/to/mydir
chmod g+w /path/to/mydir
</pre>
<p>In many cases, usually in <em>shared hosting environments</em>, it is not possible to change the ownership of files and directories. In those cases you could just set the write permission for everyone (others):</p>
<pre class="console">
chmod o+w /path/to/mydir
</pre>
<p>Which method is more <strong>secure</strong> depends on how <code>/path/to/mydir</code> is accessed.</p>
<p>If it is accessed through the web server with an HTTP request it does not really matter which of the above methods has been used in order to make <code>/path/to/mydir</code> writable by the web server, because, in any case, the web server will be able to write to <code>/path/to/mydir</code>.</p>
<p>If the directory is accessed by other means, for instance by another local program which is run by an untrusted local user, then, obviously, the first method is more secure.</p>
<p>I guess this explains how to make a directory or file writable by the web server process.</p>
<div class="cc-block"><em><a href="http://www.g-loaded.eu/2008/12/09/making-a-directory-writable-by-the-webserver/">Making a directory writable by the webserver</a></em>, unless otherwise expressly stated, is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License</a>. Terms and conditions beyond the scope of this license may be available at <a href="http://www.g-loaded.eu/about/disclaimer-and-license/">www.g-loaded.eu</a>.</div>
<h4>Related Articles</h4>
<ul><li><a href="http://www.g-loaded.eu/2009/10/08/redmine-deployment-delayed/" rel="bookmark">Redmine deployment delayed</a></li>
<li><a href="http://www.g-loaded.eu/2007/02/21/htaccess-cheat-sheet/" rel="bookmark">.htaccess Cheat Sheet</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/issues-with-the-feeds-are-now-resolved/" rel="bookmark">Issues with the feeds are now resolved</a></li>
<li><a href="http://www.g-loaded.eu/2007/08/06/file-and-directory-diff-in-color-in-midnight-commander/" rel="bookmark">File and Directory diff in color in Midnight Commander</a></li>
<li><a href="http://www.g-loaded.eu/2010/03/28/script-apache-error-report/" rel="bookmark">Script for Apache Error Report</a></li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.g-loaded.eu/2008/12/09/making-a-directory-writable-by-the-webserver/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	<creativeCommons:license>http://creativecommons.org/licenses/by-nc-sa/3.0/</creativeCommons:license>
	</item>
	</channel>
</rss>

