Fedora 25: Install Trac

This article will describe installing Trac which manages user with digest authentication.

1 Install Trac

Run the following command just once.

1.1 Install trac and mod_wsgi

Install trac and mod_wsgi.

$ sudo dnf install -y trac mod_wsgi

1.2 Open 80/tcp port

Open 80/tcp port for http.

$ sudo firewall-cmd --add-service=http --permanent
$ sudo firewall-cmd --reload

1.3 Enable SELinux httpd_unified

Make SELinux httpd_unified on. You also need to add httpd_sys_content_t to project directory.

$ sudo setsebool -P httpd_unified on

1.4 Create project root directory

Create project root directory which has project directories.

$ sudo mkdir /var/lib/trac
$ sudo mkdir /var/www/html/trac
$ sudo chown apache:apache /var/www/html/trac

2 Create project

Run the following command for each project.

2.1 Create project directory

Create project directory.

$ sudo trac-admin /var/lib/trac/test initenv test sqlite:db/trac.db
$ sudo trac-admin /var/lib/trac/test deploy /var/www/html/trac/test
$ sudo chown -R apache:apache /var/lib/trac/test
$ sudo chown -R apache:apache /var/www/html/trac/test
$ sudo chcon -R -t httpd_sys_content_t /var/lib/trac/test

2.2 Create user

Create admin user.

$ sudo htdigest -c /var/lib/trac/test/.htdigest "test" admin
Adding user admin in realm test
New password:
Re-type new password:
$ sudo trac-admin /var/lib/trac/test permission add admin TRAC_ADMIN

Create user. Run htdigest command without -c option.

$ sudo htdigest /var/lib/trac/test/.htdigest "test" hiroom2
Adding user hiroom2 in realm test
New password:
Re-type new password:

2.3 Create Apache2 conf

Create Apache2 conf for project.

$ sudo su -c '
cat <<EOF > /etc/httpd/conf.d/test.conf
WSGIScriptAlias /trac/test /var/www/html/trac/test/cgi-bin/trac.wsgi
<Location /trac/test>
  AuthType Digest
  AuthName "test"
  AuthUserFile /var/lib/trac/test/.htdigest
  Require valid-user
</Location>
EOF
'

Restart Apache2.

$ sudo systemctl restart httpd

3 Access to Trac

Access the following URL with browser.

http://<server>/trac/test

The dialog of digest authentication is displayed.

0001_Digest-Auth.png

Trac page is displayed.

0002_Trac.png

4 Script for installing Trac

The following script will install Trac automatically.

#!/bin/sh

install_trac()
{
  sudo dnf install -y trac mod_wsgi

  sudo firewall-cmd --add-service=http --permanent
  sudo firewall-cmd --reload

  sudo setsebool -P httpd_unified on

  sudo mkdir /var/lib/trac
  sudo mkdir /var/www/html/trac
  sudo chown apache:apache /var/www/html/trac
}

TMP=`mktemp -t linux-trac.sh.XXXXXX`
trap "rm $TMP* 2>/dev/null" 0
sudo dnf install -y expect

create_digest()
{
  filename=$1
  realm=$2
  username=$3
  password=$4
  options=

  if [ ! -f ${filename} ]; then
    options=-c
  fi

  cat <<EOF > ${TMP}
set timeout -1
spawn sudo htdigest ${options} ${filename} ${realm} ${username}
expect "New password: "
send "${password}\n"
expect "Re-type new password: "
send "${password}\n"
expect eof
EOF
  expect ${TMP}
}

ADMIN_PASSWORD="trac"
USER_PASSWORD="trac"

create_test_project()
{
  sudo trac-admin /var/lib/trac/test initenv test sqlite:db/trac.db
  sudo trac-admin /var/lib/trac/test deploy /var/www/html/trac/test
  sudo chown -R apache:apache /var/lib/trac/test
  sudo chown -R apache:apache /var/www/html/trac/test

  sudo chcon -R -t httpd_sys_content_t /var/lib/trac/test

  create_digest /var/lib/trac/test/.htdigest "test" admin ${ADMIN_PASSWORD}
  sudo trac-admin /var/lib/trac/test permission add admin TRAC_ADMIN
  create_digest /var/lib/trac/test/.htdigest "test" hiroom2 ${USER_PASSWORD}

  sudo su -c '
cat <<EOF > /etc/httpd/conf.d/test.conf
WSGIScriptAlias /trac/test /var/www/html/trac/test/cgi-bin/trac.wsgi
<Location /trac/test>
  AuthType Digest
  AuthName "test"
  AuthUserFile /var/lib/trac/test/.htdigest
  Require valid-user
</Location>
EOF
'
  sudo systemctl restart httpd
}

install_trac
create_test_project