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.

Prerequisites#

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 can be created and opened by .NET development environments, such as Visual Studio or Visual Studio Code.

Visual Studio#

Visual Studio Code#

  • Open an empty folder.
  • Open Terminal and run the following command:
    dotnet new console -lang PHP
    
  • Start the project by pressing F5 and let VS Code create the initial tasks.json and launch.json files for .NET.
  • Edit launch.json to point to the actual build result.