Changes between Version 27 and Version 28 of TracModWSGI
- Timestamp:
- Feb 2, 2011, 7:01:19 PM (13 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracModWSGI
v27 v28 3 3 '''Important note:''' ''Please use either version 1.6, 2.4 or later of `mod_wsgi`. Versions prior to 2.4 in the 2.X branch have problems with some Apache configurations that use WSGI file wrapper extension. This extension is used in Trac to serve up attachments and static media files such as style sheets. If you are affected by this problem attachments will appear to be empty and formatting of HTML pages will appear not to work due to style sheet files not loading properly. See mod_wsgi tickets [http://code.google.com/p/modwsgi/issues/detail?id=100 #100] and [http://code.google.com/p/modwsgi/issues/detail?id=132 #132].'' 4 4 5 [http://code.google.com/p/modwsgi/ mod_wsgi] is an Apache module for running WSGI-compatible Python applications directly on top of Apache. The mod_wsgi adapter is written completely in C and provides significantly better performance than usingexisting WSGI adapters for mod_python or CGI.5 [http://code.google.com/p/modwsgi/ mod_wsgi] is an Apache module for running WSGI-compatible Python applications directly on top of the Apache webserver. The mod_wsgi adapter is written completely in C and provides significantly better performance compared to existing WSGI adapters for mod_python or CGI. 6 6 7 Trac can be run on top of mod_wsgi with the help of the following application script, which is just a Python file, though usually saved with a .wsgi extension). This file can be created using '''trac-admin <env> deploy <dir>''' command which automatically substitutesrequired paths.7 Trac can be run on top of mod_wsgi with the help of the following application script, which is just a Python file, though usually saved with a `.wsgi` extension). This file can be created using the '''trac-admin <env> deploy <dir>''' command which automatically substitutes the required paths. 8 8 9 9 {{{ … … 34 34 }}} 35 35 36 For clarity, you should give this file a `.wsgi` extension. You should probably put the file in it's own directory, since you will open up its directory to Apache. You can create a .wsgi fileswhich handles all this for you by running the TracAdmin command `deploy`.36 For clarity, you should give this file a `.wsgi` extension. You should probably put the file in it's own directory, since you will expose its directory to Apache. You can create a .wsgi file which handles all this for you by running the TracAdmin command `deploy`. 37 37 38 If you have installed trac and eggs in a path different from the standard one you should add that path by adding the following code ontop of the wsgi script:38 If you have installed Trac and eggs in a path different from the standard one you should add that path by adding the following code at the top of the wsgi script: 39 39 40 40 {{{ … … 44 44 }}} 45 45 46 Change it according to the path you installed the trac libs at.46 Change it according to the path you installed the Trac libs at. 47 47 48 After you've done preparing your wsgi-script, add the following to your httpd.conf.48 After you've done preparing your wsgi-script, add the following to your Apache configuration file (`httpd.conf` for example). 49 49 50 50 {{{ … … 58 58 }}} 59 59 60 Here, the script is in a subdirectory of the Trac environment. In order to let Apache run the script, access to the directory in which the script resides is opened up to all of Apache. Additionally, the {{{WSGIApplicationGroup}}} directive ensures that Trac is always run in the first Python interpreter created by mod_wsgi; this is necessary because the Subversion Python bindings, which are used by Trac, don't always work in other sub interpreters and may cause requests to hang or cause Apache to crash as a result. After adding this configuration, restart Apache, and then it should work.60 Here, the script is in a subdirectory of the Trac environment. In order to let Apache run the script, access to the directory in which the script resides is opened up to all of Apache. Additionally, the {{{WSGIApplicationGroup}}} directive ensures that Trac is always run in the first Python interpreter created by mod_wsgi; this is necessary because the Subversion Python bindings, which are used by Trac, don't always work in other sub-interpreters and may cause requests to hang or cause Apache to crash as a result. After adding this configuration, restart Apache, and then it should work. 61 61 62 To test the setup of Apache, mod_wsgi and Python itself (ie. without involving Trac and dependencies), this simple wsgi application can be used to make sure that requests gets served (use as only content in your .wsgiscript):62 To test the setup of Apache, mod_wsgi and Python itself (ie. without involving Trac and dependencies), this simple wsgi application can be used to make sure that requests gets served (use as only content in your `.wsgi` script): 63 63 64 64 {{{ … … 76 76 == Apache Basic Authentication for Trac thru mod_wsgi == 77 77 78 Per the mod_wsgi documentation linked to above, here is an example Apache configuration that a) serves the tracfrom a virtualhost subdomain and b) uses Apache basic authentication for Trac authentication.78 Per the mod_wsgi documentation linked to above, here is an example Apache configuration that a) serves the Trac instance from a virtualhost subdomain and b) uses Apache basic authentication for Trac authentication. 79 79 80 80 81 If you want your trac to be served from e.g. !http://trac.my-proj.my-site.org, then from the folder e.g. {{{/home/trac-for-my-proj}}}, if you used the command {{{trac-admin the-env initenv}}} to create a folder {{{the-env}}}, and you used {{{trac-admin the-env deploy the-deploy}}} to create a folder {{{the-deploy}}}, then:81 If you want your Trac to be served from e.g. !http://trac.my-proj.my-site.org, then from the folder e.g. {{{/home/trac-for-my-proj}}}, if you used the command {{{trac-admin the-env initenv}}} to create a folder {{{the-env}}}, and you used {{{trac-admin the-env deploy the-deploy}}} to create a folder {{{the-deploy}}}, then first: 82 82 83 create the htpasswd file:83 Create the htpasswd file: 84 84 {{{ 85 85 cd /home/trac-for-my-proj/the-env … … 88 88 htpasswd htpasswd seconduser 89 89 }}} 90 ( for security keep the file above your document root)90 (keep the file above your document root for security reasons) 91 91 92 create this file e.g. (ubuntu) {{{/etc/apache2/sites-enabled/trac.my-proj.my-site.org.conf}}} with thesecontents:92 Create this file e.g. (ubuntu) {{{/etc/apache2/sites-enabled/trac.my-proj.my-site.org.conf}}} with the following contents: 93 93 94 94 {{{ … … 113 113 }}} 114 114 115 116 (for subdomains to work you would probably also need to alter /etc/hosts and add A-Records to your host's DNS.) 115 Note: for subdomains to work you would probably also need to alter `/etc/hosts` and add A-Records to your host's DNS. 117 116 118 117 == Trac with PostgreSQL == 119 118 120 When using the mod_wsgi adapter with multiple Trac instances and PostgreSQL (or MySQL?) as a database back-end the server can geta lot of open database connections. (and thus PostgreSQL processes)119 When using the mod_wsgi adapter with multiple Trac instances and PostgreSQL (or MySQL?) as a database back-end, the server can create a lot of open database connections. (and thus PostgreSQL processes) 121 120 122 A workable solution is to disabled connection pooling in Trac. This is done by setting poolable = False in trac.db.postgres_backend on the PostgreSQLConnectionclass.121 A workable solution is to disabled connection pooling in Trac. This is done by setting `poolable = False` in `trac.db.postgres_backend` on the `PostgreSQLConnection` class. 123 122 124 But it's not necessary to edit the source of trac, the following lines in trac.wsgiwill also work:123 But it's not necessary to edit the source of Trac, the following lines in `trac.wsgi` will also work: 125 124 126 125 {{{