integrii
7/4/2014 - 3:13 AM

Codeigniter running with on Centos 6.4 via HHVM and FastCGI

Codeigniter running with on Centos 6.4 via HHVM and FastCGI

# Endpoint Apache Config
Listen 80
ServerName site.com

# Options for all directories
<Directory />
        Options FollowSymLinks
        AllowOverride All
</Directory>


<VirtualHost *:80>

        DocumentRoot /var/www/html


        # Hack configuration
        <FilesMatch \.php$>
                SetHandler hhvm-php-extension
        </FilesMatch>
        <FilesMatch \.hh$>
                SetHandler hhvm-hack-extension
        </FilesMatch>

        # Load fastCGI for HHVM backend connectivity
        #LoadModule fastcgi_module modules/mod_fastcgi.so
        #Action hhvm-php-extension / virtual
        Action hhvm-php-extension /hhvm virtual
        Action hhvm-hack-extension /hhvm virtual

        Alias /hhvm hhvm
        FastCgiExternalServer hhvm -host 127.0.0.1:9000 -pass-header Authorization -idle-timeout 300
</VirtualHost>
#!/bin/bash
yum install http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm -y
cd /etc/yum.repos.d
wget "http://www.hop5.in/yum/el6/hop5.repo"
yum install hhvm mod_fastcgi fcgi-devel httpd -y

echo "##########################################"
echo "1) Uncomment NameVirtualHost *:80 in /etc/httpd/conf/httpd.conf"
echo "2) Install all configuration files included with this gist:"
echo "3) hhvm -> /etc/init.d/hhvm"
echo "4) config.hdf -> /etc/hhvm/config.hdf"
echo "5) fastcgi.conf -> /etc/httpd/conf.d/fastcgi.conf"
echo "6) site.conf -> /etc/httpd/conf.d/site.conf"
#!/bin/bash
# Run this after installing configs:
chkconfig --add hhvm
chkconfig hhvm on
/etc/init.d/httpd restart
#!/bin/bash
# HHVM daemon
# chkconfig: 345 20 80
# description: HHVM daemon for fcgi connections
# processname: hhvm

DAEMON_PATH="/var/www/html"

DAEMON=hhvm
DAEMONOPTS="--mode server --user apache"

NAME=HHVM
DESC="HHVM for FastCGI"
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

case "$1" in
start)
        printf "%-50s" "Starting $NAME..."
        cd $DAEMON_PATH
        PID=`$DAEMON $DAEMONOPTS > /dev/null 2>&1 & echo $!`
        #echo "Saving PID" $PID " to " $PIDFILE
        if [ -z $PID ]; then
            printf "%s\n" "Fail"
        else
            echo $PID > $PIDFILE
            printf "%s\n" "Ok"
        fi
;;
status)
        printf "%-50s" "Checking $NAME..."
        if [ -f $PIDFILE ]; then
            PID=`cat $PIDFILE`
            if [ -z "`ps axf | grep ${PID} | grep -v grep`" ]; then
                printf "%s\n" "Process dead but pidfile exists"
            else
                echo "Running"
            fi
        else
            printf "%s\n" "Service not running"
        fi
;;
stop)
        printf "%-50s" "Stopping $NAME"
            PID=`cat $PIDFILE`
            cd $DAEMON_PATH
        if [ -f $PIDFILE ]; then
            kill -HUP $PID
            printf "%s\n" "Ok"
            rm -f $PIDFILE
        else
            printf "%s\n" "pidfile not found"
        fi
;;

restart)
        $0 stop
        $0 start
;;

*)
        echo "Usage: $0 {status|start|stop|restart}"
        exit 1
esac
# WARNING: this is a kludge:
## The User/Group for httpd need to be set before we can load mod_fastcgi,
## but /etc/httpd/conf.d/fastcgi.conf on RHEL gets loaded before
## /etc/httpd/conf/httpd.conf, so we need to set them here :(
## mod_fcgid does not have this bug,
## but it does not handle child PHP processes appropriately per
## http://serverfault.com/questions/303535/a-single-php-fastcgi-process-blocks-all-other-php-requests/305093#305093

User apache
Group apache

LoadModule fastcgi_module modules/mod_fastcgi.so

# dir for IPC socket files
FastCgiIpcDir /var/run/mod_fastcgi

# wrap all fastcgi script calls in suexec
FastCgiWrapper Off

# global FastCgiConfig can be overridden by FastCgiServer options in vhost config
FastCgiConfig -idle-timeout 20 -maxClassProcesses 1

# sample PHP config
# see /usr/share/doc/mod_fastcgi-2.4.6 for php-wrapper script
# don't forget to disable mod_php in /etc/httpd/conf.d/php.conf!
#
# to enable privilege separation, add a "SuexecUserGroup" directive
# and chown the php-wrapper script and parent directory accordingly
# see also http://www.brandonturner.net/blog/2009/07/fastcgi_with_php_opcode_cache/
#
#FastCgiServer /var/www/cgi-bin/php-wrapper
#AddHandler php-fastcgi .php
#Action php-fastcgi /cgi-bin/php-wrapper
#AddType application/x-httpd-php .php
#DirectoryIndex index.php
#
#<Location /cgi-bin/php-wrapper>
#    Order Deny,Allow
#    Deny from All
#    Allow from env=REDIRECT_STATUS
#    Options ExecCGI
#    SetHandler fastcgi-script
#</Location>
Server {
   Type=fastcgi
   Port=9000
   PathDebug = true
   FixPathInfo = true
}

VirtualHost {
  * {
    Pattern = .*
    }
}

StaticFile {
  FilesMatch {
    * {
      pattern = .*\.(dll|exe)
      headers {
        * = Content-Disposition: attachment
      }
    }
  }

  Extensions {
    css = text/css
    gif = image/gif
    html = text/html
    jpe = image/jpeg
    jpeg = image/jpeg
    jpg = image/jpeg
    png = image/png
    tif = image/tiff
    tiff = image/tiff
    txt = text/plain
  }
}

ErrorHandling {
    CallUserHandlerOnFatals = true
    NoInfiniteRecursionDetection = false
    ThrowBadTypeExceptions = false
    ThrowTooManyArguments = false
    WarnTooManyArguments = false
    ThrowMissingArguments = false
    ThrowInvalidArguments = false
    EnableHipHopErrors = true
    NoticeFrequency = 1    # 1 out of these many notices to log
    WarningFrequency = 1   # 1 out of these many warnings to log
    AssertActive = false
    AssertWarning = false
  }

Repo {
  Central {
    Path = /var/log/hhvm/.hhvm.hhbc
  }
}

Log {
  Level = Error
  AlwaysLogUnhandledExceptions = true
  RuntimeErrorReportingLevel = 8191
  UseLogFile = true
  UseSyslog = true
  File = /var/log/hhvm/error.log
  Access {
    * {
      File = /var/log/hhvm/access.log
      Format = %h %l %u % t \"%r\" %>s %b
    }
  }
}

MySQL {
  TypedResults = false
}