Target .NET Framework#
(not .NET Core)
Projects built with PeachPie depend on the PeachPie runtime, which targets .NET Standard 2.0. This makes it compatible with the vast array of other .NET frameworks and runtimes, as long as they are compatible with .NET Standard 2.0. This includes .NET Core 2.0, Mono 5.4, Xamarin.Android 8.0, or .NET Framework 4.6.1 or higher.
Building the project#
Build a library#
When compiling a library project to be referenced by other projects, it is always the best option to target the lowest .NET Standard makes it possible for the project to be referenced by a majority of .NET projects. In this case, it is
netstandard2.0. Make sure you have the following property set in the project file:
Build an executable#
In order to build an executable application for the .NET Framework (not .NET Core), target
net461 or higher and specify the output type
exe in the project file:
Optionally, specify the startup object, which should be called upon starting the application.
Assuming the project with PHP files is compiled as a library, you can be targeting either
<TargetFramework>net461</TargetFramework> <AssemblyName>MyWebsite</AssemblyName><!-- an optional name -->
Add a package reference to request handler:
<ItemGroup> <PackageReference Include="Peachpie.RequestHandler" Version="1.0.8" /> </ItemGroup>
You can handle the requests to
*.php pages on your ASP.NET (Integrated Pipeline) server (specifically IIS 7, IIS Express or Apache with mod_mono) in two ways; either by modifying
web.config and passing requests directly to
MyWebsite.dll, or by handling the requests programatically in your C# code.
Option 1: Web.Config#
Alter the web application's
web.config file with the following configuration within
<configuration> root element:
<system.webServer> <handlers> <add name="PeachpieHandler" path="*.php" verb="*" type="Peachpie.RequestHandler.RequestHandler, Peachpie.RequestHandler" resourceType="Unspecified" preCondition="integratedMode" /> </handlers> </system.webServer>
/binfolder of your ASP.NET application contains all the necessary assemblies including
Peachpie.RequestHandler.dlland other Peachpie runtime assemblies.
Option 2: Programatically#
In order to handle requests to compiled
*.php pages, make use of the
RequestHandler API. Obtain the instance of
System.Web.HttpContext and pass it to the
using Peachpie.RequestHandler; new RequestHandler().ProcessRequest( httpContext );
The code above lazily loads PHP library assemblies (e.g.
MyWebsite.dll) and looks up the compiled script corresponding to a given
httpContext. If it is found, it gets included and processed.