Edgewall Software

Version 2 (modified by JoakimReck <joakim.mn2m@…>, 7 years ago) ( diff )

Install Trac on Ubuntu proxied by Nginx

How to install and run a single hosted Trac project from https://trac.edgewall.org

This guide should apply for the following debian variations:

  • Debian 9
  • Ubuntu 16.04
  • Ubuntu 16.10
  • LinuxMint 18.1
  • LinuxMint 18.2

Here is a somewhat basic copy paste #!bash script for this, however, there will be some manual labor for you :P but a find+replace would help you a lot. Be aware you might run all of these commands with the sudo -H

important remember to replace the https://trac-hacks.org/svn/fullblogplugin/0.11 with latest verion

apt-get install subversion libapache2-mod-python pypy python python-babel trac python-pip -y
pip install --upgrade pip
pip install --upgrade Babel
pip install --upgrade Trac
pip install --upgrade pillow
pip install dnspython
pip install spambayes
pip install oauth2
pip install httplib2
pip install TracTags
pip install TracSpamFilter 
pip install TracVote
easy_install --always-unzip https://trac-hacks.org/svn/fullblogplugin/0.11
mkdir -p /var/www/trac/

trac-admin /var/www/trac initenv

Follow the trac-admin guide…

Now lets test the trac before we do more

tracd --port 8000 /var/www/trac
lynx localhost:8000/trac

Great it's working, then it's time to setup a admin user and password for the admin account. Bad luck if it doesn't as that is beyond this wiki and you'll need to go https://duckduckgo.com to find a solution :(

htpasswd -c /var/www/trac/.htpasswd adminusername
trac-admin /var/www/trac/ permission add adminusername TRAC_ADMIN

Replace adminusername with your desired username

Next we set the propper user and group permissions on the Trac folder to allow the Nginx/Apache/Trac server to access it

chown -R UserName:GroupName /var/www/trac/
chmod -R 775 /var/www/trac/

Preparation to Enable GIT source

To enable git source browsing via Admin we need another subfolder

mkdir -p /var/www/trac/git

Systemd startup script

In your /etc/systemd/system/ make this new file —>

nano /etc/systemd/system/tracd.service
[Unit]
Description=TrackD Daemon
After=network.target

[Service]
ExecStart=/usr/local/bin/tracd -p 3050 --protocol=http --basic-auth="*,/var/www/trac/.htpasswd,Restricted" -s /var/www/trac
Type=simple
User=UserName
Group=GroupName

[Install]
WantedBy=multi-user.target

Nginx configs

Now it's time to do the NginX configureations :)

First we have to make a reverse proxy to the Trac daemon we have made in Systemd startup script

In the /etc/nginx/nginx.conf we'll have to add a upstream for our reverse_proxy to Trac

  upstream live_trachosts_com {
        server  127.0.0.1:3050;
  }

Now make the site.conf file in your preferred location, which by default would be /etc/nginx/conf.d/ for other it would be in /etc/nginx/sites-available but we go whit the default
nano /etc/nginx/conf.d/site.conf

server {
  listen       123.123.123.123:80;
  server_name  trac.local;
  
  charset utf8;
  access_log  /var/log/nginx/trac.access.log;
  error_log  /var/log/nginx/trac.debug.log;

  location / {
    proxy_pass  http://live_trachosts_com;
    proxy_set_header Host $host;
  }
  
  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
      root   /usr/share/nginx/html;
  }

  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  location ~ /\.ht {
      deny  all;
  }
}

Apache

And since you properly anyway use apache :( well here is that piece of code :(

a2enmod python
nano /etc/apache2/sites-available/trac.conf
<VirtualHost 123.123.123.123:80>
 ServerName trac.local
 <Location />
  SetHandler mod_python
  PythonInterpreter main_interpreter
  PythonHandler trac.web.modpython_frontend
  PythonOption TracEnv /var/www/trac
  PythonOption TracEnvParentDir /var/www/trac
  PythonOption TracUriRoot /
  PythonOption TracEnv /var/www/trac
  # PythonOption TracEnvIndexTemplate /var/www/trac/templates/index-template.html
  PythonOption TracLocale en_US.UTF8
  PythonOption PYTHON_EGG_CACHE /tmp
  Order allow,deny
  Allow from all
 </Location>
 <Location /login>
  AuthType Basic
  AuthName "myproject"
  AuthUserFile /var/www/trac/.htpasswd
  Require valid-user
 </Location>
</VirtualHost>

To enable the trac site run a2ensite trac.conf

Find/Replace

The following paths is to be replaced with your preferences
/var/www/trac —> /full/path/to/trac
adminusername —> YourUserName to be used as the track admin
UserName —> The username for which trac daemon runs as ex. Your login UserName
GroupName —> The group name for which trac daemon runs as ex www-data
trac.local —> full.domain.tld
live_trachosts_com —> to what suits your needs
123.123.123.123 —> if you are running both NginX and Apache on port 80/443 you'll need to set the IP, but if you only runs Nginx or Apache you can delete the ip to listen on all address

Versions

In this tutorial I have used the following software versions

$ uname -a
Linux hostname 4.11.0-14-generic #20~16.04.1-Ubuntu SMP Wed Aug 9 09:06:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
$ tracd --version
tracd 1.2.2
$ nginx -v
nginx version: nginx/1.13.6

Which list

A complete HOWTO copy/paste guide to make Nginx running as "Front-end" of trac

Note: See TracWiki for help on using the wiki.