diff --git a/interface/web/sites/form/web_vhost_domain.tform.php b/interface/web/sites/form/web_vhost_domain.tform.php index 09ed771e57ee461162c07c019f99c51b6a6c54eb..1ae118811a8b07882f9ddd1bfe6bed3b59d9de11 100644 --- a/interface/web/sites/form/web_vhost_domain.tform.php +++ b/interface/web/sites/form/web_vhost_domain.tform.php @@ -241,7 +241,7 @@ $form["tabs"]['domain'] = array ( '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'), + 'value' => array('no' => 'disabled_txt', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM'), 'searchable' => 2 ), 'fastcgi_php_version' => array ( diff --git a/interface/web/sites/templates/web_vhost_domain_edit.htm b/interface/web/sites/templates/web_vhost_domain_edit.htm index 9f22ebdd45d5c965d32fa53120bb591b73877c7f..7c9c72067802a670e3735fb5cf249918c2efd4d3 100644 --- a/interface/web/sites/templates/web_vhost_domain_edit.htm +++ b/interface/web/sites/templates/web_vhost_domain_edit.htm @@ -289,7 +289,7 @@ if(data.servertype == "nginx"){ var selected = jQuery('#php').val(); jQuery('.apache').hide(); - if(selected != "no" && selected != "php-fpm") { + if(selected != "no" && selected != "php-fpm" && selected != "hhvm") { jQuery('#php option[value="php-fpm"]').attr('selected', 'selected').val('php-fpm'); } jQuery('#php option[value="fast-cgi"]').hide(); diff --git a/server/conf/hhvm_starter.master b/server/conf/hhvm_starter.master new file mode 100644 index 0000000000000000000000000000000000000000..3320c4c165db060f9d384a7748c4206ca7f0257a --- /dev/null +++ b/server/conf/hhvm_starter.master @@ -0,0 +1,49 @@ +#!/bin/bash +# +# /etc/init.d/hhvm_{SYSTEM_USER} +# +### BEGIN INIT INFO +# Provides: hhvm_{SYSTEM_USER} +# Required-Start: $remote_fs $network +# Required-Stop: $remote_fs $network +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Description: Starts The HHVM FastCGI Daemon +### END INIT INFO +PATH=/sbin:/usr/sbin:/bin:/usr/bin +DESC="HHVM FastCGI Daemon" +NAME=hhvm + +do_start() +{ + {START} +} + +do_stop() +{ + {STOP} +} + +case "$1" in + start) + do_start + ;; + stop) + do_stop + ;; + restart|force-reload) + do_stop + case "$?" in + 0|1) + do_start + ;; + *) + ;; + esac + ;; + *) + exit 3 + ;; +esac + +: diff --git a/server/conf/vhost.conf.master b/server/conf/vhost.conf.master index e7305e48c5fa3a9516865f4a502d08df87495266..08320025b4fad2a02f54614b37d755d38ac5e198 100644 --- a/server/conf/vhost.conf.master +++ b/server/conf/vhost.conf.master @@ -20,7 +20,11 @@ <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 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> </tmpl_if> </tmpl_if> @@ -318,6 +322,25 @@ </IfModule> </tmpl_if> +<tmpl_if name='php' op='==' value='hhvm'> + <IfModule mod_fastcgi.c> + <Directory {tmpl_var name='document_root'}/cgi-bin> + <tmpl_if name='apache_version' op='>' value='2.2' format='version'> + Require all granted + <tmpl_else> + Order allow,deny + Allow from all + </tmpl_if> + </Directory> + <FilesMatch "\.php[345]?$"> + SetHandler php5-fcgi + </FilesMatch> + 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'} + 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 /tmp/hhvm.<tmpl_var name='system_user'>.sock -pass-header Authorization + </IfModule> +</tmpl_if> + <tmpl_if name="rewrite_enabled"> RewriteEngine on <tmpl_if name='seo_redirect_enabled'> diff --git a/server/plugins-available/apache2_plugin.inc.php b/server/plugins-available/apache2_plugin.inc.php index 5e3bf85e0fd44b7c9b6e65ba2d6efddc472cf25e..8af0500c4d24736b4b9bdd88d59da0de0832fcc9 100644 --- a/server/plugins-available/apache2_plugin.inc.php +++ b/server/plugins-available/apache2_plugin.inc.php @@ -104,7 +104,7 @@ class apache2_plugin { /* $data contains an array with these keys: * file -> full path of changed php_ini - * mode -> web_domain php modes to change (mod, fast-cgi, php-fpm or '' for all except 'mod') + * mode -> web_domain php modes to change (mod, fast-cgi, php-fpm, hhvm or '' for all except 'mod') * php_version -> php ini path that changed (additional php versions) */ @@ -121,6 +121,11 @@ class apache2_plugin { if($data['php_version']) { $qrystr .= " AND fastcgi_php_version LIKE '%:" . $app->db->quote($data['php_version']) . ":%'"; } + } elseif($data['mode'] == 'hhvm') { + $qrystr .= " AND php = 'hhvm'"; + if($data['php_version']) { + $qrystr .= " AND fastcgi_php_version LIKE '%:" . $app->db->quote($data['php_version']) . ":%'"; + } } else { $qrystr .= " AND php != 'mod' AND php != 'fast-cgi'"; } @@ -1318,7 +1323,7 @@ class apache2_plugin { * PHP-FPM */ // Support for multiple PHP versions - if($data['new']['php'] == 'php-fpm'){ + if($data['new']['php'] == 'php-fpm' || $data['new']['php'] == 'hhvm'){ if(trim($data['new']['fastcgi_php_version']) != ''){ $default_php_fpm = false; list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['new']['fastcgi_php_version'])); @@ -1327,7 +1332,7 @@ class apache2_plugin { $default_php_fpm = true; } } else { - if(trim($data['old']['fastcgi_php_version']) != '' && $data['old']['php'] == 'php-fpm'){ + if(trim($data['old']['fastcgi_php_version']) != '' && ($data['old']['php'] == 'php-fpm' || $data['old']['php'] == 'hhvm')){ $default_php_fpm = false; list($custom_php_fpm_name, $custom_php_fpm_init_script, $custom_php_fpm_ini_dir, $custom_php_fpm_pool_dir) = explode(':', trim($data['old']['fastcgi_php_version'])); if(substr($custom_php_fpm_ini_dir, -1) != '/') $custom_php_fpm_ini_dir .= '/'; @@ -1586,6 +1591,7 @@ class apache2_plugin { } $this->php_fpm_pool_update($data, $web_config, $pool_dir, $pool_name, $socket_dir); + $this->hhvm_update($data, $web_config); if($web_config['check_apache_config'] == 'y') { //* Test if apache starts with the new configuration file @@ -1933,6 +1939,8 @@ class apache2_plugin { // remove PHP-FPM pool if ($data['old']['php'] == 'php-fpm') { $this->php_fpm_pool_delete($data, $web_config); + } elseif($data['old']['php'] == 'hhvm') { + $this->hhvm_update($data, $web_config); } //remove the php cgi starter script if available @@ -2722,6 +2730,42 @@ class apache2_plugin { } } + private function hhvm_update($data, $web_config) { + global $app, $conf; + + if(file_exists($conf['rootpath'] . '/conf-custom/hhvm_starter.master')) { + $content = file_get_contents($conf['rootpath'] . '/conf-custom/hhvm_starter.master'); + } else { + $content = file_get_contents($conf['rootpath'] . '/conf/hhvm_starter.master'); + } + $start_content = ''; + $stop_content = ''; + + if($data['new']['php'] == 'hhvm' && $data['old']['php'] != 'hhvm') { + $start_content .= 'if [ ! -d /var/run/hhvm ]; then + mkdir -p -m0777 /var/run/hhvm + else + chmod 777 /var/run/hhvm + fi + umask 017 + sudo -u ' . $data['new']['system_user'] . ' touch /var/run/hhvm/hhvm_' . $data['new']['system_user'] . '.pid + /usr/bin/hhvm --mode daemon -vServer.Type=fastcgi --user ' . $data['new']['system_user'] . ' -vServer.FileSocket=/tmp/hhvm.' . $data['new']['system_user'] . '.sock -vLog.Level=Warning -vLog.UseLogFile=false -vRepo.Central.Path=/tmp/hhvm.' . $data['new']['system_user'] . '.hhbc -vPidFile=/var/run/hhvm/hhvm_' . $data['new']['system_user'] . '.pid & echo $! > /var/run/hhvm/hhvm_' . $data['new']['system_user'] . '.pid'; + + $stop_content .= 'if [[ -e "/var/run/hhvm/hhvm_' . $data['new']['system_user'] . '.pid" ]] ; then kill -SIGTERM `cat /var/run/hhvm/hhvm_' . $data['new']['system_user'] . '.pid` >/dev/null 2>&1 ; fi + rm -f /tmp/hhvm.' . $data['new']['system_user'] . '.sock /tmp/hhvm.' . $data['new']['system_user'] . '.hhbc /var/run/hhvm/hhvm_' . $data['new']['system_user'] . '.pid'; + + $content = str_replace(array('{START}', '{STOP}', '{SYSTEM_USER}'), array($start_content, $stop_content, $data['new']['system_user']), $content); + file_put_contents('/etc/init.d/hhvm_' . $data['new']['system_user'], $content); + exec('chmod +x /etc/init.d/hhvm_' . $data['new']['system_user'] . ' >/dev/null 2>&1'); + exec('/usr/sbin/update-rc.d hhvm_' . $data['new']['system_user'] . ' defaults >/dev/null 2>&1'); + exec('/etc/init.d/hhvm_' . $data['new']['system_user'] . ' start >/dev/null 2>&1'); + } elseif($data['new']['php'] != 'hhvm' && $data['old']['php'] == 'hhvm') { + exec('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' stop >/dev/null 2>&1'); + exec('/usr/sbin/update-rc.d hhvm_' . $data['old']['system_user'] . ' remove >/dev/null 2>&1'); + unlink('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' >/dev/null 2>&1'); + } + } + //* Update the PHP-FPM pool configuration file private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name, $socket_dir) { global $app, $conf;