Working setup, assume a request to http://127.0.0.1:8080/path/to/resource
:
$_SERVER['SCRIPT_NAME']
is always index.php
and the $_SERVER['REQUEST_URI']
is from the url /path/to/resource
(notice, no index.php
anywhere in it) index.php
file in /some/path/public/index.phpindex.php
and have their URI's (in this case `/path/to/resource) parsed by a routing system. In order to take nginx or apache out of the picture when running hhvm for dev purposes or just fun, I run hhvm in server mode (NOT FastCGI mode!!!):
cd /some/path/public/
hhvm -m server -p 8080
However, the framework doesn't handle the index.php
in the path gracefully. When served by hhvm running in server mode the only urls that work are:
http://127.0.0.1:8080/index.php
...or...
http://127.0.0.1:8080
Anything more complex fails like:
http://127.0.0.1:8080/path/to/resource (HHVM fails, file not found)
Also, sticking in an explicit index.php fails as the framework doesn't handle the index.php
in the REQUEST_URI
gracefully.
http://127.0.0.1:8080/index.php/path/to/resource (HHVM works, but framework fails, `index.php` in uri confuses it)
Does anyone know a way to get this to work where ALL request are sent to the root /some/path/public/index.php? Is there an option to set the SCRIPT_NAME explicitly via a option flag/setting?
Ideally the request http://127.0.0.1:8080/path/to/resource
would have:
index.php
/path/to/resource
Ok, I figured a few ways, running HHVM 3.18.1 with some help from another SO user.
The best way is to use virtual hosts rewite rules:
hhvm.server.default_document = index.php
hhvm.virtual_host[default][rewrite_rules][common][pattern] = "(.*)"
hhvm.virtual_host[default][rewrite_rules][common][to] = "index.php/$1"
hhvm.virtual_host[default][rewrite_rules][common][qsa] = true
Had a hard time finding documentation on this, but here's a link to the HHVM docs sort of explaining: https://docs.hhvm.com/hhvm/configuration/INI-settings#server-mode__virtual-host-format
Note that the documentation is the old format, not the new ini
format, so option names should be converted from CamelCase
to underscore seperated like camel_case
.
Another, less elegant way: Without using rewrites, you can hijack 404's. You need to set BOTH the parameters
hhvm.server.error_document404
hhvm.server.default_document
Set both of these to whatever your default index/routing file is--let your framework handle 404 messages.
You can set these in an ini
config file (I'll call it server.ini
):
hhvm.server.default_document = /path/to/index.php
hhvm.server.error_document404 = /path/to/index.php
Then you can start the server with:
hhvm -m server -p 8080 -c /path/to/server.ini
You can also skip the INI file and pass the details in when starting HHVM:
hhvm -m server -p 8080 -d hhvm.server.default_document=/path/to/index.php -d hhvm.server.error_document404=/path/to/index.php
If you don't want to have to run hhvm
from a specific folder, you can also set:
hhvm.server.source_root=/path/to/doc_root
Notes:
default_document
and error_document404
will be relative to this directory unless they have fully qualified paths. However, you must set the error_document404
to something explicitly. While default_document
seems to default to index.php
, the error_document404
seems not to have a default value.http://127.0.0.1:8080/index.php/path/to/resource
fails but http://127.0.0.1:8080/path/to/resource
now works. Guess you can't have your cake and eat it too :)