Skip to content

Commit c596328

Browse files
author
Marius Cramer
committed
Implemented: FS#3266 - HHVM PHP mode support
(nginx still missing)
1 parent 5f6dd42 commit c596328

File tree

5 files changed

+122
-6
lines changed

5 files changed

+122
-6
lines changed

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: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
{START}
20+
}
21+
22+
do_stop()
23+
{
24+
{STOP}
25+
}
26+
27+
case "$1" in
28+
start)
29+
do_start
30+
;;
31+
stop)
32+
do_stop
33+
;;
34+
restart|force-reload)
35+
do_stop
36+
case "$?" in
37+
0|1)
38+
do_start
39+
;;
40+
*)
41+
;;
42+
esac
43+
;;
44+
*)
45+
exit 3
46+
;;
47+
esac
48+
49+
:

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 /tmp/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: 47 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,42 @@ 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+
$start_content = '';
2742+
$stop_content = '';
2743+
2744+
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);
2758+
file_put_contents('/etc/init.d/hhvm_' . $data['new']['system_user'], $content);
2759+
exec('chmod +x /etc/init.d/hhvm_' . $data['new']['system_user'] . ' >/dev/null 2>&1');
2760+
exec('/usr/sbin/update-rc.d hhvm_' . $data['new']['system_user'] . ' defaults >/dev/null 2>&1');
2761+
exec('/etc/init.d/hhvm_' . $data['new']['system_user'] . ' start >/dev/null 2>&1');
2762+
} elseif($data['new']['php'] != 'hhvm' && $data['old']['php'] == 'hhvm') {
2763+
exec('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' stop >/dev/null 2>&1');
2764+
exec('/usr/sbin/update-rc.d hhvm_' . $data['old']['system_user'] . ' remove >/dev/null 2>&1');
2765+
unlink('/etc/init.d/hhvm_' . $data['old']['system_user'] . ' >/dev/null 2>&1');
2766+
}
2767+
}
2768+
27252769
//* Update the PHP-FPM pool configuration file
27262770
private function php_fpm_pool_update ($data, $web_config, $pool_dir, $pool_name, $socket_dir) {
27272771
global $app, $conf;

0 commit comments

Comments
 (0)