29 mars 2024

Installer HHVM dans ispconfig 3.0.5.3 sur ubuntu 12.04

Adding HHVM support for ISPConfig 3.0.5.3 on Ubuntu 12.04

This is a workaround for adding HHVM support for ISPConfig, any update to ISPConfig will remove these changes and might break the installation.This workaround is tested but is NOT guaranted to work, so please try it locally before applying to your server.Before proceeding, if you do not have ISPConfig install it as described here : http://www.howtoforge.com/perfect-server-ubuntu-12.04-lts-apache2-bind-dovecot-ispconfig-31 – Checking/installinig PHP5-FPM

1st of all check that PHP5-FPM and suexec are installed on your server, if not you can do this AFTER installing ISPConfig

apt-get install apache2-mpm-worker apache2-suexec php5-cgi libapache2-mod-fcgid 
a2enmod fcgid
a2enmod suexec

 

2 – Install HHVM

sudo add-apt-repository ppa:mapnik/boost
wget -O – http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
echo deb http://dl.hhvm.com/ubuntu precise main | sudo tee /etc/apt/sources.list.d/hhvm.list
sudo apt-get update
sudo apt-get install hhvm

 

 

3 – ISPConfig Modifications

in /interface/web/sites/form/web_domain.tform.php

Add :

'hhvm' => 'HHVM Over PHP-FPM'

In the ‘value’ sub-array of this block :

      'php' => array (
            'datatype'    => 'VARCHAR',
            'formtype'    => 'SELECT',
            'default'    => 'fast-cgi',
            'valuelimit' => 'client:web_php_options',
            'value'        => array('no' => 'disabled_txt', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM'),
            'searchable' => 2
        )

so the line will look like :

'value'        => array('no' => 'disabled_txt', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM Over PHP-FPM'),

 

4 – in /server/conf/vhost.conf.master

 

after :

after <tmpl_if name='php' op='==' value='php-fpm'> <IfModule mod_fastcgi.c>

Add :

<tmpl_if name='php' op='==' value='hhvm'>
    <IfModule mod_fastcgi.c>
        <Directory {tmpl_var name='document_root'}/cgi-bin>
            Order allow,deny
            Allow from all
        </Directory>
                AddHandler php5-fcgi .php
                Action php5-fcgi /php5-fcgi
        Alias /php5-fcgi {tmpl_var name='document_root'}/cgi-bin/php5-fcgi-{tmpl_var name='ip_address'}-{tmpl_var name='port'}-{tmpl_var name='domain'}

        <tmpl_if name='use_tcp'>
                    FastCgiExternalServer {tmpl_var name='document_root'}/cgi-bin/php5-fcgi-{tmpl_var name='ip_address'}-{tmpl_var name='port'}-{tmpl_var name='domain'} -idle-timeout 300 -host 127.0.0.1:<tmpl_var name='hhvm_port'> -pass-header Authorization
        </tmpl_if>
        <tmpl_if name='use_socket'>
                    FastCgiExternalServer {tmpl_var name='document_root'}/cgi-bin/php5-fcgi-{tmpl_var name='ip_address'}-{tmpl_var name='port'}-{tmpl_var name='domain'} -idle-timeout 300 -socket <tmpl_var name='hhvm_socket'> -pass-header Authorization
        </tmpl_if>
    </IfModule>
</tmpl_if>

 

Change this :

<tmpl_if name='php' op='==' value='php-fpm'>
    DocumentRoot <tmpl_var name='web_document_root'>
</tmpl_else>
    DocumentRoot <tmpl_var name='web_document_root_www'>
</tmpl_if>

into this :

<tmpl_if name='php' op='==' value='php-fpm'>
    DocumentRoot <tmpl_var name='web_document_root'>
</tmpl_else>
    <tmpl_if name='php' op='==' value='hhvm'>
        DocumentRoot <tmpl_var name='web_document_root'>
    </tmpl_else>
        DocumentRoot <tmpl_var name='web_document_root_www'>
    </tmpl_if>
</tmpl_if>

 

5 –  server/plugins-avaialble/apache2_plugin.inc.php

 

add this method inside the class :

function hhvm_upstart($web_config){
    global $app,$conf;
    // create upstart script

        //clear service_pool in mysql

        $script_content = '#!/bin/bash
mysql –user="'.$conf['db_user'].’” –password=”‘.$conf['db_password'].’” –database=”‘.$conf['db_database'].'" –execute="DELETE FROM service_pool"'."nn";

        $upstart_services = $app->db->queryAllRecords("SELECT * FROM web_domain WHERE type='vhost' and php = 'hhvm'");
        file_put_contents('/tmp/isp/t.txt', print_r($upstart_services,true));
        if(is_array($upstart_services) && !empty($upstart_services)){
            foreach ($upstart_services as $service){
                $script_content .= 'cd '.$service['document_root']."n";

                $port = '2' . ($web_config['php_fpm_start_port'] + $service['domain_id'] – 1); // get the hhvm port
                $script_content .= 'hhvm –mode server -vServer.Type=fastcgi -vServer.Port=' . $port . ' > /dev/null 2>&1 & PID=$!; '."n";
                $script_content .= 'mysql –user="'.$conf['db_user'].’” –password=”‘.$conf['db_password'].’” –database=”‘.$conf['db_database'].’” –execute=”INSERT INTO service_pool (service_type,server_id,service_pid) VALUES (’hhvm’ ,”.$service['domain_id'].'', '$PID')"'."n";

            }
        }

        file_put_contents('/etc/init.d/hhvm_ispconfig.sh', $script_content);
        exec('chmod +x /etc/init.d/hhvm_ispconfig.sh');
        exec('update-rc.d hhvm_ispconfig.sh defaults');
}

 

add this line to the end of update() method :

$this->hhvm_upstart($web_config);

 

 

After :

$fpm_socket = $socket_dir.$pool_name.'.sock';
$tpl->setVar('fpm_socket', $fpm_socket);
$tpl->setVar('fpm_port', $web_config['php_fpm_start_port'] + $data['new']['domain_id'] – 1);

Add :

$hhvm_socket = $socket_dir.$pool_name.'.hhvm.sock';
$tpl->setVar('hhvm_socket', $hhvm_socket);
$tpl->setVar('hhvm_port', '2' . ($web_config['php_fpm_start_port'] + $data['new']['domain_id'] – 1));

 

 

Replace :

if($data['new']['php'] == 'php-fpm'){

With :

if($data['new']['php'] == ‘php-fpm’ || $data['new']['php'] == 'hhvm'){

 

 

Replace :

if(trim($data['old']['fastcgi_php_version']) != ” && $data['old']['php'] == 'php-fpm'){

With :

if(trim($data['old']['fastcgi_php_version']) != ” && ($data['old']['php'] == ‘php-fpm’  || $data['new']['php'] == 'hhvm')){

 

Replace :

if(trim($data['old']['fastcgi_php_version']) != ” && $data['old']['php'] == 'php-fpm'){

With :

if(trim($data['old']['fastcgi_php_version']) != ” && ($data['old']['php'] == ‘php-fpm’  || $data['new']['php'] == 'hhvm')){

 

in the end of method « php_fpm_pool_update » add :

    //Remove all hhvm instances
    $old_services = $app->db->queryAllRecords("SELECT * FROM service_pool WHERE service_type = 'hhvm' AND server_id = '".$data['new']['domain_id']."'");
    if(is_array($old_services) && !empty($old_services)){
        foreach ($old_services as $old_service){
        exec("kill -9 ".$old_service['service_pid']);
        }
    }
    $app->db->query("DELETE FROM service_pool WHERE service_type = 'hhvm' AND server_id = '".$data['new']['domain_id']."'");
    $tmpCurDir = __DIR__; // store the current cirectory
    chdir($data['new']['document_root']); // change to the document root as HHVM needs to be run from there
    // start a fresh hhvm instance
    $port = '2' . ($web_config['php_fpm_start_port'] + $data['new']['domain_id'] – 1); // get the hhvm port
    $command =  'hhvm –mode server -vServer.Type=fastcgi -vServer.Port=' . $port . ' > /dev/null 2>&1 & echo $!; ';
    $pid = exec($command, $output);
    $app->db->query("INSERT INTO service_pool (service_type,server_id,service_pid) VALUES ('hhvm' ,'".$data['new']['domain_id']."', '".$pid."')");

 

6 – in /interface/web/sites/templates/web_domain_edit.htm

 

Replace :

if(jQuery('#php').val() == 'fast-cgi' || jQuery('#php').val() == 'php-fpm'){

With :

if(jQuery('#php').val() == 'fast-cgi' || jQuery('#php').val() == 'php-fpm' || jQuery('#php').val() == 'hhvm'){

 

Replace :

if(jQuery(this).val() == 'fast-cgi' || jQuery(this).val() == 'php-fpm'){

With :

if(jQuery(this).val() == 'fast-cgi' || jQuery(this).val() == 'php-fpm' || jQuery(this).val() == 'hhvm'){

 

7 – Create the following table in the ISPConfig database :

CREATE TABLE IF NOT EXISTS `service_pool` (
  `service_id` int(11) NOT NULL AUTO_INCREMENT,
  `service_type` varchar(32) NOT NULL,
  `service_pid` int(11) NOT NULL,
  `server_id` int(11) NOT NULL,
  PRIMARY KEY (`service_id`),
  KEY `service_type` (`service_type`),
  KEY `server_id` (`server_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

 

Hopy this will help you out guys ! Enjoy !

 

sources : http://blog.noczone.com/?p=102

Laisser un commentaire