<?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>R. Kris Hardy &#187; apache</title>
	<atom:link href="http://www.rkrishardy.com/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.rkrishardy.com</link>
	<description>Software Development, Web Applications and Business Analytics</description>
	<lastBuildDate>Tue, 19 Jul 2011 17:58:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Subversion Fix: svn copy causes &#8220;Repository moved permanently to &#8216;&#8230;&#8217;; please relocate</title>
		<link>http://www.rkrishardy.com/2009/12/subversion-fix-svn-copy-causes-repository-moved-permanentl/</link>
		<comments>http://www.rkrishardy.com/2009/12/subversion-fix-svn-copy-causes-repository-moved-permanentl/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 17:54:52 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Articles]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[repository moved permanently]]></category>
		<category><![CDATA[subversion]]></category>
		<category><![CDATA[svn copy]]></category>

		<guid isPermaLink="false">http://www.rkrishardy.com/?p=220</guid>
		<description><![CDATA[Background Subversion is a version control system. It can run as either it&#8217;s own server (svnserve), or as an Apache module (mod_dav_svn.so). When using the mod_dav_svn module for Apache, and doing an svn copy operation on the repository itself can fail if the VirtualHost configuration for subversion is not correct. Put simply, if Apache itself [...]]]></description>
			<content:encoded><![CDATA[<h1>Background</h1>
<p><a href="http://subversion.tigris.org/">Subversion</a> is a version control system.  It can run as either it&#8217;s own server (svnserve), or as an Apache module (mod_dav_svn.so).</p>
<p>When using the mod_dav_svn module for Apache, and doing an svn copy operation on the repository itself can fail if the VirtualHost configuration for subversion is not correct.  Put simply, if Apache itself and mod_dav_svn are serving content from the same path, then conflicts can occur.  Apache can get confused if it attempts to serve a physical file instead of routing the request through mod_dav_svn.</p>
<p>&#8220;svn copy &#8230;&#8221; operations will fail, while &#8220;svn update &#8230;&#8221;, &#8220;svn commit &#8230;&#8221;, and &#8220;svn checkout &#8230;&#8221; operations work fine.</p>
<p>Detail of the problem, diagnosing the problem, and the fix are below.</p>
<p><span id="more-220"></span></p>
<h1>Problem</h1>
<p>Repository checkouts (svn co &#8230;) and commits (svn ci &#8230;) work fine and throw no errors, but svn trunk copying operations fail &#8220;svn copy &#8230;/trunk &#8230;/tags/x.x&#8221; with &#8220;svn: Repository moved permanently to &#8216;&#8230;&#8217;; please relocate&#8221;.</p>
<p><code><br />
$ svn co https://svn.test.com/myproject/trunk myproject<br />
... (checkout progress)<br />
Checked out revision [x].<br />
$ svn ci myproject<br />
Committed revision [x].<br />
$ svn cp https://svn.test.com/myproject/trunk https://svn.test.com/myproject/tags/x.x<br />
svn: Repository moved permanently to 'https://svn.test.com/myproject/'; please relocate<br />
</code></p>
<h1>Diagnostics</h1>
<p>To diagnose the problem, first make sure the local checkout urls are correct.</p>
<p><code><br />
$ svn info myproject<br />
...<br />
URL: https://svn.test.com/myproject/trunk<br />
Repository Root: https://svn.test.com/myproject<br />
</code></p>
<p>The Repository Root should match the root url of the project repository that you are working with because the svn commit above worked.  However, if they don&#8217;t match, then use svn switch to move the url that your local checkout is linked to:</p>
<p><code><br />
$ svn switch --relocate [OLD URL] [NEW URL] myproject<br />
$ svn cp https://svn.test.com/myproject/trunk https://svn.test.com/myproject/tags/x.x<br />
</code></p>
<p>If relocating the base url of the checkout (svn switch &#8211;relocate &#8230;) does not fix the problem, but checkouts and commits work fine, the next step is to look at the virtual host configuration in Apache for the subversion module.  This is where I found my problem.</p>
<h1>The Cause</h1>
<p>The file path of the subversion repository was within public_html, so it had a physical path that was identitical to it&#8217;s url path.</p>
<p><code><br />
$ ls public_html<br />
repos<br />
$ cat /etc/httpd/conf.d/subversion.conf<br />
&lt;VirtualHost 127.0.0.1:443&gt; #YOUR IP ADDRESS:PORT<br />
DocumentRoot /home/svn/public_html #YOUR WEBROOT PATH<br />
...<br />
&lt;Location /repos&gt;<br />
DAV svn<br />
SVNParentPath /home/svn/public_html/repos #YOUR REPOSITORY PATH<br />
...<br />
&lt;/Location&gt;<br />
&lt;/VirtualHost&gt;<br />
</code></p>
<p>The problem is that the Location is an actual physical filepath, not an alias.  So, Apache isn&#8217;t sure whether to attempt to serve the physical file itself, or to pass the request through to mod_dav_svn.  Most of the time mod_dav_svn wins and Apache forward the request through.  However, &#8220;svn copy&#8221; must work slighly differently, and Apache attempts to serve the request itself, rather than pass it through mod_dav_svn.  The request then fails and svn errors out with the &#8220;svn: Repository moved permanently to &#8216;&#8230;&#8217;; please relocate&#8221; message.</p>
<p>A reader of this blog also pointed out that this can also happen if you have an overlap between a URL path alias and the repos folder itself:</p>
<p><code><br />
#Alias /repos    “/srv/svn/repos” #Commenting this line out fixed the problem<br />
</code></p>
<h1>Fix</h1>
<p>The fix is to 1) change the Apache configuration, and 2) change the physical path to the repository so that it does not match the url.  This way, Apache will never attempt to serve a physical file itself, and will instead forward the requests to mod_dav_svn.</p>
<h2>Edit /etc/httpd/conf.d/subversion.conf</h2>
<p><code><br />
&lt;VirtualHost svn.test.com:443&gt;<br />
DocumentRoot /home/svn/public_html<br />
...<br />
&lt;Location /repos&gt;<br />
DAV svn<br />
SVNParentPath /home/svn/repos #NOTE THAT repos IS NOW OUT OF THE PHYSICAL WEBROOT PATH<br />
...<br />
</code></p>
<h2>Move the repository directory out of the physical webroot path and restart Apache.</h2>
<p><code><br />
[svn /home/svn]$ mv public_html/repos .<br />
[svn /home/svn]$ sudo service httpd restart<br />
</code></p>
<p>All your &#8220;svn copy&#8221; operations should work now.</p>
<div class="diggthis_container">
<script type="text/javascript">
digg_url = 'http://www.rkrishardy.com/2009/12/subversion-fix-svn-copy-causes-repository-moved-permanentl/';
digg_title = 'Subversion Fix: svn copy causes &quot;Repository moved permanently to \'...\'; please relocate';
digg_bodytext = '&lt;h1&gt;Background&lt;/h1&gt;\n&lt;a href=&quot;http://subversion.tigris.org/&quot;&gt;Subversion&lt;/a&gt; is a version control system.  It can run as either it\'s own server (svnserve), or as an Apache module (mod_dav_svn.so).\n\nW...';
digg_skin = 'compact';
digg_window = 'new';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div> 
<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/apache' rel='tag' target='_self'>apache</a>, <a class='technorati-link' href='http://technorati.com/tag/repository+moved+permanently' rel='tag' target='_self'>repository moved permanently</a>, <a class='technorati-link' href='http://technorati.com/tag/subversion' rel='tag' target='_self'>subversion</a>, <a class='technorati-link' href='http://technorati.com/tag/svn+copy' rel='tag' target='_self'>svn copy</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.rkrishardy.com/2009/12/subversion-fix-svn-copy-causes-repository-moved-permanentl/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Permission Denied (13) When Opening Socket in PHP &amp; Apache</title>
		<link>http://www.rkrishardy.com/2009/12/permission-denied-13-when-opening-socket-in-php-apache/</link>
		<comments>http://www.rkrishardy.com/2009/12/permission-denied-13-when-opening-socket-in-php-apache/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 14:56:53 +0000</pubDate>
		<dc:creator>Kris</dc:creator>
				<category><![CDATA[Debugging]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[permission denied]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[selinux]]></category>
		<category><![CDATA[stream_socket_client]]></category>
		<category><![CDATA[zend framework]]></category>
		<category><![CDATA[zend_mail]]></category>

		<guid isPermaLink="false">http://www.rkrishardy.com/?p=212</guid>
		<description><![CDATA[This post covers two cases that I&#8217;ve run into that cause Permission Denied (13) errors when opening sockets in PHP. Situation #1:  SELinux denies httpd from opening socket I ran into this simple, but annoying, problem after I migrated my development workstation to Fedora 12. Problem: A large PHP application that I have developed at [...]]]></description>
			<content:encoded><![CDATA[<p>This post covers two cases that I&#8217;ve run into that cause Permission Denied (13) errors when opening sockets in PHP.</p>
<h1>Situation #1:  SELinux denies httpd from opening socket</h1>
<p>I ran into this simple, but annoying, problem after I migrated my development workstation to Fedora 12.</p>
<h2>Problem:</h2>
<p>A large PHP application that I have developed at <a href="http://www.submergedsolutions.com">Submerged Solutions</a> (<a href="http://www.submergedsolutions.com">SandPiper Accounting</a>) began throwing <strong>Permission Denied (13)</strong> system exceptions when attempting to send mail through<a href="http://www.zend.com"> Zend Framework&#8217;s</a> Zend_Mail library.</p>
<p>All the phpunit unit tests worked fine and could send e-mail, but would fail when the usability tests started and any HTTP requests that sent e-mail were handled through Apache.</p>
<p>The Apache instance was being run as user apache / group apache, and php (mod_php) is run as user apache / group apache.</p>
<p>The exception occurred in Zend_Mail_Protocol_Abstract-&gt;_connect(), immediately following the socket opening call &#8220;stream_socket_client(&#8230;)&#8221;.</p>
<h3>File: Zend/Mail/Protocol/Abstract.php; Line 224</h3>
<p><code> 50:    abstract class Zend_Mail_Protocol_Abstract<br />
51:    {<br />
...<br />
218:       protected function _connect($remote)<br />
219:       {<br />
220:           $errorNum = 0;<br />
221:           $errorStr = '';<br />
222:<br />
223:           // open connection<br />
224:           $this-&gt;_socket = @<strong>stream_socket_client</strong>($remote, $errorNum, $errorStr, self::TIMEOUT_CONNECTION);<br />
225:           ...<br />
</code></p>
<p>fopen() calls using http and ftp protocols also failed:</p>
<p style="padding-left: 30px;"><em>Warning</em>: fopen(&#8230;) [function.fopen]: failed to open stream: Permission denied in &#8230;</p>
<h2>The fix:</h2>
<p>The problem turned out to be the &#8220;<strong>httpd_can_network_connect</strong>&#8221; SELinux setting that is on by default in Fedora 12.</p>
<p>In a shell console, run as <strong>root</strong>:</p>
<p><code># /usr/sbin/setsebool httpd_can_network_connect=1<br />
</code></p>
<p><a href="http://www.php.net/manual/en/function.fopen.php#56551">Thanks to durwood, who pointed this out on PHP.net.</a></p>
<p><a href="http://bugzilla.redhat.com/show_bug.cgi?id=164700">&#8220;Bug&#8221; Report at RedHat.com.</a></p>
<p><a href="http://fedoraproject.org/wiki/SELinux">More info on SELinux.</a></p>
<h1>Situation #2: PHP forbids opening socket to 255.255.255.255</h1>
<p>A reader of this blog brought a problem of his to me.  I had never seen it before, so it was definitely interesting.</p>
<h2>Problem:</h2>
<p>This reader was using <a href="http://www.phpcs.com/codes/WAKE-ON-LAN-WAN-REVEILLER-MACHINE-SUR-INTERNET_48248.aspx">this PHP script</a> that he had found to do <a title="Wake-on-LAN" href="http://en.wikipedia.org/wiki/Wake-on-LAN">Wake-on-LAN</a> pings on his local network.  The script worked fine in Windows, but failed on his Fedora 10 server.  The error he received was Permission Denied (13).</p>
<p>His WoL packets were sent via udp to the broadcast address 255.255.255.255.  This worked fine in Windows, but failed in Linux.</p>
<p>His server&#8217;s PHP installation had socket support enabled, and udp was a registered stream socket transport.</p>
<p>His SELinux was disabled, so Situation #1 did not apply to him.</p>
<p>This is probably distribution specific.  I&#8217;m running Fedora 12, and had no such issues, whereas the person facing this problem was running Fedora 10.</p>
<h2>Solution:</h2>
<p>Either PHP or the the user running the PHP instance (&#8220;apache&#8221; in this case), was being forbidden from opening sockets to 255.255.255.255.  It turns out this is somewhat common.  Even when running the script as &#8220;root&#8221;, you can still get permission denied errors.</p>
<p>I came upon this short comment on php.net about someone else getting <a href="http://www.php.net/manual/en/ref.sockets.php#80397">permission denied errors on socket_connect() calls.</a></p>
<p>There was also this comment which showed an <a href="http://www.php.net/manual/en/ref.sockets.php#73162">easy way to get the broadcast address for the computer&#8217;s network interface.</a> This method seems to work, however, it is limited to Linux since it relies upon the following gnu utilities: <a href="http://en.wikipedia.org/wiki/Ifconfig">ifconfig</a>, <a href="http://en.wikipedia.org/wiki/Grep">grep</a> and <a href="http://en.wikipedia.org/wiki/Cut_%28Unix%29">cut</a>.  It may work if you compile Windows ports to these utilities, or use <a href="http://www.cygwin.com/">cygwin</a>.  (Note: The code snippet at PHP.net has errors.  A revised script is pasted below.)</p>
<p>Here&#8217;s the way to get the broadcast address:</p>
<pre>exec("ifconfig | grep Bcast | cut -d \":\" -f 3 | cut -d \" \" -f 1",$addr);
$addr=array_flip(array_flip($addr));
</pre>
<p>By getting the broadcast address of the network interface, you can send Wake-on-LAN magic packets to that address rather than to 255.255.255.255.  Doing this, the sockets can be connected successfully, and the permission denied errors were resolved.</p>
<p>Here&#8217;s the &#8220;fixed&#8221; code from PHP.net.  It hasn&#8217;t been tested, so you very well may need to modify it for your needs.</p>
<pre>
&lt;?php
/**
 * Wake-on-LAN
 *
 * @return boolean
 *   TRUE:    Socked was created successfully and the message has been sent.
 *   FALSE:   Something went wrong
 *
 * @param string|array  $mac   You will WAKE-UP this WOL-enabled computer, you
 *                             need to add the MAC-address here. Mac can be
 *                             array too.
 *
 * @param string|array  $addr  You will send and broadcast to this address.
 *                             Normally you need to use the 255.255.255.255
 *                             address, so I made it as the default. You don't need to do anything with this.
 *
 *                             If you get permission denied errors when using
 *                             255.255.255.255 have permission denied problems
 *                             you can set $addr = false to get the broadcast
 *                             address from the network interface using the
 *                             ifconfig command.
 *
 *                             $addr can be array with broadcast IP values
 *
 * Example 1:
 *   When the message has been sent you will see the message "Done...."
 *   if ( wake_on_lan('00:00:00:00:00:00'))
 *      echo 'Done...';
 *   else
 *      echo 'Error while sending';
 */

function wake_on_lan($mac, $addr=false, $port=7) {
    if ($addr === false){
        exec("ifconfig | grep Bcast | cut -d \":\" -f 3 | cut -d \" \" -f 1",$addr);
        $addr=array_flip(array_flip($addr));
    }
    if(is_array($addr)){
        $last_ret = false;
        for ($i = 0; $i < count($addr); $i++)
            if ($addr[$i] !== false) {
                $last_ret = wake_on_lan($mac, $addr[$i], $port);
            }
        return $last_ret;
    }
    if (is_array($mac)){
        $ret = array();
        foreach($mac as $k =&lt; $v)
            $ret[$k] = wake_on_lan($v, $addr, $port);
        return $ret;
    }
    //Check if it's an real MAC-address and split it into an array
    $mac = strtoupper($mac);
    if (!preg_match("/([A-F0-9]{1,2}[-:]){5}[A-F0-9]{1,2}/", $mac, $maccheck))
        return false;
    $addr_byte = preg_split("/[-:]/", $maccheck[0]);

    //Creating hardware adress
    $hw_addr = '';
    for ($a = 0; $a < 6; $a++)//Changing mac adres from HEXEDECIMAL to DECIMAL
        $hw_addr .= chr(hexdec($addr_byte[$a]));

    //Create package data
    $msg = str_repeat(chr(255),6);
    for ($a = 1; $a <= 16; $a++)
        $msg .= $hw_addr;
    //Sending data
    if (function_exists('socket_create')){
        //socket_create exists
        $sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);    //Can create the socket
        if ($sock){
            $sock_data = socket_set_option($sock, SOL_SOCKET, SO_BROADCAST, 1); //Set
            if ($sock_data){
                $sock_data = socket_sendto($sock, $msg, strlen($msg), 0, $addr,$port); //Send data
                if ($sock_data){
                    socket_close($sock); //Close socket
                    unset($sock);
                    return true;
                }
            }
        }
        @socket_close($sock);
        unset($sock);
    }
    $sock=fsockopen("udp://" . $addr, $port);
    if($sock){
        $ret=fwrite($sock,$msg);
        fclose($sock);
    }
    if($ret)
        return true;
    return false;
}

if (@wake_on_lan('00:00:00:00:00:00')) {
    echo 'Done...';
} else {
    echo 'Error while sending';
}
?&gt;
</pre>
<div class="diggthis_container">
<script type="text/javascript">
digg_url = 'http://www.rkrishardy.com/2009/12/permission-denied-13-when-opening-socket-in-php-apache/';
digg_title = 'Permission Denied (13) When Opening Socket in PHP &amp; Apache';
digg_bodytext = 'This post covers two cases that I\'ve run into that cause Permission Denied (13) errors when opening sockets in PHP.\n&lt;h1&gt;Situation #1:  SELinux denies httpd from opening socket&lt;/h1&gt;\nI ran into this ...';
digg_skin = 'compact';
digg_window = 'new';
</script>
<script src="http://digg.com/tools/diggthis.js" type="text/javascript"></script>
</div> 
<!-- start wp-tags-to-technorati 1.02 -->

<p class='technorati-tags'>Technorati Tags: <a class='technorati-link' href='http://technorati.com/tag/apache' rel='tag' target='_self'>apache</a>, <a class='technorati-link' href='http://technorati.com/tag/Debugging' rel='tag' target='_self'>Debugging</a>, <a class='technorati-link' href='http://technorati.com/tag/permission+denied' rel='tag' target='_self'>permission denied</a>, <a class='technorati-link' href='http://technorati.com/tag/php' rel='tag' target='_self'>php</a>, <a class='technorati-link' href='http://technorati.com/tag/selinux' rel='tag' target='_self'>selinux</a>, <a class='technorati-link' href='http://technorati.com/tag/stream_socket_client' rel='tag' target='_self'>stream_socket_client</a>, <a class='technorati-link' href='http://technorati.com/tag/zend+framework' rel='tag' target='_self'>zend framework</a>, <a class='technorati-link' href='http://technorati.com/tag/zend_mail' rel='tag' target='_self'>zend_mail</a></p>

<!-- end wp-tags-to-technorati -->
]]></content:encoded>
			<wfw:commentRss>http://www.rkrishardy.com/2009/12/permission-denied-13-when-opening-socket-in-php-apache/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

