= Trac과 mod_python =

Trac은 [http://www.modpython.org/ mod_python]을 지원합니다. [http://www.modpython.org/ mod_python]은 Trac의 응답속도를 굉장히 빠르게 하고, [wiki:TracStandalone tracd]/mod_proxy에서는 불가능한 아파치의 많은 기능들을 가능하게 합니다.

== 간단한 설정 ==

mod_python을 설치했다면, Apach 설정에서 모듈을 로드하기 위해서 다음 라인을 추가해야할지도 모릅니다.:
{{{
LoadModule python_module modules/mod_python.so
}}}

mod_python을 사용하기 위한 Trac의 간단한 설정은 다음과 같습니다.:
{{{
<Location /projects/myproject>
   SetHandler mod_python
   PythonHandler trac.web.modpython_frontend 
   PythonOption TracEnv /var/trac/myproject
   PythonOption TracUriRoot /projects/myproject
</Location>
}}}

`TracUriRoot` 옵션은 필요할 수도 있고 그렇지 않을 수도 있음을 주의하십시오.
먼저 이 옵션이 없는 상태에서 테스트하고, 만약 Trac에 의해서 제공되는 URL이 정상적이지 않거나, Trac이 URL을 정상적으로 인식하지 못하면 `TracUriRoot` 옵션을 추가하십시오.

인증에 관한 설정은 [wiki:TracCgi#AddingAuthentication CGI]에서와 동일합니다.:
{{{
<Location "/projects/myproject/login">
  AuthType Basic
  AuthName "myproject"
  AuthUserFile /var/trac/myproject/.htaccess
  Require valid-user
</Location>
}}}

만약 Trac이 Python 경로에 설치되지 않았다면, Apache에서 `PythonPath` 지시자를 사용해서 Trac의 mod_python 핸들러가 어디에 있는지를 설정해야합니다.:
{{{
<Location /projects/myproject>
  ...
  PythonPath "sys.path + ['/path/to/trac']"
  ...
</Location>
}}}


== 여러개의 프로젝트 설정하기 ==

Trac의 mod_python 핸들러는 Subversion의 `SvnParentPath` 옵션과 같은 역할을 하는 `TracEnvParentDir` 옵션을 지원합니다.:
{{{
<Location /projects>
  SetHandler mod_python
  PythonHandler trac.web.modpython_frontend 
  PythonOption TracEnvParentDir /var/trac
  PythonOption TracUriRoot /projects
</Location>
}}}

`/projects` URL을 요청하면, `TracEnvParentDir`로 설정한 디렉토리의 서브디렉토리들의 리스트를 볼 수 있을 것입니다. 리스트에서 프로젝트를 선택하면 해당 프로젝트의 Trac 페이지를 볼 수 있을 것입니다.

프로젝트 홈페이지에서 서브디렉토리의 리스트를 보기를 원하지 않는다면 다음과 같이 설정하삽시오.:
{{{
<LocationMatch "/.+/">
}}}

이렇게 설정하면 !DocumentRoot 디렉토리에 메인 페이지가 존재할 가능성이 있는 한은, 루트경로와는 다른 모든 경로에 대해서 mod_python을 사용하도록 할 것입니다.

`<LocationMatch>` 지시자를 사용하면 모든 프로젝트에 대해서 같은 인증방식을 사용할 수 있습니다.:
{{{
<LocationMatch "/[^/]+/login">
  AuthType Basic
  AuthName "Trac"
  AuthUserFile /var/trac/.htaccess
  Require valid-user
</LocationMatch>
}}}

== Virtual Host Configuration ==

Below is the sample configuration required to set up your trac as a virtual server (i.e. when you access it at the URLs like
!http://trac.mycompany.com):

{{{
<VirtualHost * >
    DocumentRoot /var/trac/myproject
    ServerName trac.mycompany.com
    <Directory />
        SetHandler mod_python
        PythonHandler trac.web.modpython_frontend
        PythonOption TracEnv /var/trac/myproject
        PythonOption TracUriRoot /
    </Directory>
    <Location /login>
        AuthType Basic
        AuthName "MyCompany Trac Server"
        AuthUserFile /var/trac/myproject/.htusers
        Require valid-user
    </Location>
</VirtualHost>
}}}

== 문제해결 ==

=== Form submission problems ===

If you're experiencing problems submitting some of the forms in Trac (a common problem is that you get redirected to the start page after submission), check whether your {{{DocumentRoot}}} contains a folder or file with the same path that you mapped the mod_python handler to. For some reason, mod_python gets confused when it is mapped to a location that also matches a static resource.

=== .htaccess 사용하기 ===

Although it may seem trivial to rewrite the above configuration as a directory in your document root with a `.htaccess` file, this does not work. Apache will append a "/" to any Trac URLs, which interferes with its correct operation.

It may be possible to work around this with mod_rewrite, but I failed to get this working. In all, it is more hassle than it is worth. Stick to the provided instructions. :)

=== Win32 Issues ===

If you run trac with mod_python (3.1.3 or 3.1.4) on Windows, 
uploading attachments will '''not''' work.
This is a known problem which we can't solve cleanly at the Trac level.

However, there is a workaround for this at the mod_python level, 
which is to apply the following patch [http://projects.edgewall.com/trac/attachment/ticket/554/util_py.patch attachment:ticket:554:util_py.patch] 
to the (Lib/site-packages)/modpython/util.py file.

If you don't have the `patch` command, that file can be replaced with the [http://svn.apache.org/viewcvs.cgi/httpd/mod_python/trunk/lib/python/mod_python/util.py?rev=103562&view=markup  fixed util.py] (fix which, although done prior to the 3.1.4 release, is ''not'' 
present in 3.1.4).

=== OS X에서의 문제점 ===

OS X에서 mod_python을 사용한다면, `apachectl restart` 명령을 사용해서 Apache를 재시작할 수 없을 것입니다. 이 문제는 외관상으로는 mod_python 3.2 버전에서 고쳐졌습니다. 이전 버전에서 사용할 수 있는 [http://www.dscpl.com.au/projects/vampire/patches.html 패치]도 존재합니다.

----
참고 : TracGuide, TracInstall, TracCgi, TracFastCgi
