Skip to content

Get started#

The purpose of this page is to get you started with PeachPie quickly. The following steps let you to create a minimalistic project containing PHP files and then compile and run them on top of .NET Core.


Install dotnet templates#

Open a command prompt and run the following command:

install dotnet templates

dotnet new -i Peachpie.Templates::*

The dotnet command downloads the latest project template to be used to create new PeachPie projects for you.

Create your app#

The following steps create a new project in the current directory. They come with a simple hello world code.

Console Application#

The easiest way to start is to create a console application with PHP code. Open the command prompt and run the following commands:

create and run console project

dotnet new console -lang PHP
dotnet run

The first run takes a few seconds, since it will download all the dependencies for the first time and compile the project.

Web Application#

The second option is to create an ASP.NET Core application that runs a website with compiled PHP. Open the command prompt in a new directory and run the following commands:

create and run web project

dotnet new web -lang PHP
dotnet run -p Server

The dotnet new command creates a new project and downloads all the necessary dependencies. The application then compiles and runs a built-in web server on http://localhost:5004. You can access the page in the browser and see the result of index.php.

The newly created web application actually consists of two projects - Server and Website. The first one is a C# .NET Core app that initializes the web server and passes requests to scripts in the second project. You can integrate this solution with a regular .NET Core MVC application with your additional configuration.

Class Library#

The third project type is a class library. The following command creates a project that builds a .dll file out of your PHP files to be used as a library that can be referenced by other projects - either C# or other PHP projects.

create and build class library project

dotnet new classlib -lang PHP
dotnet build

This kind of project can be used purely as a dependency to other projects. The contained classes and interfaces are exposed as regular .NET types. The included script files and global functions are also accessible, either by the PeachPie API or seamlessly within another PHP project that references this library.

Development Environment#

Projects created by the steps above can be opened by .NET development environments, such as Visual Studio 2017 or newer or Visual Studio Code. There are a few additional steps necessary to do so, however.

Visual Studio Code#

  • Install PeachPie for VS Code extension.
  • Open the folder with your PHP project.
  • Start the project by pressing F5 and let VSCode create the initial tasks.json and launch.json files for .NET Core.
  • Edit launch.json to point to the actual build result.

The steps above add support for PeachPie diagnostics and breakpoints in PHP code within a PHP project. The building and debugging of the application is handled by the .NET runtime and debugger.

Visual Studio#

no additional steps needed