PHP Native - Build desktop apps with PHP and native WebKit.
output.mp4
- Smaller bundle size (~50-100MB vs Electron's ~150MB+)
- Uses native WebKit instead of bundling Chromium
- Write desktop apps in PHP like you'd write web apps
- Works with Laravel, Symfony, or any PHP code
- Proper $_GET, $_POST, $_COOKIE support
- PHP 8.4+
- macOS 11+ (Windows/Linux support coming)
- CMake 3.15+
- Xcode CLI tools
Currently tested and working with:
- Laravel 11 - Not fully working. WIP
- Plain PHP - Works with any standard PHP application
Other frameworks like Symfony, CodeIgniter, and Slim should work but haven't been tested yet. Let me know if you try one!
Clone and build:
git clone https://github.com/phpn/phpn.git
cd phpn
./bin/phpn buildRun the example:
./bin/phpn run examples/test-app/public/index.phpInstall:
composer require --dev phpn/phpnRun (downloads prebuilt runtime automatically on first use):
php artisan desktop:serveBundle as .app:
php artisan desktop:bundle "My App"
php artisan desktop:bundle --icon=resources/icon.icnsOr just use the binary:
vendor/bin/phpn run public/index.php --width=1200 --height=800
vendor/bin/phpn bundle . "My App" --icon=icon.icns<?php
// app.php
$name = $_GET['name'] ?? 'World';
?>
<!DOCTYPE html>
<html>
<body>
<h1>Hello <?= htmlspecialchars($name) ?>!</h1>
<p>PHP <?= phpversion() ?></p>
</body>
</html>./bin/phpn run app.phpPHPN embeds PHP's SAPI library and runs your PHP code, then displays the output in a native WebKit view. Request data ($_GET, $_POST, etc.) gets populated from the URL bar, so your existing routing works.
The native/macos folder has the Objective-C code for the window. The shared folder has the C code that talks to PHP. When you run a file, it spins up PHP, executes your code, and renders the HTML output.
Set defaults in config/phpn.php or pass CLI options:
./bin/phpn run app.php --width=1600 --height=1000 --title="My App"- Cmd+Q: Quit
- Cmd+W: Close window
- Cmd+R: Reload
- Cmd+C/V/X/A: Copy/Paste/Cut/Select All
Create a standalone macOS app:
# Using phpn
./bin/phpn bundle examples/test-app "My App Name"
# With Laravel
php artisan desktop:bundle "My App"
php artisan desktop:bundle --icon=resources/icon.icnsWith a custom icon:
./bin/phpn bundle ./my-app "My App" --icon=icon.icnsThe bundled app will be in native/macos/build/My App.app (or vendor/phpn/phpn/native/macos/build/ for Laravel projects). You can:
- Double-click to run it
- Move it to Applications folder
- Distribute it (zip or create a DMG)
The bundle includes the PHP runtime and your entire app, so users don't need PHP installed.
The bundling process automatically removes build artifacts from vendor/x0ptr/phpn/. For even smaller bundles:
composer install --no-dev
php artisan desktop:bundle "My App"
composer install You can also exclude unnecessary files by creating a custom bundle script or using .gitattributes export-ignore.
./bin/phpn buildThis compiles PHP with the embed SAPI, builds the native macOS app, and puts everything in native/macos/build/.
Note: On first use, PHPN automatically downloads prebuilt binaries from GitHub releases. Building from source is only needed if you're developing PHPN itself or if no prebuilt binary is available for your platform.
To create a release with prebuilt binaries:
git tag v1.0.0
git push origin v1.0.0GitHub Actions will automatically build and upload binaries for macOS (and Linux when implemented).
Or manually create archives:
cd native
./create-release.sh 1.0.0Then upload the archives in native/dist/ to the GitHub release.
- macOS only right now (planning Windows/Linux)
- No system dialogs yet (file open/save)
- JavaScript bridge is basic
- Single window only
Electron bundles an entire Chromium browser. PHPN uses the WebKit that's already on your Mac. A typical bundle is 50-100MB (mostly your app + PHP runtime + dependencies) instead of 150MB+ with Electron.
Also I like PHP.
MIT - See LICENSE file for details.
- Menu bar integration
- Windows support (Win32/WebView2)
- Linux support (GTK/WebKitGTK)
- Composer package for easy installation
- macOS 11.0+
- Xcode Command Line Tools
- CMake 3.15+
- pkg-config, libxml2, sqlite (via Homebrew)
- macOS 11.0+
- Bundled PHP runtime (included in built app)
MIT
- Electron - Desktop apps with web technologies
- Tauri - Lightweight Electron alternative (Rust)
- Neutralinojs - Lightweight cross-platform apps
- PHP Desktop - PHP desktop apps (older)
Contributions welcome! This is an early-stage project.
- Fork the repository
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a Pull Request