Deploy HHVM on PHP

Deploy HHVM on PHP

HHVM doesn’t and have no plans to support 32 bit operating system. As we are running Debian 7.8 Wheezy (on Plesk), we will install it from prebuilt packages.

# https://docs.hhvm.com/hhvm/installation/linux
#
sudo apt-get install software-properties-common
wget -O - http://dl.hhvm.com/conf/hhvm.gpg.key | sudo apt-key add -
sudo add-apt-repository "deb http://dl.hhvm.com/ubuntu $(lsb_release -sc) main"
sudo apt-get update
sudo apt-get -y install hhvm

To test it’s working, type:

hhvm --help

Now, we want to use HHVM in the FastCGI mode.

By reading this script /usr/share/hhvm/install_fastcgi.sh I found out that only one file needs to be included: /etc/nginx/hhvm.conf

include /etc/nginx/hhvm.conf;

Warning: HHVM has incorporated a lot of commonly used PHP extensions. However, if an application uses a PHP extension that hasn’t been incorporated yet, choosing HHVM will break the application. The complete list of PHP extensions that have been ported over to HHVM is here

Make HHVM start at boot:

sudo update-rc.d hhvm defaults
Watch out of ports and sockets

As detected from here, we are communication with php-fpm by sockets. If this would not be the case, we would need to change HHVM port. But for our current situation it’s safe to communicate to HHVM via port.

grep "listen =" /etc/php5/fpm/pool.d/*.conf

But I could also switch to using HHVM via sockets, but for now - I won’t.

Sources & Articles


    location ~ \.php$ {
        try_files /5cfdacfc84ded7cb25fbc0ad678ef7be.htm @php;
    }

    location @php {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/var/lib/php5-fpm/web23.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_intercept_errors on;
    }

HHVM: Prebuilt packages on Ubuntu 15.04 (vivid) · facebook/hhvm Wiki

Install HHVM with package manager

Prebuilt packages on Ubuntu 15.04

That file contains only this:

location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

HHVM is installed. *

  • Running PHP web scripts with HHVM is done by having your
  • webserver talk to HHVM over FastCGI. Install nginx or Apache,
  • and then:
  • $ sudo /usr/share/hhvm/install_fastcgi.sh
  • $ sudo /etc/init.d/hhvm restart
  • (if using nginx) $ sudo /etc/init.d/nginx restart
  • (if using apache) $ sudo /etc/init.d/apache restart
  • Detailed FastCGI directions are online at:
  • https://github.com/facebook/hhvm/wiki/FastCGI
  • If you’re using HHVM to run web scripts, you probably want it
  • to start at boot:
  • $ sudo update-rc.d hhvm defaults
  • Running command-line scripts with HHVM requires no special setup:
  • $ hhvm whatever.php
  • You can use HHVM for /usr/bin/php even if you have php-cli
  • installed:
  • $ sudo /usr/bin/update-alternatives \
  • –install /usr/bin/php php /usr/bin/hhvm 60

Test the HHVM

First, I want to create phpinfo() files, both for PHP and HHVM:

cd /var/www/antikhandel.ch/web
echo "<?php phpinfo(); ?>" >nfo.php
wget https://gist.githubusercontent.com/ck-on/67ca91f0310a695ceb65/raw/hhvminfo.php -O nfo_hhvm.php

HHVMinfo



Making your own High Performance WordPress Server | Zach Adams | Boise Web Design and Development - Making your own WPEngine-Like High Performance WordPress Server



joostlaan/hhvm-laravel Repository | Docker Hub Registry - Repositories of Docker Images


HHVM permissions

We have to allow group write permissions to files in Wordpress:

# Permissions for HHVM
#
find . -type d -exec chmod 775 {} \;
find . -type f -exec chmod 664 {} \;

Also, add this to wp-config.php, but it’s not necessary:

if (defined('HHVM_VERSION')) {
  define('FS_CHMOD_DIR', 0775);
  define('FS_CHMOD_FILE', 0664);

  define('FS_METHOD', 'direct');
}

In this way, all new files created by WP itself will have adequate permissions. I also think that the line with FS_METHOD is not really required.

Those more permissive permissions, as set above, are nicely explained in WordPress Codex: Changing File Permissions « WordPress Codex

HHVM runs under www-data user, same as nginx. On ISPConfig, www-data user is already part of client? groups, so no additional settings are necessary.

Also, if switching again to PHP-FPM, and some dirs were created by HHVM, we also need to add a user of PHP-FPM to the HHVM’s group:

usermod -a -G www-data web1

Fastest way to set wanted owners is:

# Ownership
#
chown -R --reference . *

Add HHVM to services

Add these to /usr/lib/systemd/system/hhvm.service:

[Unit]
Description=HHVM HipHop Virtual Machine (FCGI)

[Service]
ExecStartPre=-/usr/bin/mkdir -p /var/run/hhvm
ExecStartPre=-/usr/bin/chown nobody /var/run/hhvm
ExecStart=/usr/local/bin/hhvm --config /etc/hhvm/server.ini --user nobody --mode daemon -vServer.Type=fastcgi -vServer.Port=9000

[Install]
WantedBy=multi-user.target

And do some systemctl work to make it start automatically:

systemctl enable hhvm
systemctl start hhvm
systemctl status hhvm

Building and installing hhvm on CentOS 7.x · facebook/hhvm Wiki How to use HHVM with systemd / journald / syslog? · Issue #4785 · facebook/hhvm include systemd init setup files in hhvm proper? · Issue #4520 · facebook/hhvm


Problems with HHVM

cat <<'EOF' >> /etc/nginx/fastcgi_params

# Increase maximum execution time in seconds (default was 30)
fastcgi_read_timeout 600;

EOF

Nginx timeout + PHP-FPM/HHVM

There is a problem in HHVM and it’s cUrl extension:

Installing composer using vagrant, hhvm

Error in SlowTimer [5241ms] at curl: http://api.tradedoubler.com/1.0/vouchers.xml?token=27C616CD76D972191913A0F1F474EAF38B591962

CURLOPT_LOW_SPEED_LIMIT, CURLOPT_LOW_SPEED_TIME Hack and HHVM: curl_setopt - Manual

curl_setopt($ch_2, CURLOPT_CONNECTTIMEOUT, 60); curl_setopt($ch_2, CURLOPT_TIMEOUT, 86400); curl_setopt($ch_2, CURLOPT_LOW_SPEED_LIMIT, 10240); curl_setopt($ch_2, CURLOPT_LOW_SPEED_TIME, 60);

ResourceLimit.SocketDefaultTimeout=30 # in seconds Http.SlowQueryThreshold=30000 # in milliseconds (took me half an hour to figure this one out)

Building a Better PHP — Part 2: Using HHVM

? hhvm.http.default_timeout

; max_execution_time alternative
hhvm.resource_limit.socket_default_timeout=30
hhvm.http.slow_query_threshold=30000
hhvm.server.request_timeout_seconds=600

the max_execution_time value defined in the php.ini.

The ini setting max_execution_time is for CLI scripts. For a server you want to set hhvm.server.request_timeout_seconds=5. Also note that this will set a timeout for the request not just script execution, so if the script has been queued for longer than this timeout it won’t run at all. I verified that this works with the FastCGI server in my environment.

You can use the hhvm.server.connection_timeout_seconds INI setting, which defaults to 120, to control how long a FastCGI request will last for.



How to Purge Nginx FastCGI Cache from WordPress Admin Panel | WEBVISION

How to Install nginx and google pagespeed on Ubuntu 15.04 (Vivid Vervet) Dashboard ‹ save-up.ch — WordPress How To Use Multiple PHP Versions (PHP-FPM & FastCGI) With ISPConfig 3 (Ubuntu 13.04)

Running HHVM with fallback to PHP-FPM phpinfo() ISPConfig 3.0.5.4p8

linux - How to execute a command whenever a file changes? - Super User Why don’t you buy goldkaufen.ch? | Parked Domains Install WordPress with HHVM, Nginx and MariaDB on an Ubuntu 12.04 LTS | RoseHosting.com Linux VPS Hosting Blog HHVM, MariaDB and Nginx Make WordPress Fly - Intro “Call to undefined function force_ssl_admin()” - Google Search Get Google to fall in love with you - in 9 steps | Wordtracker Academy Search Console - Crawl Errors - http://www.save-up.ch/ How to Set Up LEMH (Linux, Nginx, MariaDB, HHVM) Stack in Ubuntu Server - Make Tech Easier ISPConfig 3.0.5.4p8 HHVM Wow HHVM is fast…too bad it doesn’t run my code « HHVM Getting WordPress running on HHVM « HHVM hhvm wordpress compatibility - Google Search WP Engine Sponsors John James Jacoby to Work on HHVM Compatibility with BuddyPress HHVM for Varying Vagrant Vagrants: WordPress Development on Speed hgv/provisioning/roles/nginx/templates/nas/wp/www/sites at master · wpengine/hgv Database: koviljaca_rs - Adminer

Debugging HHVM falling over | Web Hosting Talk HHVM 3.0 / Hack with Nginx cannot access file in directory with 770 permissions on Ubuntu 13.10 while having group membership - Stack Overflow HHVM and directory permissions · Issue #150 · roots/trellis HHVM seems to fail on some group permission s · Issue #2248 · facebook/hhvm

500 hphp_invoke white screen of dead · Issue #3667 · facebook/hhvm php - HHVM returns error 500 - Stack Overflow php - nginx - laravel - hhvm-Fastcgi get error 500 - Stack Overflow WooCommerce ‘Place Order’ 500 Error on HHVM | WEBVISION hhvm toString php error · Issue #5551 · facebook/hhvm WordPress › Support » Fatal error: Call to undefined function wp() in wp-blog-header.php on line 18


Trying to fix that HHVM:

hhvm timeout - Google Search INI Settings · facebook/hhvm Wiki hhvm max_execution_time - Google Search Hack and HHVM: Runtime Configuration - Manual Hack and HHVM: set_time_limit - Manual max_execution_time ignored · Issue #4124 · facebook/hhvm max_execution_time hhvm · Issue #4209 · facebook/hhvm Config Litespeed with HHVM FastCGI | LiteSpeed Support Forums api - PHP curl maximum execution time using hhvm - Stack Overflow hhvm SlowTimer at curl - Google Search Hack and HHVM: curl_setopt - Manual Hack and HHVM: curl_setopt - Manual hhvm/builtins_curl.hhi at master · facebook/hhvm SlowTimer at curl - Google Search Installing composer using vagrant, hhvm, and Ubuntu 14.04 - Stack Overflow vanderveer.be/speed-up-composer-by-using-hhvm-including-a-slowtimer-error-fix/ Building a Better PHP — Part 2: Using HHVM Disqus - Speed up Composer by using HHVM, including a SlowTimer error fix - vanderVeer.be resourcelimit.socketdefaulttimeout=30 - Google Search Thought I’d update this classic comic for us PHP guys (and gals)… XKDC’s “compiling” : PHP http://osdir.com/ml/general/2014-09/msg28208.html failed to load Hack and HHVM: Runtime Configuration - Manual HHVM-3.3.0 InvalidArgumentException · Issue #3797 · facebook/hhvm Hack and HHVM: Runtime Configuration - Manual max_execution_time hhvm · Issue #4209 · facebook/hhvm HHVMinfo phpinfo() Ubuntu Manpage: CURLOPT_TIMEOUT - set maximum time the request is allowed to take c++ - libcurl - Strange timeout after 5 seconds - Stack Overflow Download is not resuming using Curl C API - Stack Overflow PHP Manual: curl_setopt

W3 Total Cache compatibility

Warning: Parameter 1 to W3_Plugin_TotalCache::ob_callback() expected to be a reference Fixing Warning on HHVM

WooCommerce compatibility

WooCommerce ‘Place Order’ 500 Error on HHVM


Sources of information:

There is more on this above:

sudo update-rc.d hhvm remove

Upstart supports this with respawn directive, but we are using systemd.

/etc/init.d contains scripts used by the SystemV init tools. This is the traditional service management package for Linux. It includes the init program, which is the first process to run after the kernel has finished initialising, as well as some infrastructure for starting and stopping services and configuring them. Specifically, files in /etc/init.d are shell scripts that respond to start, stop, restart, and, when supported, reload commands to manage a certain service. These scripts can be invoked directly or more commonly via some other trigger, typically the presence of a symbolic link in /etc/rc?.d/.

/etc/init contains the configuration files used by Upstart. Upstart is a young service management package championed by Ubuntu, now replaced by the systemd package.

HHVM - HHVM Overview and Configuration Information

date 07. Jun 2016 | modified 10. Jun 2024
filename: Server » HHVM