In ScriptAlias /trac ... code block, use #!apache rather than #!sh
ScriptAlias /trac ...
#!apache
#!sh