Skip to content

Commit e25e407

Browse files
author
Marius Cramer
committed
Merge branch 'master' into 'master'
HHVM Support
2 parents 5f6dd42 + 1b0683b commit e25e407

File tree

10 files changed

+169
-9
lines changed

10 files changed

+169
-9
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',

interface/web/sites/form/web_vhost_domain.tform.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@
241241
'formtype' => 'SELECT',
242242
'default' => 'fast-cgi',
243243
'valuelimit' => 'client:web_php_options',
244-
'value' => array('no' => 'disabled_txt', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM'),
244+
'value' => array('no' => 'disabled_txt', 'fast-cgi' => 'Fast-CGI', 'cgi' => 'CGI', 'mod' => 'Mod-PHP', 'suphp' => 'SuPHP', 'php-fpm' => 'PHP-FPM', 'hhvm' => 'HHVM'),
245245
'searchable' => 2
246246
),
247247
'fastcgi_php_version' => array (

interface/web/sites/templates/web_vhost_domain_edit.htm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ <h2><tmpl_var name="list_head_txt"></h2>
289289
if(data.servertype == "nginx"){
290290
var selected = jQuery('#php').val();
291291
jQuery('.apache').hide();
292-
if(selected != "no" && selected != "php-fpm") {
292+
if(selected != "no" && selected != "php-fpm" && selected != "hhvm") {
293293
jQuery('#php option[value="php-fpm"]').attr('selected', 'selected').val('php-fpm');
294294
}
295295
jQuery('#php option[value="fast-cgi"]').hide();

server/conf/hhvm_starter.master

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
#
3+
# /etc/init.d/hhvm_{SYSTEM_USER}
4+
#
5+
### BEGIN INIT INFO
6+
# Provides: hhvm_{SYSTEM_USER}
7+
# Required-Start: $remote_fs $network
8+
# Required-Stop: $remote_fs $network
9+
# Default-Start: 2 3 4 5
10+
# Default-Stop: 0 1 6
11+
# Description: Starts The HHVM FastCGI Daemon
12+
### END INIT INFO
13+
PATH=/sbin:/usr/sbin:/bin:/usr/bin
14+
DESC="HHVM FastCGI Daemon"
15+
NAME=hhvm
16+
17+
do_start()
18+
{
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+
25+
if [[ -e "/var/run/hhvm/hhvm_{SYSTEM_USER}.pid" ]] ; then
26+
kill -0 `cat /var/run/hhvm/hhvm_{SYSTEM_USER}.pid` >/dev/null 2>&1 ;
27+
case "$?" in
28+
0)
29+
return 1
30+
;;
31+
esac
32+
fi
33+
34+
umask 017
35+
sudo -u {SYSTEM_USER} touch /var/run/hhvm/hhvm_{SYSTEM_USER}.pid
36+
/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
37+
}
38+
39+
do_stop()
40+
{
41+
if [[ -e "/var/run/hhvm/hhvm_{SYSTEM_USER}.pid" ]] ; then
42+
kill -SIGTERM `cat /var/run/hhvm/hhvm_{SYSTEM_USER}.pid` >/dev/null 2>&1 ;
43+
fi
44+
rm -f /var/run/hhvm/hhvm.{SYSTEM_USER}.sock /var/run/hhvm/hhvm.{SYSTEM_USER}.hhbc /var/run/hhvm/hhvm_{SYSTEM_USER}.pid
45+
}
46+
47+
case "$1" in
48+
start)
49+
do_start
50+
;;
51+
stop)
52+
do_stop
53+
;;
54+
restart|force-reload)
55+
do_stop
56+
case "$?" in
57+
0|1)
58+
do_start
59+
;;
60+
*)
61+
;;
62+
esac
63+
;;
64+
*)
65+
exit 3
66+
;;
67+
esac
68+
69+
:

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: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
<tmpl_if name='php' op='==' value='php-fpm'>
2121
DocumentRoot <tmpl_var name='web_document_root'>
2222
</tmpl_else>
23-
DocumentRoot <tmpl_var name='web_document_root_www'>
23+
<tmpl_if name='php' op='==' value='hhvm'>
24+
DocumentRoot <tmpl_var name='web_document_root'>
25+
</tmpl_else>
26+
DocumentRoot <tmpl_var name='web_document_root_www'>
27+
</tmpl_if>
2428
</tmpl_if>
2529
</tmpl_if>
2630
</tmpl_if>
@@ -318,6 +322,25 @@
318322
</IfModule>
319323
</tmpl_if>
320324

325+
<tmpl_if name='php' op='==' value='hhvm'>
326+
<IfModule mod_fastcgi.c>
327+
<Directory {tmpl_var name='document_root'}/cgi-bin>
328+
<tmpl_if name='apache_version' op='>' value='2.2' format='version'>
329+
Require all granted
330+
<tmpl_else>
331+
Order allow,deny
332+
Allow from all
333+
</tmpl_if>
334+
</Directory>
335+
<FilesMatch "\.php[345]?$">
336+
SetHandler php5-fcgi
337+
</FilesMatch>
338+
Action php5-fcgi /php5-fcgi
339+
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 /var/run/hhvm/hhvm.<tmpl_var name='system_user'>.sock -pass-header Authorization
341+
</IfModule>
342+
</tmpl_if>
343+
321344
<tmpl_if name="rewrite_enabled">
322345
RewriteEngine on
323346
<tmpl_if name='seo_redirect_enabled'>

server/plugins-available/apache2_plugin.inc.php

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function php_ini_changed($event_name, $data) {
104104

105105
/* $data contains an array with these keys:
106106
* file -> full path of changed php_ini
107-
* mode -> web_domain php modes to change (mod, fast-cgi, php-fpm or '' for all except 'mod')
107+
* mode -> web_domain php modes to change (mod, fast-cgi, php-fpm, hhvm or '' for all except 'mod')
108108
* php_version -> php ini path that changed (additional php versions)
109109
*/
110110

@@ -121,6 +121,11 @@ function php_ini_changed($event_name, $data) {
121121
if($data['php_version']) {
122122
$qrystr .= " AND fastcgi_php_version LIKE '%:" . $app->db->quote($data['php_version']) . ":%'";
123123
}
124+
} elseif($data['mode'] == 'hhvm') {
125+
$qrystr .= " AND php = 'hhvm'";
126+
if($data['php_version']) {
127+
$qrystr .= " AND fastcgi_php_version LIKE '%:" . $app->db->quote($data['php_version']) . ":%'";
128+
}
124129
} else {
125130
$qrystr .= " AND php != 'mod' AND php != 'fast-cgi'";
126131
}
@@ -1318,7 +1323,7 @@ function update($event_name, $data) {
13181323
* PHP-FPM
13191324
*/
13201325
// Support for multiple PHP versions
1321-
if($data['new']['php'] == 'php-fpm'){
1326+
if($data['new']['php'] == 'php-fpm' || $data['new']['php'] == 'hhvm'){
13221327
if(trim($data['new']['fastcgi_php_version']) != ''){
13231328
$default_php_fpm = false;
13241329
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 @@ function update($event_name, $data) {
13271332
$default_php_fpm = true;
13281333
}
13291334
} else {
1330-
if(trim($data['old']['fastcgi_php_version']) != '' && $data['old']['php'] == 'php-fpm'){
1335+
if(trim($data['old']['fastcgi_php_version']) != '' && ($data['old']['php'] == 'php-fpm' || $data['old']['php'] == 'hhvm')){
13311336
$default_php_fpm = false;
13321337
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']));
13331338
if(substr($custom_php_fpm_ini_dir, -1) != '/') $custom_php_fpm_ini_dir .= '/';
@@ -1586,6 +1591,7 @@ function update($event_name, $data) {
15861591
}
15871592

15881593
$this->php_fpm_pool_update($data, $web_config, $pool_dir, $pool_name, $socket_dir);
1594+
$this->hhvm_update($data, $web_config);
15891595

15901596
if($web_config['check_apache_config'] == 'y') {
15911597
//* Test if apache starts with the new configuration file
@@ -1933,6 +1939,8 @@ function delete($event_name, $data) {
19331939
// remove PHP-FPM pool
19341940
if ($data['old']['php'] == 'php-fpm') {
19351941
$this->php_fpm_pool_delete($data, $web_config);
1942+
} elseif($data['old']['php'] == 'hhvm') {
1943+
$this->hhvm_update($data, $web_config);
19361944
}
19371945

19381946
//remove the php cgi starter script if available
@@ -2722,6 +2730,28 @@ private function awstats_delete ($data, $web_config) {
27222730
}
27232731
}
27242732

2733+
private function hhvm_update($data, $web_config) {
2734+
global $app, $conf;
2735+
2736+
if(file_exists($conf['rootpath'] . '/conf-custom/hhvm_starter.master')) {
2737+
$content = file_get_contents($conf['rootpath'] . '/conf-custom/hhvm_starter.master');
2738+
} else {
2739+
$content = file_get_contents($conf['rootpath'] . '/conf/hhvm_starter.master');
2740+
}
2741+
2742+
if($data['new']['php'] == 'hhvm' && $data['old']['php'] != 'hhvm') {
2743+
$content = str_replace('{SYSTEM_USER}', $data['new']['system_user'], $content);
2744+
file_put_contents('/etc/init.d/hhvm_' . $data['new']['system_user'], $content);
2745+
exec('chmod +x /etc/init.d/hhvm_' . $data['new']['system_user'] . ' >/dev/null 2>&1');
2746+
exec('/usr/sbin/update-rc.d hhvm_' . $data['new']['system_user'] . ' defaults >/dev/null 2>&1');
2747+
exec('/etc/init.d/hhvm_' . $data['new']['system_user'] . ' start >/dev/null 2>&1');
2748+
} elseif($data['new']['php'] != 'hhvm' && $data['old']['php'] == 'hhvm') {
2749+
exec('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' stop >/dev/null 2>&1');
2750+
exec('/usr/sbin/update-rc.d hhvm_' . $data['old']['system_user'] . ' remove >/dev/null 2>&1');
2751+
unlink('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' >/dev/null 2>&1');
2752+
}
2753+
}
2754+
27252755
//* Update the PHP-FPM pool configuration file
27262756
private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name, $socket_dir) {
27272757
global $app, $conf;

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)