Skip to content

Commit 1c6da35

Browse files
author
Marius Cramer
committed
Implemented: FS#3266 - HHVM PHP mode support (some improvements, nginx support)
1 parent c596328 commit 1c6da35

File tree

8 files changed

+55
-21
lines changed

8 files changed

+55
-21
lines changed

interface/web/client/form/client.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@
823823
'default' => '',
824824
'separator' => ',',
825825
'valuelimit' => 'client:web_php_options',
826-
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM')
826+
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM')
827827
),
828828
'limit_cgi' => array (
829829
'datatype' => 'VARCHAR',

interface/web/client/form/client_template.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@
345345
'default' => '',
346346
'separator' => ',',
347347
'valuelimit' => 'client:web_php_options',
348-
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM')
348+
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM')
349349
),
350350
'limit_cgi' => array (
351351
'datatype' => 'VARCHAR',

interface/web/client/form/reseller.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,7 @@
818818
),
819819
'default' => '',
820820
'separator' => ',',
821-
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM')
821+
'value' => array('no' => 'Disabled', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM')
822822
),
823823
'limit_cgi' => array (
824824
'datatype' => 'VARCHAR',

server/conf/hhvm_starter.master

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,22 @@ NAME=hhvm
1616

1717
do_start()
1818
{
19-
{START}
19+
if [ ! -d /var/run/hhvm ]; then
20+
mkdir -p -m0777 /var/run/hhvm
21+
else
22+
chmod 777 /var/run/hhvm
23+
fi
24+
umask 017
25+
sudo -u {SYSTEM_USER} touch /var/run/hhvm/hhvm_{SYSTEM_USER}.pid
26+
/usr/bin/hhvm --mode daemon -vServer.Type=fastcgi --user {SYSTEM_USER} -vServer.FileSocket=/var/run/hhvm/hhvm.{SYSTEM_USER}.sock -vLog.Level=Warning -vLog.UseLogFile=false -vRepo.Central.Path=/var/run/hhvm/hhvm.{SYSTEM_USER}.hhbc -vPidFile=/var/run/hhvm/hhvm_{SYSTEM_USER}.pid & echo $! > /var/run/hhvm/hhvm_{SYSTEM_USER}.pid
2027
}
2128

2229
do_stop()
2330
{
24-
{STOP}
31+
if [[ -e "/var/run/hhvm/hhvm_{SYSTEM_USER}.pid" ]] ; then
32+
kill -SIGTERM `cat /var/run/hhvm/hhvm_{SYSTEM_USER}.pid` >/dev/null 2>&1 ;
33+
fi
34+
rm -f /var/run/hhvm/hhvm.{SYSTEM_USER}.sock /var/run/hhvm/hhvm.{SYSTEM_USER}.hhbc /var/run/hhvm/hhvm_{SYSTEM_USER}.pid
2535
}
2636

2737
case "$1" in

server/conf/nginx_vhost.conf.master

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,22 @@ server {
152152
fastcgi_intercept_errors on;
153153
}
154154
</tmpl_else>
155+
<tmpl_if name='php' op='==' value='hhvm'>
156+
location @php {
157+
try_files $uri =404;
158+
include /etc/nginx/fastcgi_params;
159+
fastcgi_pass unix:/var/run/hhvm/hhvm.<tmpl_var name='system_user'>.sock;
160+
fastcgi_index index.php;
161+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
162+
#fastcgi_param PATH_INFO $fastcgi_script_name;
163+
fastcgi_intercept_errors on;
164+
}
165+
</tmpl_else>
166+
155167
location @php {
156168
deny all;
157169
}
170+
</tmpl_if>
158171
</tmpl_if>
159172

160173
<tmpl_if name='cgi' op='==' value='y'>

server/conf/vhost.conf.master

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@
337337
</FilesMatch>
338338
Action php5-fcgi /php5-fcgi
339339
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'}
340-
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
340+
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 /var/run/hhvm/hhvm.<tmpl_var name='system_user'>.sock -pass-header Authorization
341341
</IfModule>
342342
</tmpl_if>
343343

server/plugins-available/apache2_plugin.inc.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,23 +2738,9 @@ private function hhvm_update($data, $web_config) {
27382738
} else {
27392739
$content = file_get_contents($conf['rootpath'] . '/conf/hhvm_starter.master');
27402740
}
2741-
$start_content = '';
2742-
$stop_content = '';
27432741

27442742
if($data['new']['php'] == 'hhvm' && $data['old']['php'] != 'hhvm') {
2745-
$start_content .= 'if [ ! -d /var/run/hhvm ]; then
2746-
mkdir -p -m0777 /var/run/hhvm
2747-
else
2748-
chmod 777 /var/run/hhvm
2749-
fi
2750-
umask 017
2751-
sudo -u ' . $data['new']['system_user'] . ' touch /var/run/hhvm/hhvm_' . $data['new']['system_user'] . '.pid
2752-
/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';
2753-
2754-
$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
2755-
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';
2756-
2757-
$content = str_replace(array('{START}', '{STOP}', '{SYSTEM_USER}'), array($start_content, $stop_content, $data['new']['system_user']), $content);
2743+
$content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $content);
27582744
file_put_contents('/etc/init.d/hhvm_' . $data['new']['system_user'], $content);
27592745
exec('chmod +x /etc/init.d/hhvm_' . $data['new']['system_user'] . ' >/dev/null 2>&1');
27602746
exec('/usr/sbin/update-rc.d hhvm_' . $data['new']['system_user'] . ' defaults >/dev/null 2>&1');

server/plugins-available/nginx_plugin.inc.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,7 @@ function update($event_name, $data) {
16441644
}
16451645

16461646
$this->php_fpm_pool_update($data, $web_config, $pool_dir, $pool_name, $socket_dir);
1647+
$this->hhvm_update($data, $web_config);
16471648

16481649
if($web_config['check_apache_config'] == 'y') {
16491650
//* Test if nginx starts with the new configuration file
@@ -1954,6 +1955,8 @@ function delete($event_name, $data) {
19541955
// remove PHP-FPM pool
19551956
if ($data['old']['php'] == 'php-fpm') {
19561957
$this->php_fpm_pool_delete($data, $web_config);
1958+
} elseif($data['old']['php'] == 'hhvm') {
1959+
$this->hhvm_update($data, $web_config);
19571960
}
19581961

19591962
//remove the php cgi starter script if available
@@ -2301,6 +2304,28 @@ private function awstats_delete ($data, $web_config) {
23012304
}
23022305
}
23032306

2307+
private function hhvm_update($data, $web_config) {
2308+
global $app, $conf;
2309+
2310+
if(file_exists($conf['rootpath'] . '/conf-custom/hhvm_starter.master')) {
2311+
$content = file_get_contents($conf['rootpath'] . '/conf-custom/hhvm_starter.master');
2312+
} else {
2313+
$content = file_get_contents($conf['rootpath'] . '/conf/hhvm_starter.master');
2314+
}
2315+
2316+
if($data['new']['php'] == 'hhvm' && $data['old']['php'] != 'hhvm') {
2317+
$content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $content);
2318+
file_put_contents('/etc/init.d/hhvm_' . $data['new']['system_user'], $content);
2319+
exec('chmod +x /etc/init.d/hhvm_' . $data['new']['system_user'] . ' >/dev/null 2>&1');
2320+
exec('/usr/sbin/update-rc.d hhvm_' . $data['new']['system_user'] . ' defaults >/dev/null 2>&1');
2321+
exec('/etc/init.d/hhvm_' . $data['new']['system_user'] . ' start >/dev/null 2>&1');
2322+
} elseif($data['new']['php'] != 'hhvm' && $data['old']['php'] == 'hhvm') {
2323+
exec('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' stop >/dev/null 2>&1');
2324+
exec('/usr/sbin/update-rc.d hhvm_' . $data['old']['system_user'] . ' remove >/dev/null 2>&1');
2325+
unlink('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' >/dev/null 2>&1');
2326+
}
2327+
}
2328+
23042329
//* Update the PHP-FPM pool configuration file
23052330
private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name, $socket_dir) {
23062331
global $app, $conf;

0 commit comments

Comments
 (0)