Skip to content

Day 12 – Configuring Catalyst and Apache

May 30, 2013

Well, now that I’m satisfy with my code base, I’m going to enable access to my Catalyst application through Apache server.

First thing I realize is that it uses FastCGI instead of mod_perl, the problem is that it doesn’t comes by default with Apache, then, need to install it.

  1. Install required packages
    • yum install libtool httpd-devel apr-devel apr
  2. Download and uncompress source code from http://www.fastcgi.com/dist/mod_fastcgi-2.4.6.tar.gz
  3. Compile
    1. cd <mod_fastcgi_dir>
    2. cp Makefile.AP2 Makefile
      • As my Apache directory is different to /usr/local/apache2 I change it on Makefile
      • top_dir = /usr/lib/httpd
    3. make
      1. If “build/special.mk: No such file or directory” error appears, install httpd-devel
    4. sudo make install
    5. Add an entry to httpd.conf like this:

      • <IfModule !mod_fastcgi.c>
        LoadModule fastcgi_module modules/mod_fastcgi.soUser web
        Group apache
        FastCgiIpcDir /tmp/fcgi_ipc/
        AddHandler fastcgi-script .fcgi
        </IfModule>
    6. FastCGI creates temporal files and in the configuration we said that directory is /tmp/fcgi_ipc/ in order to avoid “Permission denied: FastCGI: can’t create (dynamic) server” error, you have to assign full permissions:
      1. mkdir /tmp/fcgi_ipc
      2. sudo 777 /tmp/fcgi_ipc
      3. mkdir /tmp/fcgi_ipc/dynamic
      4. sudo 777 /tmp/fcgi_ipc/dynamic
    7. Configure your app on httpd.conf
      1. #
        ################################################
        # Perl Catalyst
        # Allow CGI script to run
        <Directory /system/path/to/yourapp>
        Options +ExecCGI
        </Directory># Tell Apache this is a FastCGI application
        <Files yourapp_fastcgi.pl>
        SetHandler fastcgi-script
        </Files>

        RewriteCond %{HTTP:Authorization} ^(.+)
        RewriteRule ^(.*)$ $1 [E=HTTP_AUTHORIZATION:%1,PT]

        # Serve static content directly
        Alias /static /system/path/to/yourapp/root/static

        # In case you want your app be server on the root of the address, if not, assign other alias
        Alias /          /system/path/to/yourapp/script/yourapp_fastcgi.pl/

    8. Restart Apache
    9. If you can’t see the Catalyst welcome page, check Apache’s error log and fix the reported error.

And that’s all (Actually I had to re-install Catalyst modules as root because my local installation were not reached by the Apache account)


.

Leave a Comment

Leave a comment