<?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>Zend Framework Blog</title>
	<atom:link href="http://blog.richardknop.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.richardknop.com</link>
	<description>Zend Framework, PHP, Django, Python, SQL, MySQL, PostgreSQL, Oracle, PL/SQL, data model patterns, OOP, design patterns, JavaScript, jQuery, HTML, XHTML, CSS, XML, web services &#38; APIs, Security, E-commerce and much more</description>
	<lastBuildDate>Sat, 04 Feb 2012 19:47:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>A MySQL procedure to drop all tables in a specific database</title>
		<link>http://blog.richardknop.com/2012/02/a-mysql-procedure-to-drop-all-tables-in-a-specific-database/</link>
		<comments>http://blog.richardknop.com/2012/02/a-mysql-procedure-to-drop-all-tables-in-a-specific-database/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 19:47:10 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[stored procedure]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=753</guid>
		<description><![CDATA[Here is a nice MySQL stored procedure which can be used to delete all tables in a specified database. It takes one argument &#8211; a database name &#8211; and it deletes all tables in that database. Be careful when using this procedure DROP PROCEDURE IF EXISTS drop_all_tables_from_specified_database; DELIMITER $$ CREATE PROCEDURE drop_all_tables_from_specified_database(IN dbname CHAR(50)) BEGIN [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a nice MySQL stored procedure which can be used to delete all tables in a specified database. It takes one argument &#8211; a database name &#8211; and it deletes all tables in that database. Be careful when using this procedure <img src='http://blog.richardknop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre>
DROP PROCEDURE IF EXISTS drop_all_tables_from_specified_database;

DELIMITER $$
CREATE PROCEDURE drop_all_tables_from_specified_database(IN dbname CHAR(50))
BEGIN
    DECLARE done INT DEFAULT FALSE;
    DECLARE tblname CHAR(50);
    DECLARE cur1 CURSOR FOR SELECT table_name FROM information_schema.tables WHERE table_schema = dbname COLLATE utf8_general_ci;
    DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;

    SET foreign_key_checks = 0;

    OPEN cur1;
    read_loop: LOOP
        FETCH cur1 INTO tblname;
        IF done THEN
            LEAVE read_loop;
        END IF;
        SET @database_name = dbname;
        SET @table_name = tblname;
        SET @sql_text = CONCAT('DROP TABLE ', @database_name, '.' , @table_name, ';');
        PREPARE stmt FROM @sql_text;
        EXECUTE stmt;
        DEALLOCATE PREPARE stmt;
    END LOOP;
    CLOSE cur1;

    SET foreign_key_checks = 1;

END$$
DELIMITER ;

CALL drop_all_tables_from_specified_database('test');

DROP PROCEDURE drop_all_tables_from_specified_database;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2012/02/a-mysql-procedure-to-drop-all-tables-in-a-specific-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install PHPUnit on FreeBSD 8.2</title>
		<link>http://blog.richardknop.com/2012/02/install-phpunit-on-freebsd-8-2/</link>
		<comments>http://blog.richardknop.com/2012/02/install-phpunit-on-freebsd-8-2/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 19:38:19 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[PHPUnit]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=746</guid>
		<description><![CDATA[Here is how to install PHPUnit on FreeBSD 8.2 so you can write unit tests for your code: #portsnap fetch #portsnap extract #portsnap update #cd /usr/ports/devel/pear #make #make install #pear channel-discover pear.symfony-project.com #pear install symfony/YAML #pear channel-discover pear.phpunit.de #pear install phpunit/PHPUnit #pear config-get php_dir The last line will show you the directory where PHPUnit was installed. Add [...]]]></description>
			<content:encoded><![CDATA[<p>Here is how to install PHPUnit on FreeBSD 8.2 so you can write unit tests for your code:</p>
<pre>#portsnap fetch
#portsnap extract
#portsnap update
#cd /usr/ports/devel/pear
#make
#make install

#pear channel-discover pear.symfony-project.com
#pear install symfony/YAML

#pear channel-discover pear.phpunit.de
#pear install phpunit/PHPUnit

#pear config-get php_dir</pre>
<p>The last line will show you the directory where PHPUnit was installed. Add it to your include path and you are ready to go:</p>
<div class="geshi no php">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">set_include_path</span><span class="br0">&#40;</span><span class="st0">&#39;/usr/local/share/pear&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">require_once</span><span class="br0">&#40;</span><span class="st0">&#39;PHPUnit/Autoload.php&#39;</span><span class="br0">&#41;</span><span class="sy0">;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">class</span> FooTest <span class="kw2">extends</span> PHPUnit_Framework_TestCase</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2012/02/install-phpunit-on-freebsd-8-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MAMP 2.0.5 PHP PEAR not working</title>
		<link>http://blog.richardknop.com/2012/02/mamp-2-0-5-php-pear-not-working/</link>
		<comments>http://blog.richardknop.com/2012/02/mamp-2-0-5-php-pear-not-working/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 19:33:28 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=743</guid>
		<description><![CDATA[After installing MAMP 2.0.5 on my Macbook I have found out PEAR doesn&#8217;t work (I wanted to use it to install PHPUnit for unit testing). This solves the problem: #rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf Once you delete that file PEAR will start working so you can install PHPUnit.]]></description>
			<content:encoded><![CDATA[<p>After installing MAMP 2.0.5 on my Macbook I have found out PEAR doesn&#8217;t work (I wanted to use it to install PHPUnit for unit testing). This solves the problem:</p>
<pre>#rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf</pre>
<p>Once you delete that file PEAR will start working so you can install PHPUnit.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2012/02/mamp-2-0-5-php-pear-not-working/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Django missing admin CSS stylesheets</title>
		<link>http://blog.richardknop.com/2012/01/django-missing-admin-css-stylesheets/</link>
		<comments>http://blog.richardknop.com/2012/01/django-missing-admin-css-stylesheets/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 16:34:38 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[Django]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[WSGI]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=733</guid>
		<description><![CDATA[Follow up on three of my previous posts: How to install and configure mod_wsgi on FreeBSD 8.2 How to install and configure Django with mod_wsgi on FreeBSD 8.2 Install PostgreSQL on FreeBSD 8.2 and make it work with Django I have been following the official Django tutorial and creating the polls app. I have decided [...]]]></description>
			<content:encoded><![CDATA[<p>Follow up on three of my previous posts:</p>
<ul>
<li><a href="http://blog.richardknop.com/2012/01/how-to-install-and-configure-mod_wsgi-on-freebsd-8-2/">How to install and configure mod_wsgi on FreeBSD 8.2</a></li>
<li><a href="http://blog.richardknop.com/2012/01/how-to-install-and-configure-django-with-mod_wsgi-on-freebsd-8-2/">How to install and configure Django with mod_wsgi on FreeBSD 8.2</a></li>
<li><a href="http://blog.richardknop.com/2012/01/install-postgresql-on-freebsd-8-2-and-make-it-work-with-django/">Install PostgreSQL on FreeBSD 8.2 and make it work with Django</a></li>
</ul>
<p>I have been following the official Django tutorial and creating the polls app. I have decided to test my app in a FreeBSD virtual machine with properly configured Apache instead of the development server though.</p>
<p>I got to the part where I am supposed to log in into the automatically generated admin area.  The http://IP_OF_MY_TEST_VM/admin/ works and I get the admin sign in page but the links to stylesheets are not working. It&#8217;s simple to fix that.</p>
<p>My app is located in /usr/local/www/myapp folder and it&#8217;s document root is set via httpd.conf to /usr/local/www/myapp/public directory. So:</p>
<pre>#cd /usr/local/www/myapp/public
#mkdir static
#cd static
#mkdir admin
#cp -r /usr/local/lib/python2.7/site-packages/django/contrib/admin/media/* /usr/local/www/myapp/public/static/admin</pre>
<p>That should copy free directories (css, img, js) into your document root. One more thing, edit your virtual host configuration to tell mod_wsgi to match /static/ to /usr/local/www/myapp/public/static/:</p>
<pre>WSGIPythonPath /usr/local/www
&lt;VirtualHost *:80&gt;
  ServerName localhost.home
  ServerAlias localhost.home

  DocumentRoot /usr/local/www/myapp/public
  Alias /static/ /usr/local/www/myapp/public/static/

  &lt;Directory /usr/local/www/myapp/public&gt;
  Order allow,deny
  Allow from all
  &lt;/Directory&gt;

  WSGIScriptAlias / /usr/local/www/myapp/wsgi.py

  &lt;Directory /usr/local/www&gt;
  Order allow,deny
  Allow from all
  &lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre>
<p>Restart Apache:</p>
<pre>#/usr/local/sbin/apachectl restart</pre>
<p>And go to http://IP_OF_MY_TEST_VM/admin/. CSS stylesheets should now get loaded properly <img src='http://blog.richardknop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2012/01/django-missing-admin-css-stylesheets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PostgreSQL chear sheet</title>
		<link>http://blog.richardknop.com/2012/01/postgresql-chear-sheet/</link>
		<comments>http://blog.richardknop.com/2012/01/postgresql-chear-sheet/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 15:02:34 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[pgsql]]></category>
		<category><![CDATA[psql]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=731</guid>
		<description><![CDATA[Since I have been using MySQL for a long time, transition to PostgreSQL is a little bit difficult. I will be posting some useful commands here for my own reference. This post will be getting updated a lot. I have explained how to install PostgreSQL on FreeBSD 8.2 in my previous post. To create a [...]]]></description>
			<content:encoded><![CDATA[<p>Since I have been using MySQL for a long time, transition to PostgreSQL is a little bit difficult. I will be posting some useful commands here for my own reference. This post will be getting updated a lot.</p>
<p>I have explained <a href="http://blog.richardknop.com/2012/01/install-postgresql-on-freebsd-8-2-and-make-it-work-with-django/">how to install PostgreSQL on FreeBSD 8.2</a> in my previous post.</p>
<p>To create a database:</p>
<pre>#su pgsql
$ createdb db_name
$ exit</pre>
<p>To drop a database:</p>
<pre>#su pgsql
$ dropdb db_name
$ exit</pre>
<p>To list all databases:</p>
<pre>#psql -l</pre>
<p>To open psql prompt for a database and a user:</p>
<pre>#psql db_name -U user</pre>
<h3>After opening psql prompt with psql db_name -U user</h3>
<p>To list all tables in a database:</p>
<pre>\d</pre>
<p>To describe  a table structure:</p>
<pre>\d table_name</pre>
<p>Psql help:</p>
<pre>\?</pre>
<p>To quit psql prompt:</p>
<pre>\q</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2012/01/postgresql-chear-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install PostgreSQL on FreeBSD 8.2 and make it work with Django</title>
		<link>http://blog.richardknop.com/2012/01/install-postgresql-on-freebsd-8-2-and-make-it-work-with-django/</link>
		<comments>http://blog.richardknop.com/2012/01/install-postgresql-on-freebsd-8-2-and-make-it-work-with-django/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 02:43:09 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[PostgreSQL]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[psycopg2]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=724</guid>
		<description><![CDATA[Follow up on my previous two blog posts: How to install and configure mod_wsgi on FreeBSD 8.2 How to install and configure Django with mod_wsgi on FreeBSD 8.2 I am going to write down installation steps for PostgreSQL on FreeBSD 8.2 so it can be used with django.db.backends.postgresql_psycopg2 adapter. #cd /usr/ports/databases/postgresql91-server #make #make install Add [...]]]></description>
			<content:encoded><![CDATA[<p>Follow up on my previous two blog posts:</p>
<ul>
<li><a href="http://blog.richardknop.com/2012/01/how-to-install-and-configure-mod_wsgi-on-freebsd-8-2/">How to install and configure mod_wsgi on FreeBSD 8.2</a></li>
<li><a href="http://blog.richardknop.com/2012/01/how-to-install-and-configure-django-with-mod_wsgi-on-freebsd-8-2/">How to install and configure Django with mod_wsgi on FreeBSD 8.2</a></li>
</ul>
<p>I am going to write down installation steps for PostgreSQL on FreeBSD 8.2 so it can be used with django.db.backends.postgresql_psycopg2 adapter.</p>
<pre>#cd /usr/ports/databases/postgresql91-server
#make
#make install</pre>
<p>Add this line to /etc/rc.conf:</p>
<pre>postgresql_enable="YES"</pre>
<p>Next, initialize a PostgreSQL database cluster:</p>
<pre>#/usr/local/etc/rc.d/postgresql initdb</pre>
<p>Now add this line to /usr/local/pgsql/data/postgresql.conf:</p>
<pre>listen_addresses = '*'</pre>
<p>Thirdly, add this line to /usr/local/pgsql/data/pg_hba.conf:</p>
<pre>host   all   all   127.0.01/32 md5</pre>
<p>Reboot. Now let&#8217;s create a new user for our PostgreSQL database:</p>
<pre>#su pgsql
$ createuser -sdrP username
Enter password for new role: ******
Enter it again: ******

$ exit</pre>
<p>Finally, we need to install psycopg2 client in order to be able to connect to the PostgreSQL server from a Django web application.</p>
<pre>#pip install psycopg2
#/usr/local/sbin/apachectl restart</pre>
<p>Cool. Now you should be able to connect to the PostgreSQL server from your Django app. Make sure to create a database first:</p>
<pre>#su pgsql
$ createdb myapp
$ exit</pre>
<p>Now go to your Django application folder and edit settings.py. Use django.db.backends.postgresql_psycopg2 as ENGINE, also set NAME, USER and PASSWORD fields. Reload the Django app in the browser and it should work fine.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2012/01/install-postgresql-on-freebsd-8-2-and-make-it-work-with-django/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to install and configure Django with mod_wsgi on FreeBSD 8.2</title>
		<link>http://blog.richardknop.com/2012/01/how-to-install-and-configure-django-with-mod_wsgi-on-freebsd-8-2/</link>
		<comments>http://blog.richardknop.com/2012/01/how-to-install-and-configure-django-with-mod_wsgi-on-freebsd-8-2/#comments</comments>
		<pubDate>Sat, 21 Jan 2012 20:55:20 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[Django]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[WSGI]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=713</guid>
		<description><![CDATA[This is a follow up on my previous post: How to install and configure mod_wsgi on FreeBSD 8.2 I will assume you have followed all steps in the previous blog post and have FreeBSD 8.2 with Apache, Python and mod_wsgi installed and configured properly. We will use the same directory as we used for the [...]]]></description>
			<content:encoded><![CDATA[<p>This is a follow up on my previous post: <a href="http://blog.richardknop.com/2012/01/how-to-install-and-configure-mod_wsgi-on-freebsd-8-2/">How to install and configure mod_wsgi on FreeBSD 8.2</a></p>
<p>I will assume you have followed all steps in the previous blog post and have FreeBSD 8.2 with Apache, Python and mod_wsgi installed and configured properly. We will use the same directory as we used for the hello world python WSGI web app in the previous article. However, we will re-create it with Django so let&#8217;s delete if first:</p>
<pre>#rm -rf /user/local/www/myapp</pre>
<p>Let&#8217;s install Django:</p>
<pre>#cd /usr/ports/devel/py-pip
#make
#make install</pre>
<p>Either refresh your shell path or reboot your virtual machine and install Django via pip:</p>
<pre>#pip install django</pre>
<p>Test Django installation:</p>
<pre>#python
&gt;&gt;&gt;import django</pre>
<p>Next, I used UNIX find comman to find django-admin.py file:</p>
<pre>#find / -name django-admin.py
/usr/local/bin/django-admin.py
/usr/local/lib/python2.7/site-packages/django/bin/django-admin.py</pre>
<p>Let&#8217;s go to the /usr/local/www directory:</p>
<pre>#cd /usr/local/www</pre>
<p>And type:</p>
<pre>#/usr/local/bin/django-admin.py startproject myapp</pre>
<p>This will create a myapp directory with couple of files inside it, basically a standard Django project.</p>
<p>The only thing remaning is to configure mod_wsgi. First, edit the Apache configuration file:</p>
<pre>#ee /usr/local/etc/apache22/httpd.conf</pre>
<p>It should look exactly like the one in my previous blog post, the only thing changed is that I have moved the virtual host into a separate file. So delete the virtual host configuration and add an Include directive:</p>
<pre>Include /usr/local/www/myapp/httpd.conf</pre>
<p>I am basically telling the Apache to include contents of another httpd.conf file which will be inside the /usr/local/www/myapp folder. This way the virtual host configuration for our app will be inside the app home folder which makes way more sense. So create a new httpd.conf file:</p>
<pre>#cd /usr/local/www/myapp
#ee httpd.conf</pre>
<p>Configure an Apache virtual  host for our Django app:</p>
<pre>WSGIPythonPath /usr/local/www
&lt;VirtualHost *:80&gt;
  ServerName localhost.home
  ServerAlias localhost.home

  DocumentRoot /usr/local/www/myapp/public

  &lt;Directory /usr/local/www/myapp/public&gt;
  Order allow,deny
  Allow from all
  &lt;/Directory&gt;

  WSGIScriptAlias / /usr/local/www/myapp/wsgi.py

  &lt;Directory /usr/local/www&gt;
  Order allow,deny
  Allow from all
  &lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre>
<p>Finally, you might have noticed that our Django app is missing the wsgi.py file mentioned in the httpd.conf. Let&#8217;s create it:</p>
<pre>#ee wsgi.py</pre>
<p>The simplest Django app will look like this:</p>
<pre>import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'myapp.settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()</pre>
<p>That&#8217;s it. Open the app in your browser and you should see a page like this:</p>
<p style="text-align: center;"><a href="http://blog.richardknop.com/wp-content/uploads/2012/01/Screen-shot-2012-01-21-at-20.43.22.png"><img class="aligncenter  wp-image-719" title="Django project welcome page" src="http://blog.richardknop.com/wp-content/uploads/2012/01/Screen-shot-2012-01-21-at-20.43.22.png" alt="" width="508" height="120" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2012/01/how-to-install-and-configure-django-with-mod_wsgi-on-freebsd-8-2/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to install and configure mod_wsgi on FreeBSD 8.2</title>
		<link>http://blog.richardknop.com/2012/01/how-to-install-and-configure-mod_wsgi-on-freebsd-8-2/</link>
		<comments>http://blog.richardknop.com/2012/01/how-to-install-and-configure-mod_wsgi-on-freebsd-8-2/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 23:48:29 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Python27]]></category>
		<category><![CDATA[WSGI]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=698</guid>
		<description><![CDATA[I will cover installation and configuration process of mod_wsgi on a fresh installation of FreeBSD 8.2. After that I will show you how to create a Hello World Python web application using the just installed and configured mod_wsgi. There are multiple ways to use Python for web development (for example, mod_python) but mod_wsgi is recommended [...]]]></description>
			<content:encoded><![CDATA[<p>I will cover installation and configuration process of <a href="http://code.google.com/p/modwsgi/">mod_wsgi</a> on a fresh installation of FreeBSD 8.2. After that I will show you how to create a Hello World Python web application using the just installed and configured mod_wsgi.</p>
<p>There are multiple ways to use Python for web development (for example, mod_python) but mod_wsgi is recommended as the best approach in the Python documentation.</p>
<p>I have set up a fresh installation of FreeBSD 8.2 for i386 platform in VirtualBox on my MacBook. You can <a href="http://www.freebsd.org/where.html">get FreeBSD here</a>.</p>
<p>Enough talking, let&#8217;s start. First, let&#8217;s update the port collection. Run these commands:</p>
<pre>#portsnap fetch
#portsnap extract
#portsnap update</pre>
<p>Ok. Let&#8217;s install Apache:</p>
<pre>#cd /usr/ports/www/apache22
#make config</pre>
<p>Make sure THREADS option is selected.</p>
<pre>#make
#make install</pre>
<p>Make sure Apache is started with every reboot:</p>
<pre>#ee /etc/rc.conf
apache22_enable="YES"</pre>
<p>You will also edit one more file:</p>
<pre>#ee /boot/loader.conf
accf_http_load="YES"</pre>
<p>Now the important part. Let&#8217;s install mod_wsgi:</p>
<pre>#cd /usr/ports/www/mod_wsgi3
make
make install</pre>
<p>Cool. Let&#8217;s create a directory for our hello world application (and a public directory inside it &#8211; that will be internet accessible directory where you can put your stylesheets or javascript files):</p>
<pre>#mkdir /usr/local/www/myapp
#mkdir /usr/local/www/myapp/public
#cd /usr/local/www/myapp</pre>
<p>Let&#8217;s create a virtual host in the directory. Before editing httpd.conf file, make sure to make a backup in case something goes wrong:</p>
<pre>#cp /usr/local/etc/apache22/httpd.conf /usr/local/etc/apache22/httpd.conf.backup</pre>
<p>After that, remove or comment out ServerRoot, DocumentRoot and their corresponding Directory Apache directives and add this line on the bottom of the the /usr/local/etc/apache22/httpd.conf file:</p>
<pre>Include /usr/local/www/myapp/httpd.conf</pre>
<p>Create the file httpd.conf inside the /usr/local/www/myapp folder. It will contain virtual host configuration for our application:</p>
<pre>#ee /usr/local/www/myapp/httpd.conf</pre>
<p>Add this inside the just created httpd.conf:</p>
<pre>WSGIPythonPath /usr/local/www/myapp

&lt;VirtualHost *:80&gt;
  ServerName localhost
  ServerAlias localhost

  DocumentRoot /usr/local/www/myapp/public

  &lt;Directory /usr/local/www/myapp/public&gt;
  Order allow,deny
  Allow from all
  &lt;/Directory&gt;

  WSGIScriptAlias / /usr/local/www/myapp/myapp.wsgi

  &lt;Directory /usr/local/www/myapp&gt;
  Order allow,deny
  Allow from all
  &lt;/Directory&gt;
&lt;/VirtualHost&gt;</pre>
<p>There are few important lines:</p>
<ul>
<li>WSGIPythonPath will be added to sys.path. Make sure to set this variable in httpd.conf so you can load modules and packages in Python.</li>
<li>WSGIScriptAlias is an URLI alias that will tell Apache to call the /usr/local/www/myapp/myapp.wsgi. I have put there just a forward slash so http://localhost/ will be the URI which will set off the myapp.wsgi script. If I were to put /myapp there, http://localhost/myapp would be the URI which would set off the wsgi script.</li>
</ul>
<p>You might be wondering what should the /usr/local/www/myapp/myapp.wsgi script look like. Here is a simplest example:</p>
<pre>import wsgiref

def application(environ, start_response):
    response_status = '200 OK'
    response_body = 'Hello!'
    response_headers = []
    content_type = ('Content-type', 'text-plain')
    content_length = ('Content-Length', str(len(response_body)))
    response_headers.append(content_type)
    response_headers.append(content_length)
    start_response(response_status, response_headers)
    return [response_body]</pre>
<p>Now restart Apache:</p>
<pre>#/etc/local/sbin/apachectl restart</pre>
<p>Go to http://localhost/ and enjoy your first working Python WSGI app <img src='http://blog.richardknop.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>Of course, substitute localhost for your IP address if you are not working on your local development machine. If you are using VirtualBox, find out the VirtualBox instance IP address with ifconfig and use that.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2012/01/how-to-install-and-configure-mod_wsgi-on-freebsd-8-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Set default encoding in Eclipse to UTF-8</title>
		<link>http://blog.richardknop.com/2011/09/set-default-encoding-in-eclipse-to-utf-8/</link>
		<comments>http://blog.richardknop.com/2011/09/set-default-encoding-in-eclipse-to-utf-8/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 20:24:29 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=660</guid>
		<description><![CDATA[Just add this line to eclipse.ini: -Dfile.encoding=UTF-8]]></description>
			<content:encoded><![CDATA[<p>Just add this line to eclipse.ini:</p>
<pre>-Dfile.encoding=UTF-8</pre>
<p> <img src='http://blog.richardknop.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2011/09/set-default-encoding-in-eclipse-to-utf-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making Zend Framework run under IIS</title>
		<link>http://blog.richardknop.com/2011/09/making-zend-framework-run-under-iis/</link>
		<comments>http://blog.richardknop.com/2011/09/making-zend-framework-run-under-iis/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 18:47:04 +0000</pubDate>
		<dc:creator>Richard Knop</dc:creator>
				<category><![CDATA[IIS]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend Framework]]></category>
		<category><![CDATA[Set up Zend Framework project under IIS 7]]></category>
		<category><![CDATA[Zend Framework IIS rewrite rules]]></category>

		<guid isPermaLink="false">http://blog.richardknop.com/?p=666</guid>
		<description><![CDATA[PHP is usually used together with Apache web server but sometimes, mainly during development, it is easier to work on a Windows PC with IIS 7. Fortunately, PHP and IIS 7 are friends and it&#8217;s easy to set up a Zend Framework project under IIS 7 webs server. I have decided to merge together few [...]]]></description>
			<content:encoded><![CDATA[<p>PHP is usually used together with Apache web server but sometimes, mainly during development, it is easier to work on a Windows PC with IIS 7. Fortunately, PHP and IIS 7 are friends and it&#8217;s easy to set up a Zend Framework project under IIS 7 webs server. I have decided to merge together few of my older posts which dealt with smaller parts of the whole process. This post should cover installation of IIS 7, PHP, configuration of PHP in IIS manager and finally setting up a Zend Framework project. Let&#8217;s begin.</p>
<p>First, you need to install PHP. Download it from <a href="http://php.iis.net/">here</a> and install it with default settings. On Windows 7 default installation path should be:</p>
<pre>C:\Program Files (x86)\PHP\v5.3</pre>
<p>Second, install IIS 7. That&#8217;s too easy so I won&#8217;t give you step by step instructions.</p>
<p>Third, we need to set handler mappings for PHP in IIS manager. Click on Start, type IIS and open Internet Information Services (IIS) Manager:</p>
<div id="attachment_667" class="wp-caption aligncenter" style="width: 423px"><a href="http://blog.richardknop.com/wp-content/uploads/2011/09/1.jpg"><img class="size-full wp-image-667" title="Open Internet Information Services (IIS) Manager" src="http://blog.richardknop.com/wp-content/uploads/2011/09/1.jpg" alt="Open Internet Information Services (IIS) Manager" width="413" height="517" /></a><p class="wp-caption-text">Open Internet Information Services (IIS) Manager</p></div>
<p>In IIS Manager click on Handler Mappings:</p>
<div id="attachment_673" class="wp-caption aligncenter" style="width: 611px"><a href="http://blog.richardknop.com/wp-content/uploads/2011/09/2.jpg"><img class="size-full wp-image-673 " title="Click on Handler Mappings in IIS manager" src="http://blog.richardknop.com/wp-content/uploads/2011/09/2.jpg" alt="Click on Handler Mappings in IIS manager" width="601" height="352" /></a><p class="wp-caption-text">Click on Handler Mappings in IIS manager</p></div>
<p>Click on Add Module Mapping. In Request Path field type &#8220;*.php&#8221;, choose &#8220;FastCgiModule&#8221; as Module and type path to your php-cgi.exe file into Executable (Optional) field, in my case &#8220;C:\Program Files (x86)\PHP\v5.3\php-cgi.exe&#8221;. Type &#8220;PHP_via_FastCGI&#8221; into Name field. Click on OK. The handler mapping should look like this:</p>
<div id="attachment_674" class="wp-caption aligncenter" style="width: 613px"><a href="http://blog.richardknop.com/wp-content/uploads/2011/09/3.jpg"><img class="size-full wp-image-674 " title="PHP Handler Mapping" src="http://blog.richardknop.com/wp-content/uploads/2011/09/3.jpg" alt="PHP Handler Mapping" width="603" height="352" /></a><p class="wp-caption-text">PHP Handler Mapping</p></div>
<p>Next, we need to tell IIS manager to treat index.php files as default opening points for PHP websites. Open command line and execute this command:</p>
<pre>%windir%\system32\inetsrv\appcmd.exe set config ^ -section:system.webServer/defaultDocument /+"files.[value='index.php']" ^ /commit:apphost</pre>
<div id="attachment_676" class="wp-caption aligncenter" style="width: 552px"><a href="http://blog.richardknop.com/wp-content/uploads/2011/09/4.jpg"><img class="size-full wp-image-676 " title="Add index.php as default file to IIS 7" src="http://blog.richardknop.com/wp-content/uploads/2011/09/4.jpg" alt="Add index.php as default file to IIS 7" width="542" height="273" /></a><p class="wp-caption-text">Add index.php as default file to IIS 7</p></div>
<p>You should have PHP installed and configured correctly in IIS 7 now. As a checkpoint, create a new website with different port than the default one (e.g. 81), add index.php file with some simple echo statement to its root directory and open it in a web browser.</p>
<div id="attachment_677" class="wp-caption aligncenter" style="width: 613px"><a href="http://blog.richardknop.com/wp-content/uploads/2011/09/5.jpg"><img class="size-full wp-image-677 " title="Create a new website and test your configuration with simple index.php" src="http://blog.richardknop.com/wp-content/uploads/2011/09/5.jpg" alt="Create a new website and test your configuration with simple index.php" width="603" height="352" /></a><p class="wp-caption-text">Create a new website and test your configuration with simple index.php</p></div>
<p>In the case of the image above, the URI of that website would be http://localhost:82/. Open it in your web browser. If everything works fine, we can move on.</p>
<p>Create your usual directory structure for Zend Framework in the root of your newly created website. The only thing left is rewriting URIs. Since IIS 7 does not support .htaccess files we are all used to from Apache environments, you will need to install the <a href="http://www.iis.net/download/urlrewrite">URL Rewrite module for IIS</a>.</p>
<p>You can use my <a href="http://blog.richardknop.com/2009/06/zend-blank-project-v15/">Zend blank project</a> to create a quick basic structure for Zend Framework project with already configured index.php and bootstrap files. Just download the zipped file and unzip its contents inside the root directory of your newly created website. In case of this tutorial that would be C:\inetpub\test_website. The only thing you need to edit is the include path in index.php, so it will point to your Zend Framework library folder.</p>
<p>Create a file named web.config in the public directory of your Zend Framework project and put this XML code there:</p>
<div>
<div class="geshi no xml">
<ol>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;?xml</span> <span class="re0">version</span>=<span class="st0">&quot;1.0&quot;</span> <span class="re0">encoding</span>=<span class="st0">&quot;UTF-8&quot;</span><span class="re2">?&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;configuration<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;system</span>.webServer<span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;rewrite<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;rules<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;rule</span> <span class="re0">name</span>=<span class="st0">&quot;Imported Rule 1&quot;</span> <span class="re0">stopProcessing</span>=<span class="st0">&quot;true&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;match</span> <span class="re0">url</span>=<span class="st0">&quot;^.*$&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;conditions</span> <span class="re0">logicalGrouping</span>=<span class="st0">&quot;MatchAny&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;add</span> <span class="re0">input</span>=<span class="st0">&quot;{REQUEST_FILENAME}&quot;</span> <span class="re0">matchType</span>=<span class="st0">&quot;IsFile&quot;</span> <span class="re0">pattern</span>=<span class="st0">&quot;&quot;</span> <span class="re0">ignoreCase</span>=<span class="st0">&quot;false&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;add</span> <span class="re0">input</span>=<span class="st0">&quot;{REQUEST_FILENAME}&quot;</span> <span class="re0">matchType</span>=<span class="st0">&quot;IsDirectory&quot;</span> <span class="re0">pattern</span>=<span class="st0">&quot;&quot;</span> <span class="re0">ignoreCase</span>=<span class="st0">&quot;false&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/conditions<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;action</span> <span class="re0">type</span>=<span class="st0">&quot;None&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/rule<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;rule</span> <span class="re0">name</span>=<span class="st0">&quot;Imported Rule 2&quot;</span> <span class="re0">stopProcessing</span>=<span class="st0">&quot;true&quot;</span><span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;match</span> <span class="re0">url</span>=<span class="st0">&quot;^.*$&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;action</span> <span class="re0">type</span>=<span class="st0">&quot;Rewrite&quot;</span> <span class="re0">url</span>=<span class="st0">&quot;index.php&quot;</span> <span class="re2">/&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/rule<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/rules<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="sc3"><span class="re1">&lt;/rewrite<span class="re2">&gt;</span></span></span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="sc3"><span class="re1">&lt;/system</span>.webServer<span class="re2">&gt;</span></span></div>
</li>
<li class="li1">
<div class="de1"><span class="sc3"><span class="re1">&lt;/configuration<span class="re2">&gt;</span></span></span></div>
</li>
</ol>
</div>
</div>
<div id="attachment_683" class="wp-caption aligncenter" style="width: 611px"><a href="http://blog.richardknop.com/wp-content/uploads/2011/09/6.jpg"><img class="size-full wp-image-683 " title="Create web.config file in public directory and put rewrite rules in it" src="http://blog.richardknop.com/wp-content/uploads/2011/09/6.jpg" alt="Create web.config file in public directory and put rewrite rules in it" width="601" height="425" /></a><p class="wp-caption-text">Create web.config file in public directory and put rewrite rules in it</p></div>
<p>Open your website in the browser and it it should work correctly. In case you used my Zend blank project you should see a page like this:</p>
<div id="attachment_685" class="wp-caption aligncenter" style="width: 604px"><a href="http://blog.richardknop.com/wp-content/uploads/2011/09/11.jpg"><img class="size-full wp-image-685  " title="Hurray! You got Zend Framework working like charm under IIS 7 ;)" src="http://blog.richardknop.com/wp-content/uploads/2011/09/11.jpg" alt="Hurray! You got Zend Framework working like charm under IIS 7 ;)" width="594" height="183" /></a><p class="wp-caption-text">Hurray! You got Zend Framework working like charm under IIS 7 <img src='http://blog.richardknop.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p></div>
<p>Final tip. You might have noticed that IIS 7 by default does not show you any PHP application errors. As a developer surely you need to see the errors so you can fix them. Just open your php.ini file, find display_errors directive and set it to On:</p>
<div id="attachment_687" class="wp-caption aligncenter" style="width: 540px"><a href="http://blog.richardknop.com/wp-content/uploads/2011/09/Untitled.jpg"><img class="size-full wp-image-687 " title="Set display_errors directive in php.ini to On" src="http://blog.richardknop.com/wp-content/uploads/2011/09/Untitled.jpg" alt="Set display_errors directive in php.ini to On" width="530" height="248" /></a><p class="wp-caption-text">Set display_errors directive in php.ini to On</p></div>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.richardknop.com/2011/09/making-zend-framework-run-under-iis/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

