<?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>tech stuff &#187; apache</title>
	<atom:link href="http://codytaylor.org/tag/apache/feed" rel="self" type="application/rss+xml" />
	<link>http://codytaylor.org</link>
	<description>From Cody Taylor.</description>
	<lastBuildDate>Sun, 30 Oct 2011 04:15:41 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Django Quick Install With WSGI</title>
		<link>http://codytaylor.org/2009/05/django-quick-install-with-wsgi.html</link>
		<comments>http://codytaylor.org/2009/05/django-quick-install-with-wsgi.html#comments</comments>
		<pubDate>Sat, 30 May 2009 20:15:53 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[framework]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wsgi]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=14059</guid>
		<description><![CDATA[Django is a high level python web framework that I've been hearing a lot about lately..]]></description>
			<content:encoded><![CDATA[<p>Django is a high level python web framework that I&#8217;ve been hearing a lot about lately. I decided to try it out this weekend.<br />
It took a little reading to get up and running so I documented the steps I took so others can get up and running a little more quickly.</p>
<p><span style="color: #888888;">sudo apt-get install django<br />
django-admin &#8211;version </span></p>
<p>Create the appropriate directories and start the django project.</p>
<p>For no real reason I decided to put my new projects in /var/django.<br />
<span style="color: #888888;">sudo mkdir /var/django<br />
sudo chmod 755 /var/django<br />
cd /var/django<br />
django-admin startproject mysite<br />
cd mysite<br />
mkdir apache</span></p>
<p>It seems that mod-wsgi is the best way to serve up python web apps due to mod_python being a little outdated. Note that django does come with a built in webserver that is really easy to get going. So if you&#8217;re just planning on evaluating the framework and not actually do any production aplications then that would be the way to go. mod_wsgi is an Apache module which can be used to host Python applications.</p>
<p>Install the module:<br />
<span style="color: #888888;">sudo apt-get install libapache2-mod-wsgi</span></p>
<p>Now for the configuration. It took me a few tries to get this right.<br />
For now I just put my django site on port 8080 so I can play around without it being public to anyone else.</p>
<p>In the /var/django/mysite/apache directory I created a file called django.wsgi and put this in it:</p>
<p><span style="color: #888888;">import os, sys<br />
apache_configuration= os.path.dirname(__file__)<br />
project = os.path.dirname(apache_configuration)<br />
sys.path.append(&#8217;/var/django&#8217;)<br />
os.environ['DJANGO_SETTINGS_MODULE'] = &#8216;mysite.settings&#8217;<br />
import django.core.handlers.wsgi<br />
application = django.core.handlers.wsgi.WSGIHandler()</span></p>
<p>Make sure that the sys.path.append line contains the directory above the project directory. This one took me awhile to figure out.<br />
I was getting this error until I got it right.<br />
<span style="color: #ff0000;"><br />
[Sat May 30 15:33:24 2009] [error] [client 127.0.0.1]     raise ImportError, &#8220;Could not import settings &#8216;%s&#8217; (Is it on sys.path? Does it have syntax errors?): %s&#8221; % (self.SETTINGS_MODULE, e)<br />
[Sat May 30 15:33:24 2009] [error] [client 127.0.0.1] ImportError: Could not import settings &#8216;mysite.settings&#8217; (Is it on sys.path? Does it have syntax errors?): No module named mysite.settings</span></p>
<p>Next I added a new virtual host in my sites-enabled folder like this:</p>
<p><span style="color: #808080;">&lt;VirtualHost *:808http://localhost:8080/0&gt;<br />
ServerAdmin root@mysite.com<br />
ServerName mysite.com<br />
ServerAlias mysite.com<br />
&lt;Directory /var/django/mysite/apache&gt;<br />
Allow from all<br />
&lt;/Directory&gt;</span></p>
<p><span style="color: #888888;">WSGIDaemonProcess www-data<br />
WSGIProcessGroup www-data<br />
WSGIScriptAlias / /var/django/mysite/apache/django.wsgi<br />
&lt;/VirtualHost&gt;</span></p>
<p>After restarting apache :<br />
<span style="color: #808080;">sudo /etc/init.d/apache2 restart</span></p>
<p>I got an &#8220;It Worked&#8221; page when I point my browser to http://localhost:8080/</p>
<p>Of course this doesn&#8217;t allow you to use a database in your applications yet but it&#8217;s a start.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F05%2Fdjango-quick-install-with-wsgi.html&amp;linkname=Django%20Quick%20Install%20With%20WSGI"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/05/django-quick-install-with-wsgi.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unable to load dynamic library php_pgsql.dll</title>
		<link>http://codytaylor.org/2009/04/unable-to-load-dynamic-library-php_pgsqldll.html</link>
		<comments>http://codytaylor.org/2009/04/unable-to-load-dynamic-library-php_pgsqldll.html#comments</comments>
		<pubDate>Thu, 23 Apr 2009 19:46:37 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[problems and solutions]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[error]]></category>
		<category><![CDATA[postgres]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=12768</guid>
		<description><![CDATA[Unable to load dynamic library php_pgsql.dll The application has failed to start because its side-by-side configuration is incorrect. ]]></description>
			<content:encoded><![CDATA[<p>I was installing a postgres database to work with apache from uniform server. It was very slow due to running both mysql and postgres on a laptop. Since it was only for a tradeshow I didn&#8217;t really care. But I did get this error:<br />
<pre><code>
Unable to load dynamic library php_pgsql.dll The application has failed to start because its side-by-side configuration is incorrect. 
</code></pre><br />
After some reading about similar errors which were mostly about mysql because no one likes postgres. I managed to fix it by replacing the dll’s in the apache folder with the dll’s from the postgres folder.<br />
Nice and Easy.</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F04%2Funable-to-load-dynamic-library-php_pgsqldll.html&amp;linkname=Unable%20to%20load%20dynamic%20library%20php_pgsql.dll"><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/04/unable-to-load-dynamic-library-php_pgsqldll.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>INCREASE SEO with this mod_rewrite tutorial. Only the useful.</title>
		<link>http://codytaylor.org/2009/04/increase-seo-with-this-mod_rewrite-tutorial-only-the-useful.html</link>
		<comments>http://codytaylor.org/2009/04/increase-seo-with-this-mod_rewrite-tutorial-only-the-useful.html#comments</comments>
		<pubDate>Mon, 13 Apr 2009 01:23:31 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[problems and solutions]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[only the useful]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=12112</guid>
		<description><![CDATA[mod_rewrite apache module tutorial. Examples of basic RewriteRules with explanations of the regular expressions.]]></description>
			<content:encoded><![CDATA[<p>Since I didn&#8217;t really delve into how to actually use mod_rewrite to do something useful in my last post I will now.<br />
The main reason I got mod_rewrite going is to improve my search ranking for a few sites so I&#8217;ll show how to do this with a dynamic php site.<br />
What I primarily aimed at was to get $_GET variables to look like directories.</p>
<p>The .htaccess file from the previous post was<br />
<pre><code>
1. RewriteEngine on
2. RewriteRule ^/?test\.html$ test.php [L]
</code></pre></p>
<p>First line obviously turns on the .htaccess Rewrite Engine. .htaccess files can be used for other stuff. Check <a href='http://codytaylor.org/?p=11284'>here</a> for an example of a different use of a .htaccess file.</p>
<p>The second line is rewriting test.html to test.php. The text before the space represents the string to search and replace using regular expressions. The text after the space specifies what to replace the aforementioned string with. </p>
<p>This rule is really simple. The special characters that denote the regular expression are:</p>
<p>&#8216;^&#8217; 	This symbol, the caret, signifies the start of the URL.<br />
	This is under the current directory. Think of it like the &#8216;~&#8217; character on the command line.<br />
	If your site is <a href='http://www.quick-content.com'>http://www.quick-content.com</a> then<br />
	the &#8216;^&#8217; in these regular expressions are the equivalent of the that URL<br />
	(as long as the htaccess file is in the root directory for that site).</p>
<p>&#8216;$&#8217;	This symbol, the dollar sign, signifies the end of the URL.</p>
<p>&#8220;\.&#8217;	This is just a period. There is nothing special about this because it is &#8216;escaped&#8217; by the slash.<br />
	For the search this will look just tell apache to treat it like a normal period.<br />
	This is necessary because the period has a special meaning and in this case we just<br />
	want to look for a period and not any character (which is the &#8216;.&#8217;s normal meaning).</p>
<p>It&#8217;s great and all to redirect from one file to another using mod_rewrite and apache but it&#8217;s not that helpful for SEO.<br />
Here is another search and replace rewrite rule:<br />
<pre><code>
RewriteRule ^posts/([^/\.]+)\.html$ single_post.php?post_name=$1 [L]
</code></pre></p>
<p>This rule isn&#8217;t that simple.<br />
First we want to match all urls that start with &#8216;posts/&#8217;.<br />
Then we want to capture the characters that come after &#8216;post/&#8217; but before &#8216;.html&#8217; and use them as the get variable for the single_post php script.</p>
<p>This will rewrite pages like :<br />
http://www.quick-content.com/posts/techstuff.html<br />
to<br />
http://www.quick-content.com/single_post?post_name=techstuff</p>
<p>The &#8216;()&#8217; brackets tell apache to take whatever is inside of them and put it in a temporary location that can be acessed by the replacement string.<br />
In this case the string &#8217;somepost&#8217; is stored as $1. If you had multiple parenthesis then the $2,$3,.. would be used also.</p>
<p>The square brackets signify an expression of a sort. [0-9] will match any digit between 0 and 9. [^0-9] will match any character that is not between 0 and 9.<br />
So [^/\.]+ matches one or more characters that are not a slash or a dot.</p>
<p>After that the &#8216;\.html$&#8217; searches for the .html file extension so that url will look like a basic old html file.</p>
<p>A general overview of the structure of a mod_rewrite RewriteRule:</p>
<p><pre><code>
RewriteRule Pattern Substitution [OptionalFlags]
</code></pre></p>
<p>Fairly simple right? RewriteRules are dissected as follows:</p>
<p>RewriteRule<br />
    This is just the name of the command for apache.</p>
<p>Pattern<br />
    This is a regular expression which will be applied to the current URL. </p>
<p>Substitution<br />
    Substitution occurs in the same way as it does in Perl or PHP. </p>
<p>    You can include backreferences and server variable names in the substitution. Backreferences to this RewriteRule should be written as $N, whereas backreferences to the previous RewriteCond should be written as %N.</p>
<p>    A special substitution is -. This substitution tells Apache to not perform any substitution. </p>
<p>OptionalFlags</p>
<p>    Any flags should be surrounded in square brackets and comma separated. The most useful are:</p>
<p>        F &#8211; Forbidden. The user will receive a 403 error.<br />
        L &#8211; Last Rule. No more rules will be proccessed if this one was successful.<br />
        R[=code] &#8211; Redirect. The user’s web browser will be visibly redirected to the substituted URL.<br />
		If you use this flag, you must prefix the substitution with http://www.site.com/</p>
<p>    There are more flags but I haven&#8217;t had a use for them yet.</p>
<p>I did up a few other more complex rewrites for one of my dynamic sites. </p>
<p><pre><code>
RewriteRule ^([0-9]+)/([0-9]+)/?$ /index.php?num_posts=$1&amp;start=$2&nbsp;&nbsp;[L]
</code></pre></p>
<p>This one is pretty straight-forward if you understood the previous example.<br />
It is looking for two numerical strings separated by slashes. It then takes those two values and places them as the<br />
$_GET['num_posts'] and $_GET['start'] variables. The &#8216;/?&#8217; at the end allows for a possible slash.<br />
[0-9]+ means: match one or more characters that are between 0 and 9.</p>
<p>The main problem that I ran into was that after a rewrite all of the images and includes would not work because I&#8217;m lazy and use relative paths.<br />
So when I type a url like www.quick-content.com/10/11023/ I don&#8217;t get any images or style sheets because the browser is trying to find images<br />
at www.quick-content.com/10/images/. I had to write two rules to make this work properly:<br />
<pre><code>
RewriteRule ^.*/?.+/images/(.+)$ /images/$1 [L]
RewriteRule ^.*/?.+/includes/(.+)$ /includes/$1 [L]
</code></pre></p>
<p>These rules check for one or more directories before the image or includes directory and if they exist then it rewrites the url to either /images or /includes.<br />
The &#8216;.*/?&#8217; means 0 or more characters before an optional slash (the &#8216;?&#8217; following the slash means that it is optional).<br />
&#8216;.+/images/&#8217; and &#8216;.+/includes/ tries to match one or more characters before the image or includes directory.<br />
The &#8216;.&#8217; means any character. So &#8216;.*&#8217; means 0 or more any characters which is essentially any string.</p>
<p>Hopefully that wasn&#8217;t too confusing. There are a lot of great resources out there for learning regular expressions if you still don&#8217;t get it.<br />
-Cody Taylor</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F04%2Fincrease-seo-with-this-mod_rewrite-tutorial-only-the-useful.html&amp;linkname=INCREASE%20SEO%20with%20this%20mod_rewrite%20tutorial.%20Only%20the%20useful."><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/04/increase-seo-with-this-mod_rewrite-tutorial-only-the-useful.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up mod_rewrite on ubuntu example. Only the useful.</title>
		<link>http://codytaylor.org/2009/04/setting-up-mod_rewrite-on-ubuntu-example-only-the-useful.html</link>
		<comments>http://codytaylor.org/2009/04/setting-up-mod_rewrite-on-ubuntu-example-only-the-useful.html#comments</comments>
		<pubDate>Sun, 12 Apr 2009 13:25:10 +0000</pubDate>
		<dc:creator>Cody Taylor</dc:creator>
				<category><![CDATA[problems and solutions]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[only the useful]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://codytaylor.org/?p=12075</guid>
		<description><![CDATA[mod_rewrite is a way to change one url to another. It is very useful for making dynamic php sites better for search engine optimization (SEO).]]></description>
			<content:encoded><![CDATA[<p>mod_rewrite is a way to change one url to another. It is very useful for making dynamic php sites better for search engine optimization (SEO).</p>
<p>Obviously you&#8217;re going to need apache installed. I&#8217;m using Apache 2.0 with php5. This is how I did it.</p>
<p>I had hoped that it was already installed and I could just start writing regular expressions in an htaccess file and have everything work. So I went to check if it was installed by calling the phpinfo function. I created a file called asdf.php which contained:</p>
<p>I then did a search for rewrite in my browser. No go. So it&#8217;s either not installed or not enabled.<br />
I checked the /etc/apache2 directory for any files that look like mod_rewrite.<br />
I found rewrite.load in the mods-available directory. There is also a mods-enabled directory so I copied rewrite.load to mods-enabled with this command.<br />
<pre><code>
cody@taylor:/etc/apache2$: sudo cp rewrite.load ../mods-enabled/rewrite.load
</code></pre></p>
<p>I thought this may do it so I restarted apache2 with this command:<br />
<pre><code>
cody@taylor:/etc/apache2$: /etc/init.d/apache2 restart
</code></pre></p>
<p>I created two text files to test whether it was working:<br />
<pre><code>
filename: test.html
This is a HTML File</code></pre></p>
<p>filename: test.php<br />
This is a PHP File</p>
<p>I then created a .htaccess file in my web root directory which contained this text:<br />
<pre><code>
RewriteEngine on
RewriteRule ^/?test\.html$ test.php
</code></pre></p>
<p>I went to http://localhost/test.html hoping to see that it&#8217;s a php file. Didn&#8217;t work obviously.<br />
I checked the sites-enabled directory and opened 000-default in vim.</p>
<p>It contained :</p>
<p>        ServerAdmin webmaster@localhost<br />
                Options Indexes FollowSymLinks MultiViews<br />
                AllowOverride None<br />
                Order allow,deny<br />
                allow from all</p>
<p>        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/<br />
        ErrorLog /var/log/apache2/error.log</p>
<p>        # Possible values include: debug, info, notice, warn, error, crit,<br />
        # alert, emerg.<br />
        LogLevel warn</p>
<p>        CustomLog /var/log/apache2/access.log combined</p>
<p>    Alias /doc/ &#8220;/usr/share/doc/&#8221;<br />
        Options Indexes MultiViews FollowSymLinks<br />
        AllowOverride None<br />
        Order deny,allow<br />
        Deny from all<br />
        Allow from 127.0.0.0/255.0.0.0 ::1/128</p>
<p>AllowOverride is what I was looking for so I change AllowOverride to all and restart apache again.<br />
This time when i check http://localhost/test.html I get that it is a php file which is good.</p>
<p>I noticed I was getting this error when I restarted apache:<br />
<pre><code>
cody@taylor:/etc/apache2$: sudo /etc/init.d/apache2 restart
* Restarting web server apache2
apache2: Could not reliably determine the server&#039;s fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server&#039;s fully qualified domain name, using 127.0.1.1 for ServerName
</code></pre></p>
<p>I fixed this by adding this line to the apache2.conf file:<br />
<pre><code>
ServerName &quot;codytaylor.org&quot;
</code></pre></p>
<p>A restart fixed it all up.</p>
<p>-Cody Taylor</p>
<a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save?linkurl=http%3A%2F%2Fcodytaylor.org%2F2009%2F04%2Fsetting-up-mod_rewrite-on-ubuntu-example-only-the-useful.html&amp;linkname=Setting%20up%20mod_rewrite%20on%20ubuntu%20example.%20Only%20the%20useful."><img src="http://codytaylor.org/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a>]]></content:encoded>
			<wfw:commentRss>http://codytaylor.org/2009/04/setting-up-mod_rewrite-on-ubuntu-example-only-the-useful.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

