How To Run PHP Codes on .NET Core

Ajiboye Temitope Tayomi
3 min readAug 10, 2018

--

Before, it was near impossible to run your PHP codes on .NET platforms, if you could, it would be such a big headache. Now, you can run PHP Codes on .NET Core using a PHP compiler like Peachpie. Peachpie allows you to run existing PHP applications with the performance, speed, security and interoperability of .NET

Peachpie is an open source PHP compiler to .NET. Peachpie has the ability to seamlessly interoperate between PHP and .NET.

Let’s get started running your first PHP project on .NET Core.

  1. First, you will need to install PeachPie Templates using this command dotnet new -i Peachpie.Templates::*
installing peachpie templates

2. Once your installation is complete, create a new project using the command dotnet new web -lang PHP

The command creates the project files your solution needs.

3. Navigate to the server folder, this is where you will run the server. Use the command,

cd server

4. Now, we need to start the server using the command

dotnet run

This may likely give you an error CS0234. Refer to the image below.

Here is how I solved it.

Open the newly created solution in Visual Studio Code or Visual Studio. There are Two folders namely: Server and Website.

Open the server folder and open the file “program.cs”.

Here is a list of errors you will need to fix.

At the top of your “program.cs”, replace

using Peachpie.Web;

with

using Peachpie.AspNetCore.Web;

import Peachpie.AspNetCore.Web

Now run “dotnet run” on your console and your server will start running now. Your app should start running at http://localhost:5004

Hello World on localhost:5004

There you go. That is a simple way to run your PHP codes on .NET Core using PeachPie. Pretty straightforward right?

If you have comments, errors and feedback please post them in the comments and I will respond as fast as possible.

--

--