Orchard Hungary is an archive

This site is now an archive. We'll keep it so the content is accessible, but we won't update it anymore. However, we frequently publish Orchard-related news on our other site Orchard Dojo, so be sure to check that out instead. And if you're interested in news about our Orchard development company, Lombiq, check out our website.

Running PHP inside Orchard

Tags: Orchard, PHP

Sounds a bit perverted, right? Well, I admit it is, but recently I had to move a legacy PHP site to Orchard and it had a forum that had do be kept. Since there is not suitable forum solution currently for Orchard, migration was not an option, so somehow the existing punBB forum had to be integrated into the Orchard site. Now is this possible? For me, it wasn't...

I've made multiple approaches, let me describe them.

Running PHP from a static folder a la naturale

Dropping PHP to a suitable folder, like a theme's Content folder should work with some tweaking, thought I. But it won't, because Orchard's Web.config clears all handlers:

  <system.webServer>
    ...
    <handlers accessPolicy="Script">
      <clear/>

Thus if there are any, PHP handlers are also gone, so nothing will run PHP scripts. One could try to re-add a FastCGI handler for PHP like this from e.g. the Web.Release.config:

    <handlers accessPolicy="Read, Script" xdt:Transform="SetAttributes(accessPolicy)">
      <clear xdt:Transform="Remove" />
      <add name="PHP via FastCGI" path="*.php" verb="*" modules="FastCgiModule" scriptProcessor="%RoleRoot%\approot\php\php-cgi.exe" resourceType="Unspecified" requireAccess="Script" xdt:Transform="Insert" />
    </handlers>

Assuming you know the path to the PHP script processor, this would work I think. The site is on Gearhost and they can't tell the path, so this is a no-go.

Running as an app folder

Since Gearhost gives you the ability to mark subfolders of a web site as applications (thus giving the folder the ability of overriding almost everything the root Web.config sets) theoretically this could also work. I experimented around with this but haven't succeeded, in the end I guess some configuration of the root Web.config was still blocking (despite me trying to reset everything from the app folder's config).

Giving up

Having spent too much hours digging Web.config files I decided that I don't really want to do this and simply put the forum under a completely different website. There it runs happily, I even migrated the .htaccess settings it had (just some url rewriting) to a Web.config.

But now how to fake that the forum is part of the same website? First I wanted to rewrite the legacy /forum url to the different domain, what, according to a SO answer, is possible, since the forum and the Orchard site is under the same IP, on the same server, even in the same AppPool. The Gearhost support engineers really wanted to suggest something else, so in the end I've taken their suggestion of configuring the domain settings so that the forum appeared under a subdomain of the main site. This is no big deal, and I was relieved to end this at once.

Moral of the story: don't try to mix PHP with Orchard, you don't really want to do it.

Happy PHP coding!

No Comments