Self-contained executable#
Note
Get access to the PeachPie Sdk first. See download page for details.
To create a self-contained PHP executable, start with a console application, e.g.:
<?php
echo "Hello world!";
and a corresponding project file indicating that the output should be exe:
<Project Sdk="Peachpie.NET.Sdk/1.1.4">
<PropertyGroup>
<OutputType>exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<StartupObject>main.php</StartupObject>
</PropertyGroup>
<ItemGroup>
<Compile Include="**/*.php" />
</ItemGroup>
</Project>
Now compile your project into binaries using the following command:
dotnet publish -c release
This will publish the resulting binaries into the /bin/release/netcoreapp3.1/publish
folder.
As the final step, select an operating system to target, e.g.
dotnet publish -c release -r win-x64
for 64-bit Windows, or
dotnet publish -c release -r linux-x64
for Linux.
This creates a self-contained executable PHP application targeting the operating system of your choice.
Size considerations#
A few tips on how to minimize the size of the resulting application:
- On Linux, you can get rid of culture-specific functionalities and keep just the "Invariant" culture features (cuts about 26MB of data). More detail at globalization-invariant-mode.md.
- Use
dotnet-warp
to merge DLL files and remove unnecessary IL and methods. More info can be found at hanselman.com.
Note
Rename the project file so that it has the .csproj
extension, it will work just fine.