Build Native Desktop Apps with PHP Using NativePHP – A Step‑by‑Step Guide
This guide explains how to set up the required environment, clone the example repository, install backend and frontend dependencies, run development mode, build a native executable, and troubleshoot common errors when using NativePHP to create PHP‑based desktop applications.
Overview
NativePHP compiles PHP code into native binaries, allowing developers to create desktop applications that run directly on the OS without a web server or interpreter. The first stable desktop version (V1.0) was released on 2025‑04‑13.
Environment Requirements
PHP 8.3+
Laravel 11 or newer
Node 22+
Windows 10+, macOS 12+, or Linux
The optimal workflow is to run PHP and Node on the development machine.
Note: While you can develop in virtualized or container environments, you may encounter unexpected issues and need extra manual steps.
Example Project
Clone the repository
Official repository:
https://github.com/NativePHP/kitchen-sink git clone [email protected]:NativePHP/kitchen-sink.gitInstall backend dependencies
Run Composer to install required packages: composer install Successful installation shows a list of packages ending with DONE.
Install frontend dependencies
npm iStart development mode
composer native:devWhen the command finishes, you should see output similar to the example, indicating that the Laravel app is running in a native desktop window.
Build for release
php artisan native:buildIf the build succeeds, a dist folder containing an .exe file is created; double‑clicking it runs the desktop application.
Custom Installation
Install NativePHP via Composer: composer require nativephp/electron Or specify a PHP version explicitly:
/usr/local/php-8.3.20/bin/php /home/build/composer.phar require nativephp/electronThen install dependencies and start the app:
php artisan native:install
php artisan native:serveCommon Errors
Q1: MissingAppKey
Run php artisan key:generate and ensure .env contains a valid APP_KEY like APP_KEY=base64:your_key.
Q2: Frontend startup failure
Make sure frontend dependencies are installed: npm i.
Q3: Service startup error about packageManager
Remove the "packageManager" field from package.json and reinstall with npm i.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Tech Hub
Sharing cutting-edge internet technologies and practical AI resources.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
