2

I recently built XHP 1.5 from source, and installed it on an existing web server. The web server is running PHP 5.4.32, Apache 2.2.15 calling PHP using mod_php (not fastcgi), CentOS 6.5. All our existing PHP code (that doesn't rely on the new XHP syntax) still works great, including other extensions like Imagick, curl, and JSON.

Using a test file based on the XHP installation test:

<?php
echo "XHP!\n";
exit;
echo <a/>;
?>

This works as expected when run from the command line. (It prints XHP! then exits. The doesn't cause the parser to fail, but doesn't display either, since we're not loading in the dependencies.)

When I fetch this script through Apache, I get the error

Parse error: syntax error, unexpected '<' in /var/www/html/bloom/play.php on line 4 

Getting phpinfo() via Apache shows that XHP is loaded, extension_loaded("xhp") through Apache returns true.

What could be causing XHP to work from the command line, but to not work (not even parse) when run via Apache?

Jeremy Wadhams
  • 1,744
  • 18
  • 26
  • Have you loaded the `mod_php` module in Apache? Could you show us the `httpd.conf` file or the `vhost` file for your domain/subdomain? Try seeing if you have something similar in your `httpd.conf`: `LoadModule php5_module modules/libphp.so` and `AddType application/x-httpd-php .php` – tftd Sep 17 '14 at 17:16
  • Sorry, I should have specified, any existing PHP page we have that contains no XHP type syntax works perfectly, including other extensions like imagick, json, and curl. Our vhost and httpd.conf do not modify PHP behavior, and /etc/httpd/conf.d/php.conf appears to be totally vanilla (including both the LoadModule and AddType you suggest) – Jeremy Wadhams Sep 17 '14 at 17:41
  • p.s. If you've solved your problem, post the answer below and mark it as answered, for posterity. – Leo Bedrosian Sep 22 '14 at 19:36

2 Answers2

0

One possible reason is a difference in versions of PHP, especially since you're building XHP from source. I've encountered similar odd behavior on a shared host that had multiple versions of PHP installed. Compare the PHP version reported by Apache (look at the phpinfo() output) against the version you're using at the command line php -v. If there's a difference, that could be one explanation for the problem you're having.

Leo Bedrosian
  • 3,659
  • 2
  • 18
  • 22
0

After looking into more detail for how my production server (not working) differed from my test servers (working) I discovered that all servers had APC 3.1.15 installed, but in production, APC's opcode cache was disabled in /etc/php.d/apc.ini:

# BAD NEWS
apc.enable_opcode_cache=0

As it happens, this is not what we wanted for unrelated performance reasons.

Turning on APC's opcode cache, by changing this line in /etc/php.d/apc.ini and restarting Apache caused XHP to immediately begin working:

# WORKING
apc.enable_opcode_cache=1

I've also been able to resolve the problem by uninstalling APC altogether (although that's not practical in my app).

That would also explain why it worked from the CLI and not from the web--all my servers have apc.enable_cli=0, so APC wouldn't interfere with XHP from the CLI.

Jeremy Wadhams
  • 1,744
  • 18
  • 26