NativePHP: What is it and how to Use it?

In a world dominated by JavaScript, Swift, Kotlin, and heavy frameworks, NativePHP emerges as a breath of innovation for PHP developers. This tool allows you to create native applications for desktop and mobile using the same language and tools you already master — without leaving your PHP/Laravel ecosystem. If your dream is to transform your web projects into real native apps, this tutorial is for you!
What is NativePHP?
NativePHP is a modern framework that combines:
- Simple and intuitive classes to access operating system resources natively (such as windows, menus, notifications, files, and more).
- Building and packaging tools — like Electron, which is widely used and has broad support, or Tauri, which stands out for generating lighter desktop applications with lower memory consumption — seamlessly integrated.
- A static PHP runtime that embeds the PHP interpreter inside the app, allowing distribution without requiring PHP installed on the user’s system.
You continue writing code in PHP (Laravel or pure), Blade, Inertia, Livewire, etc., and get a cross-platform native application ready to use.
Usage Requirements (Desktop)
Before starting, make sure you have installed in your environment:
- PHP 8.1+
- Composer
- Node.js and npm (for asset building)
- Laravel (v10+ recommended)
- Git
- Electron/Tauri dependency
Usage Tutorial (Desktop)
1. Create (or Use) a Laravel Project
Open your terminal and create a new Laravel project (or use an existing one):
composer create-project laravel/laravel meu-app-native
cd meu-app-native
Verify if the server is running:
php artisan serve
If you access http://localhost:8000, you’ll see Laravel running normally.
2. Install NativePHP (Desktop via Electron)
Add the NativePHP package:
composer require nativephp/electron
Then run the installation command:
php artisan native:install
This command will:
- Prepare the Electron boilerplate.
- Create the
.nativephp/folder with app configurations. - Add necessary dependencies.
3. Run and Test the Application
Now, just run:
php artisan native:serve
Laravel will start in the background and open a native window using Electron, displaying your application. You’re no longer in the browser: it’s a real desktop application.
4. Create a Custom Window
NativePHP allows you to control how your window opens.
Edit the app/Providers/NativeAppServiceProvider.php file:
use Native\Laravel\Facades\Window;
public function boot()
{
Window::open()
->title('Meu Primeiro App Nativo')
->width(1024)
->height(768)
->resizable()
->centerOnScreen();
}
5. Add a Native Menu
You can create menus similar to any desktop app:
use Native\Laravel\Facades\Menu;
use Native\Laravel\Menu\MenuItem;
public function boot()
{
$menu = Menu::new()
->appMenu()
->submenu('Arquivo', [
MenuItem::label('Abrir')->event('arquivo.abrir'),
MenuItem::label('Salvar')->event('arquivo.salvar'),
MenuItem::label('Sair')->quit(),
]);
$menu->register();
}
Now your app will have a “File” menu with options that can trigger events in Laravel.
6. Sending Native Notifications
System notifications can be displayed with a single line:
use Native\Laravel\Facades\Notification;
Notification::new()
->title('Sucesso!')
->message('Seu app nativo em PHP está rodando.')
->show();Notification::new()
->title('Sucesso!')
->message('Seu app nativo em PHP está rodando.')
->show();
This triggers a notification in the operating system, just like any other application.
7. Distributing your Application
After development, you can package your application:
php artisan native:build
This command generates an executable for the operating system (Windows, macOS, or Linux), with PHP built-in.
You can distribute this file to end users without requiring PHP or Composer installation.
NativePHP on Mobile (iOS and Android)
In addition to supporting desktop applications, NativePHP also allows creating native mobile applications, leveraging the same PHP code from your Laravel backend.
This is possible because NativePHP provides an embedded PHP runtime inside a Swift (iOS) or Kotlin (Android) app. Thus, PHP runs directly on the device, without requiring internet or remote server — ideal for offline-first apps, with full access to system APIs.
Mobile Requirements
- macOS + Xcode (for iOS)
- Android Studio + SDK (for Android)
- PHP 8.1+
- Composer
- Node.js / npm
- Apple Developer account (to distribute on iOS)
- Google Play Console account (to distribute on Android)
Step by Step Guide to Create a Mobile App with NativePHP
1. Install NativePHP Mobile CLI
In your Laravel project, run:
composer require nativephp/mobile
Then initialize the mobile environment:
php artisan native:mobile:install
This will create the necessary structure to generate iOS/Android apps.
2. Create a New Mobile Project
Run the command:
php artisan native:mobile:init
This command generates a wrapper project:
- For iOS, a Swift project with embedded PHP.
- For Android, a Kotlin project with embedded PHP.
These projects are located inside the mobile/ folder and come pre-configured to run your Laravel app.
3. Run the App in Emulator or Device
For iOS:
php artisan native:mobile:serve ios
This will open the Xcode Simulator with your app.
For Android:
php artisan native:mobile:serve android
This will open the Android Studio Emulator or run on the device connected via USB.
4. Using Mobile APIs
Just like on desktop, you can access native mobile features:
use Native\Laravel\Facades\Camera;
$photo = Camera::capture();
$photo->save(storage_path('app/public/foto.jpg'));
Example – Local push notifications:
use Native\Laravel\Facades\Notification;
Notification::new()
->title('Bem-vindo!')
->message('Você abriu o app NativePHP no celular 🚀')
->show();
Example – Biometrics (Face ID / Fingerprint):
use Native\Laravel\Facades\Biometrics;
if (Biometrics::check()) {
echo "Usuário autenticado com biometria!";
}
5. Packaging and Distribution
When development is complete, you can generate distribution builds:
For iOS:
php artisan native:mobile:build ios
For Android:
php artisan native:mobile:build android
These commands generate an .ipa (iOS) or .apk/.aab (Android), ready to be submitted to official stores.
Conclusion
NativePHP opens a new frontier for those who already master PHP and Laravel: creating native applications with access to system resources and distribution as real executables.
- If before it was necessary to learn Swift, Java, or resort to heavy frameworks, now you can just stay in the PHP world.
- The development flow is simple: install, create windows, interact with native APIs, and package.
- The learning curve is low and the benefits are enormous, especially for those who want to reuse code from existing web applications.
If you’ve always wanted to transform your web project into a cross-platform application, NativePHP is a tool that deserves to be on your radar.