<?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>P0L0&#039;s Blog &#187; virtualenv</title>
	<atom:link href="http://p0l0.binware.org/index.php/tag/virtualenv/feed/" rel="self" type="application/rss+xml" />
	<link>http://p0l0.binware.org</link>
	<description>Opensource Projects and IT experiences</description>
	<lastBuildDate>Sun, 30 Oct 2011 08:39:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Installing TRAC with mod_wsgi using virtualenv</title>
		<link>http://p0l0.binware.org/index.php/2010/05/10/installing-trac-with-mod_wsgi-using-virtualenv/</link>
		<comments>http://p0l0.binware.org/index.php/2010/05/10/installing-trac-with-mod_wsgi-using-virtualenv/#comments</comments>
		<pubDate>Mon, 10 May 2010 19:33:03 +0000</pubDate>
		<dc:creator>P0L0</dc:creator>
				<category><![CDATA[Blog]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[IT Security]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[mod_wsgi]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[trac]]></category>
		<category><![CDATA[virtualenv]]></category>

		<guid isPermaLink="false">http://p0l0.binware.org/?p=664</guid>
		<description><![CDATA[This guide is for installing Trac as a user using virtualenv for a isolated Python environment so that the whole installation runs under a specific user. First of all we need to install needed packages apt-get install libapache2-mod-wsgi python-virtualenv python-setuptools Once we have installed the required packages proceed to create the Python environment mkdir /usr/local/trac [...]]]></description>
			<content:encoded><![CDATA[<p>This guide is for installing <a href="http://trac.edgewall.org/" target="_blank">Trac </a> as a user using <a href="http://pypi.python.org/pypi/virtualenv/1.4.8" target="_blank">virtualenv</a> for a isolated Python environment so that the whole installation runs under a specific user.</p>
<p>First of all we need to install needed packages</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libapache2-mod-wsgi python-virtualenv python-setuptools</pre></div></div>

<p>Once we have installed the required packages proceed to create the Python environment</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac
virtualenv python</pre></div></div>

<p>We now have the isolated Python environment locate under <strong>/usr/local/trac/python</strong>.</p>
<p>To make possible to use <strong>easy_install</strong> with repositories we need to upgrade easy_install. I use this to install Trac plugins directly from SVN.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>easy_install <span style="color: #660033;">-U</span> trunk</pre></div></div>

<p>We now can install trac 0.12 using the 0.12b1 SVN Tag (<strong>http://svn.edgewall.com/repos/trac/tags/trac-0.12b1</strong> or <strong>Trac==0.12b1</strong>) or directly from SVN Trunk:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>easy_install http:<span style="color: #000000; font-weight: bold;">//</span>svn.edgewall.org<span style="color: #000000; font-weight: bold;">/</span>repos<span style="color: #000000; font-weight: bold;">/</span>trac<span style="color: #000000; font-weight: bold;">/</span>trunk</pre></div></div>

<p>This will download and install the latest trunk version for Trac.</p>
<p>To have webaccess to the Trac projects, we need a <strong>.wsgi</strong> script, were we define where our local python environment is located:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;"># Not needed if mod_wsgi &gt;= 3.0</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span> = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stderr</span>
&nbsp;
<span style="color: #808080; font-style: italic;"># Load Trac</span>
<span style="color: #ff7700;font-weight:bold;">import</span> trac.<span style="color: black;">web</span>.<span style="color: black;">main</span>
application = trac.<span style="color: black;">web</span>.<span style="color: black;">main</span>.<span style="color: black;">dispatch_request</span></pre></div></div>

<p>And finally we need to configure apache. If you want only one Trac project, you should define <strong>trac.env</strong> to the location of your trac, but if you want multiproject support, you must use <strong>trac.env_parent_dir</strong> (this is what I used)</p>

<div class="wp_syntax"><div class="code"><pre class="apache" style="font-family:monospace;">&lt;<span style="color: #000000; font-weight:bold;">virtualhost</span> *:<span style="color: #ff0000;">80</span>&gt;
    <span style="color: #00007f;">ServerName</span> trac.dns.com
&nbsp;
    <span style="color: #00007f;">DocumentRoot</span> /usr/local/trac/htdocs
    <span style="color: #00007f;">ErrorLog</span> /var/log/apache2/trac-error.log
    <span style="color: #00007f;">CustomLog</span> /var/log/apache2/trac-access.log combined
&nbsp;
    <span style="color: #adadad; font-style: italic;"># Trac Auth</span>
    &lt;<span style="color: #000000; font-weight:bold;">location</span> /&gt;
        <span style="color: #00007f;">AuthType</span> Basic
        <span style="color: #00007f;">AuthName</span> <span style="color: #7f007f;">&quot;Trac&quot;</span>
        <span style="color: #00007f;">AuthUserFile</span> /usr/local/trac/.htpasswd
        <span style="color: #00007f;">Require</span> valid-<span style="color: #00007f;">user</span>
    &lt; /location&gt;
&nbsp;
    <span style="color: #adadad; font-style: italic;">#Trac</span>
    <span style="color: #adadad; font-style: italic;">#Define ProcessGroup with user and group under which it should run</span>
    WSGIDaemonProcess trac <span style="color: #00007f;">user</span>=trac <span style="color: #00007f;">group</span>=trac python-path=/usr/local/trac/python/lib/python2.5/site-packages python-eggs=/usr/local/trac/python/cache
    WSGIScriptAlias / /usr/local/trac/htdocs/trac.wsgi
&nbsp;
    &lt;<span style="color: #000000; font-weight:bold;">directory</span> /usr/local/trac/htdocs&gt;
        WSGIProcessGroup trac
        WSGIApplicationGroup %{GLOBAL}
        <span style="color: #00007f;">SetEnv</span> trac.env_parent_dir /usr/local/trac/projects
    &lt;/<span style="color: #000000; font-weight:bold;">directory</span>&gt;
&lt;/<span style="color: #000000; font-weight:bold;">virtualhost</span>&gt;</pre></div></div>

<p>We need to create the user and change the permissions for <strong>/usr/local/trac</strong> for that user <strong>trac</strong></p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">adduser <span style="color: #660033;">--home</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac <span style="color: #660033;">--shell</span> <span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span> <span style="color: #660033;">--no-create-home</span> trac
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> trac:trac <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac</pre></div></div>

<p>If you get an error <strong>&#8220;ImportError: No module named simplejson&#8221;</strong> just install it using easy_install</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>trac<span style="color: #000000; font-weight: bold;">/</span>python<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>easy_install simplejson</pre></div></div>

<p><div style="margin-left: -20px; margin-top: 20px; margin-bottom: 20px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-5682258244719056";
/* Inline Post */
google_ad_slot = "6946080416";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div></p>
]]></content:encoded>
			<wfw:commentRss>http://p0l0.binware.org/index.php/2010/05/10/installing-trac-with-mod_wsgi-using-virtualenv/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

