Getting Drupal 7 (almost) running on HHVM

In analogy to the article of the hiphop-php.com site, I'll try to give you a tutorial on how to run Drupal on HHVM

Installing HHVM

For the sake of this case-study, I used a Vagrant Ubuntu “Precise” 12.04 as my linux distribution. Also, to not screw up my local development machine, I'll be using disposable virtual boxes.

Installing VirtualBox

https://www.virtualbox.org/wiki/Downloads Download and install the appropriate version of VirtualBox for your machine

Installing Vagrant

http://vagrantup.com/ Download and install the appropriate version of Vagrant for your machine

Downloading and Installing Precise64

  1. cd ~/
  2. git clone --recursive --branch 7.x-1.x http://git.drupal.org/project/vagrant.git
  3. cd vagrant
  4. vagrant box add base http://files.vagrantup.com/precise64.box
  5. vagrant up
  6. sudo nano /etc/hosts
  7. # add
  8. # 33.33.33.10 drupal.vbox.local dev-site.vbox.local
  9. vagrant ssh
  10. # Update our packages
  11. sudo apt-get update
  12. sudo apt-get upgrade
  13. # After updates, run chef again
  14. vagrant provision

Installing hiphop-php

  1. cd ~/vagrant
  2. vagrant ssh
  3. sudo add-apt-repository "deb http://dl.hiphop-php.com/ubuntu precise main"
  4. # no sources are present in hiphops repository, so remove them
  5. sudo add-apt-repository --remove "deb-src http://dl.hiphop-php.com/ubuntu"
  6. sudo apt-get update
  7. sudo apt-get install hiphop-php -y --force-yes

Create a config file

  1. cd ~/vagrant
  2. vagrant ssh
  3. sudo mkdir /var/log/hhvm
  4. sudo chmod 777 /var/log/hhvm/
  5. sudo nano /etc/hhvm.hdf

Add the following snippet and save the file (/etc/hhvm.hdf)

  1. Server {
  2. Port = 8000
  3. SourceRoot = /vagrant/public/drupal.vbox.local/www/
  4. }
  5.  
  6. Eval {
  7. Jit = true
  8. }
  9. Log {
  10. Level = Error
  11. UseLogFile = true
  12. File = /var/log/hhvm/error.log
  13. Access {
  14. * {
  15. File = /var/log/hhvm/access.log
  16. Format = %h %l %u %t \"%r\" %>s %b
  17. }
  18. }
  19. }
  20.  
  21. VirtualHost {
  22. * {
  23. Pattern = .*
  24. RewriteRules {
  25. dirindex {
  26. pattern = ^/(.*)/$
  27. to = $1/index.php
  28. qsa = true
  29. }
  30. }
  31. }
  32. }
  33.  
  34. StaticFile {
  35. FilesMatch {
  36. * {
  37. pattern = .*\.(dll|exe)
  38. headers {
  39. * = Content-Disposition: attachment
  40. }
  41. }
  42. }
  43. Extensions {
  44. css = text/css
  45. gif = image/gif
  46. html = text/html
  47. jpe = image/jpeg
  48. jpeg = image/jpeg
  49. jpg = image/jpeg
  50. png = image/png
  51. tif = image/tiff
  52. tiff = image/tiff
  53. txt = text/plain
  54. }
  55. }

Start the webserver

  1. cd ~/vagrant
  2. vagrant ssh
  3. # Adding some debug modes
  4. sudo hhvm --config /etc/hhvm.hdf --user vagrant --mode daemon -v "Log.Level=Verbose" -v "Log.NoSilencer=on" -v "Log.Header=on"
  5. tail -f /var/log/hhvm/error.log
  • Go to http://drupal.vbox.local:8000/index.php in your browser
  • You can see a couple of errors in the terminal but none of them really are significant.
  1. [Fri Nov 30 12:07:27 2012] [hphp] [2544:7fe6eaf40dc0:0:000015] [] admin server started
  2. [Fri Nov 30 12:07:27 2012] [hphp] [2544:7fe6eaf40dc0:0:000016] [] all servers started
  3. [Fri Nov 30 12:07:27 2012] [hphp] [2544:518f3700:0:000001] [] perf_event_open failed with: No such file or directory
  4. [Fri Nov 30 12:07:27 2012] [hphp] [2544:518f3700:0:000002] [] perf_event_open failed with: No such file or directory
  5. [Fri Nov 30 12:07:27 2012] [hphp] [2544:518f3700:0:000003] [] perf_event_open failed with: No such file or directory
  6. [Fri Nov 30 12:07:30 2012] [hphp] [2544:5254c700:0:000001] [] perf_event_open failed with: No such file or directory
  7. [Fri Nov 30 12:07:30 2012] [hphp] [2544:5254c700:0:000002] [] perf_event_open failed with: No such file or directory
  8. [Fri Nov 30 12:07:30 2012] [hphp] [2544:5254c700:0:000003] [] perf_event_open failed with: No such file or directory
  9. [Fri Nov 30 12:07:30 2012] [hphp] [2544:5254c700:1:000001] [] receiving index.php
  10. [Fri Nov 30 12:07:30 2012] [hphp] [2544:5254c700:1:000002] [7fe6e4d5f4c0:7fe6e4d5f445:7fe6e4d62bab:7fe6e4d5810e:7fe6e4d581b2:b0d80d:114c70b:1154cd6:1359eab:d814db:d390b5:d391e8:d3943e:d39e5e:d3a064:c4af2e:b08ffb:b1ae95:b7fdc0:c14c9c:c02c06:c0529e:f9e1ca:f9e3d9:7fe6e83f7e9a:7fe6e4e1b4bd] Core dumped: Aborted

So I went looking for errors and found the following in /tmp/stacktrace-PID.log

  1. Host: precise64
  2. ProcessID: 2544
  3. ThreadID: 5254c700
  4. ThreadPID: 2553
  5. Name: unknown program
  6. Type: Aborted
  7.  
  8. URL: /index.php
  9. ThreadType: Web Request
  10. Server: drupal.vbox.local:8000
  11.  
  12. # 0 ?? at hhvm:0
  13. # 1 killpg at /lib/x86_64-linux-gnu/libc.so.6:0
  14. # 2 raise at /lib/x86_64-linux-gnu/libc.so.6:0
  15. # 3 abort at /lib/x86_64-linux-gnu/libc.so.6:0
  16. # 4 __uselocale at /lib/x86_64-linux-gnu/libc.so.6:0
  17. # 5 __assert_fail at /lib/x86_64-linux-gnu/libc.so.6:0
  18. # 6 ?? at hhvm:0
  19. # 7 ?? at hhvm:0
  20. # 8 HPHP::c_PDO::t_prepare(HPHP::String const&, HPHP::Array const&) at hhvm:0
  21. # 9 HPHP::tg_3PDO_prepare(HPHP::VM::ActRec*) at hhvm:0
  22. # 10 void HPHP::VMExecutionContext::dispatchImpl<4>(int) at hhvm:0
  23. # 11 HPHP::VMExecutionContext::dispatch() at hhvm:0
  24. # 12 HPHP::VMExecutionContext::enterVMWork(HPHP::VM::ActRec*) at hhvm:0
  25. # 13 HPHP::VMExecutionContext::enterVM(HPHP::TypedValue*, HPHP::VM::ActRec*, HPHP::VM::ExtraArgs*) at hhvm:0
  26. # 14 HPHP::VMExecutionContext::invokeFunc(HPHP::TypedValue*, HPHP::VM::Func const*, HPHP::Array const&, HPHP::ObjectData*, HPHP::VM::Class*, HPHP::VM::VarEnv*, HPHP::StringData*, HPHP::VM::Unit*) at hhvm:0
  27. # 15 HPHP::VMExecutionContext::invokeUnit(HPHP::TypedValue*, HPHP::VM::Unit*) at hhvm:0
  28. # 16 HPHP::eval_invoke_file_hook(HPHP::Variant&, HPHP::String const&, bool, HPHP::LVariableTable*, char const*) at hhvm:0
  29. # 17 HPHP::invoke_file(HPHP::String const&, bool, HPHP::LVariableTable*, char const*) at hhvm:0
  30. # 18 HPHP::include_impl_invoke(HPHP::String const&, bool, HPHP::LVariableTable*, char const*) at hhvm:0
  31. # 19 HPHP::hphp_invoke(HPHP::ExecutionContext*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, bool, HPHP::Array const&, HPHP::VRefParamValue const&, std::basic_string<char, std::char_traits<char>, std::$
  32. # 20 HPHP::HttpRequestHandler::handleRequest(HPHP::Transport*) at hhvm:0
  33. # 21 HPHP::LibEventWorker::doJob(boost::shared_ptr<HPHP::LibEventJob>) at hhvm:0
  34. # 22 HPHP::JobQueueWorker<boost::shared_ptr<HPHP::LibEventJob>, true, false>::start() at hhvm:0
  35. # 23 HPHP::AsyncFuncImpl::threadFuncImpl() at hhvm:0
  36. # 24 HPHP::AsyncFuncImpl::ThreadFunc(void*) at hhvm:0
  37. # 25 start_thread at /lib/x86_64-linux-gnu/libpthread.so.0:0
  38. # 26 __clone at /lib/x86_64-linux-gnu/libc.so.6:0
  39.  
  40. PHP Stacktrace:
  41.  
  42. #0 PDO->prepare() called at [/vagrant/public/drupal.vbox.local/www/includes/database/database.inc:464]
  43. #1 DatabaseConnection->prepareQuery() called at [/vagrant/public/drupal.vbox.local/www/includes/database/database.inc:663]
  44. #2 DatabaseConnection->query() called at [/vagrant/public/drupal.vbox.local/www/includes/database/database.inc:2318]
  45. #3 db_query() called at [/vagrant/public/drupal.vbox.local/www/includes/cache.inc:357]
  46. #4 DrupalDatabaseCache->getMultiple() called at [/vagrant/public/drupal.vbox.local/www/includes/cache.inc:338]
  47. #5 DrupalDatabaseCache->get() called at [/vagrant/public/drupal.vbox.local/www/includes/cache.inc:56]
  48. #6 cache_get() called at [/vagrant/public/drupal.vbox.local/www/includes/bootstrap.inc:902]
  49. #7 variable_initialize() called at [/vagrant/public/drupal.vbox.local/www/includes/bootstrap.inc:2403]
  50. #8 _drupal_bootstrap_variables() called at [/vagrant/public/drupal.vbox.local/www/includes/bootstrap.inc:2180]
  51. #9 drupal_bootstrap() called at [/vagrant/public/drupal.vbox.local/www/includes/bootstrap.inc:2301]
  52. #10 _drupal_bootstrap_page_cache() called at [/vagrant/public/drupal.vbox.local/www/includes/bootstrap.inc:2172]
  53. #11 drupal_bootstrap() called at [/vagrant/public/drupal.vbox.local/www/index.php:20]

So I suppose HHVM is not ready for PDO yet? I'd appreciate more input from people that are more knowledgable.

I think this is where my adventure with HHVM ends for now :-)