[Catalyst] apache2 fastcgi
Mike Raynham
catalyst at mikeraynham.co.uk
Sun Mar 13 15:02:40 GMT 2011
On 13/03/11 12:54, shawn wilson wrote:
> i'm trying to deploy a project on apache2. first, i tried by hand with
> this config:
>
> <VirtualHost *:80>
> DocumentRoot /var/www/Shell/root
> Alias /static /var/www/Shell/root
> ErrorLog /var/log/apache2/error.log
> <Location /static>
> SetHandler default-handler
> </Location>
> Alias / /var/www/Shell/script/shell_fastcgi.pl/
> <http://shell_fastcgi.pl/>
> <Location />
> Options ExecCGI
> Order allow,deny
> Allow from all
> AddHandler fcgid-script .pl
> </Location>
> </VirtualHost>
>
> and i get this in my error log:
>
> [Sun Mar 13 08:40:46 2011] [error] [client 192.168.15.117] File does not
> exist: /var/www/Shell/script/shell_fastcgi.pl/main
> <http://shell_fastcgi.pl/main>
>
> then, i tried this, pretty much verbatim from Catalyst::Engine::FastCGI pod:
>
> <VirtualHost *:80>
> DocumentRoot /var/www/Shell
> ErrorLog /var/log/apache2/error.log
> <Directory /var/www/Shell>
> Options +ExecCGI
> </Directory>
> <Files shell_fastcgi.pl <http://shell_fastcgi.pl>>
> SetHandler fastcgi-script
> </Files>
> </VirtualHost>
>
> and i get this in my error log:
>
> [Sun Mar 13 08:48:37 2011] [error] [client 192.168.15.117] client denied
> by server configuration: /var/www/Shell/main
>
> i'm pretty sure that the second config is wrong (as there's no main in
> the root there and it's not running the fastcgi script) however the
> former config looks like it almost should work? btw, i haven't modified
> the fastcgi.pl <http://fastcgi.pl> script from the default that catalyst
> created for me.
>
>
>
> _______________________________________________
> List: Catalyst at lists.scsys.co.uk
> Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
> Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
> Dev site: http://dev.catalyst.perl.org/
I moved over to Nginx a while ago, and when I used Apache, I created the
Catalyst app as an external process, rather than a static process.
However, I've just tweaked on of my old Apache virtual host files so
that it creates the app as a static process:
---
<VirtualHost *:80>
ServerName www.example.com
ServerAdmin hostmaster at example.com
DocumentRoot /var/www/example.com/public_html/root
<Location />
Order allow,deny
Allow from all
</Location>
# Allow Apache to serve static content.
Alias /static /var/www/example.com/public_html/root/static
<Location /static>
SetHandler default-handler
ExpiresDefault "modification plus 1 year"
</Location>
FastCgiServer
/var/www/example.com/public_html/script/example_fastcgi.pl -processes 3
Alias / /var/www/example.com/public_html/script/example_fastcgi.pl/
LogLevel debug
ErrorLog /var/www/example.com/logs/error_log
CustomLog /var/www/example.com/logs/access.log combined
</VirtualHost>
---
You can find more information about the different FastCGI application
types here:
http://www.fastcgi.com/mod_fastcgi/docs/mod_fastcgi.html
The Catalyst Advent Calendar also contains an article about FastCGI
deployment:
http://www.catalystframework.org/calendar/2006/16
The example in the Advent Calendar runs the app as an external process.
Here's a copy of one of my old external Apache Virtual Host files:
---
<VirtualHost *:80>
ServerName www.example.com
ServerAdmin hostmaster at example.com
DocumentRoot /var/www/example.com/public_html/root
<Location />
Order allow,deny
Allow from all
</Location>
# Allow Apache to serve static content.
Alias /static /var/www/example.com/public_html/root/static
<Location /static>
SetHandler default-handler
ExpiresDefault "modification plus 1 year"
</Location>
# Display friendly error page if the FastCGI process is not running.
Alias /_errors /var/www/example.com/public_html/root/error-pages
ErrorDocument 500 /_errors/500.htm
# Connect to the external server.
FastCgiExternalServer /var/run/example.fcgi -socket
/var/run/example.socket
Alias / /var/run/example.fcgi/
LogLevel debug
ErrorLog /var/www/example.com/logs/error_log
CustomLog /var/www/example.com/logs/access.log combined
</VirtualHost>
---
To start the app as an external process (or 3), you need something like
this:
/var/www/example.com/public_html/script/example_fastcgi.pl -n 3 -l
/var/run/example.socket -p /var/run/example.pid -d -e
Alternatively, you can manage it with a suitable script. Here's an
Ubuntu init script that uses start-stop-daemon:
---
#!/bin/sh -e
# Start a Catalyst Example application under FastCGI
#
# Set the following variables:
APPNAME=example
APPDIR=/var/www/example.com/public_html
PROCS=1
# Do not alter the following variables:
UNIXNAME=$(echo $APPNAME | perl -pe 's/::/_/;$_=lc')
DAEMON=$APPDIR/script/${UNIXNAME}_fastcgi.pl
# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions
# Check if the PIDDIR directory exists.
if [ -d /var/run ] ; then
PIDDIR=/var/run
elif [ -d /tmp ] ; then
PIDDIR=/tmp
else
log_daemon_msg "Could not find suitable PID directory."
exit 0
fi
# Check if the FastCGI script exists.
if [ ! -r $DAEMON ] ; then
log_daemon_msg "Could not find FastCGI script for '$DAEMON'"
exit 0
fi
# Set location for PID and socket files.
PIDFILE=$PIDDIR/${UNIXNAME}.pid
SOCKET=$PIDDIR/${UNIXNAME}.socket
DAEMON_ARGS="-n $PROCS -l $SOCKET -p $PIDFILE -d -e"
running() {
[ -s $PIDFILE ] && \
[ -S $SOCKET ] && \
kill -0 `cat $PIDFILE` 2>/dev/null 2>&1
}
start() {
if running ; then
PID=`cat $PIDFILE`
log_daemon_msg "$APPNAME already started (pid $PID)"
return 0
fi
log_daemon_msg "Attempting to start $APPNAME..."
# Remove any existing PID or socket files.
rm -f $PIDFILE 2>/dev/null
rm -f $SOCKET 2>/dev/null
# Use start-stop-daemon to start the FastCGI process in the
background.
start-stop-daemon \
--start \
--quiet \
--pidfile $PIDFILE \
--chdir $APPDIR \
--startas $DAEMON -- $DAEMON_ARGS
log_end_msg $?
return $?
}
stop() {
if running ; then
log_daemon_msg "Attempting to stop $APPNAME..."
else
log_daemon_msg "$APPNAME is not running."
return 0
fi
# Use start-stop-daemon to stop the FastCGI process.
start-stop-daemon \
--stop \
--quiet \
--pidfile $PIDFILE \
--retry TERM/5/TERM/30/KILL/30
RETVAL=$?
# Remove any remaining PID or socket files.
rm -f $PIDFILE 2>/dev/null
rm -f $SOCKET 2>/dev/null
log_end_msg $RETVAL
return $RETVAL
}
status() {
status_of_proc -p $PIDFILE $DAEMON $APPNAME && exit 0 || exit $?
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
start
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $?
More information about the Catalyst
mailing list