Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run both HHVM and Normal Apache Server

Tags:

php

apache

hhvm

This morning I started using HHVM as my default local server. Most things are fine, but I still have applications that HHVM doesn't fully support yet.

Rather than changing my configuration and restarting services, it would be much easier if I could just switch ports or directories.

My Question: Is it possible to run a normal Apache server on one port (80) and a HHVM powered server on another port (8080)? Alternatively, is it possible to only run HHVM in a specific directory (and its' sub-directories)?

In scenario 1 switching to HHVM application would look like this:

  localhost/my-project/index.php
  localhost:8080/my-project/index.php

In scenario 2 switching to HHVM application would look like this:

  localhost/my-project/index.php
  localhost/hhvm/my-project/index.php

I would guess that this can be achieved via Apache's config file, but I don't know enough about how the config files work to do it myself, please help!?


OS: Ubuntu 14.04
Apache Version: 2.4.7
HHVM Version: 3.2.0

like image 903
Nicholas Summers Avatar asked Sep 02 '14 06:09

Nicholas Summers


1 Answers

To /etc/apache2/ports.conf add...

Listen 8080

Then, to your vhost configuration (since using localhost as your domain, probably /etc/apache2/sites-available/default.conf), copy everything in there and paste it right below so you have a second VirtualHost instance. To the second instance, change the *:80 to *:8080, then add your ProxyPassMatch to tell it you're wanting to use HHVM for hh and php file extensions (don't forget to update to correct directory).

It should look something like...

<VirtualHost *:80>

    ... keep the same ...

</VirtualHost>
<VirtualHost *:8080>

    ... keep the same ...

    ProxyPassMatch ^/(.+\.(hh|php)(/.*)?)$ fcgi://127.0.0.1:9000/var/www/$1

</VirtualHost>

Go into /etc/apache2/mods-available/hhvm_proxy_fcgi.conf and comment out what's in there. Otherwise everything will be headed toward HHVM.

Finally, restart apache

sudo service apache2 restart

I tested this quickly on an existing local site and it was redirecting back to 80 from 8080 which it should have done. If this doesn't work out, let me know.

UPDATE: Tested a bit more, and it looks like this should work out for you. After adding the following, jumping between local.site.com/hhvm.php and local.site.com:8080/hhvm.php flipped the echo correctly.

<?php if (defined('HHVM_VERSION')) {
    echo "golden!";
} else {
    echo "doh...";
}
like image 164
BlakePetersen Avatar answered Sep 28 '22 12:09

BlakePetersen