Run both HHVM and Normal Apache Server
Asked Answered
D

2

5

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

Dreibund answered 2/9, 2014 at 6:24 Comment(2)
You can run it in FastCGI mode alongside Apache and PHP-FPM.Heinous
@Heinous Thanks, I think that show me how to do scenario 2. But if possible, I would still prefer scenario 1; have any ideas for that???Dreibund
G
6

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...";
}
Goldarn answered 3/9, 2014 at 2:1 Comment(2)
Perfect! =D (more than 15 characters)Dreibund
I would just like to point out that the step where you comment out /etc/apache2/mods-available/hhvm_proxy_fcgi.conf contents is very important, and will need to be done again if you update HHVM.Dreibund
C
1

Yes. You can have Apache listen on both port 80 and port 8080 (just add in additional listen configurations), then add a virtual host for localhost:8080 that passes requests off to HHVM through FastCGI.

Charmine answered 2/9, 2014 at 8:28 Comment(1)
ok, I am pretty sure that involves editing one of Apache's config files. As a said above, I don't know enough about the config files to do it myself. Can you add some code showing what it would look like for one port to use hhvm and one that doesn't?Dreibund

© 2022 - 2024 — McMap. All rights reserved.