PHP scripts compiled with HipHop for PHP compiler can easily act as HTTP servers. However, they do not provide the Internet’s most popular method for creating friendly URLs’, the mod_rewrite module that is supplied with the Apache Web server.
In this article I will describe the easiest way to run compiled PHP scripts from the Apache server.
This article will show you the integration of HipHop for PHP with Apache under Fedora 32-bit system. Following these steps on a different Linux distribution should not pose any difficulties. Used modules are normally available in other operating systems.
Please, remember to change files’ paths from /usr/lib/ to /usr/lib64/ in case of 64-bit operating systems.
In addition to the PHP compiler, whose installation is described in previous articles, to run the PHP scripts properly we need two more things.
Apache web server along with its development tools:
yum -y install httpd httpd-devel
And a HTTP proxy module for Apache:
mkdir proxy cd proxy wget http://apache.webthing.com/mod_proxy_html/mod_proxy_html.tar.bz2 tar jxfv mod_proxy_html.tar.bz2 apxs -iac -I/usr/include/libxml2 mod_proxy_html/mod_proxy_html.c
After installing the HTTP server, you need to reconfigure the proxy module.
Assuming that the PHP script will run as a local server on port 8080, part of the Apache configuration file should look like this:
LoadFile /usr/lib/libxml2.so LoadModule proxy_html_module /usr/lib/httpd/modules/mod_proxy_html.so ProxyRequests off RequestHeader unset Accept-Encoding SetOutputFilter proxy-html ProxyHTMLExtended on ProxyHTMLDoctype XHTML RewriteEngine on RewriteRule ^(/.*) http://localhost:8080/$1 [P]
As you can see, at this point you can manipulate the mod_rewrite module settings used to create the friendly URLs using internal redirections.
In order to test the configuration, run the compiled PHP script as a local HTTP server:
/root/test/program -m server -p 8080 &
And then the external Apache server:
service httpd start
Please remember to block access to port 8080 from the firewall system.
The last thing you can do is to test the connection by executing the compiled script (in my case a PHP file named test.php):