How to Build a Mobile App with NativePHP and Laravel

Learning complex frameworks like Flutter or React Native for mobile app development is a bit challenging, but what if you can build mobile apps using Laravel—the framework you already know?

Laravel comes with a framework called NativePHP, which is used for building mobile and desktop apps. Building a mobile app with NativePHP is now completely free, which was announced by the NativePHP team.

In this article, we will discuss a step-by-step guide on how to build a mobile app using NativePHP in Laravel. We will know the definition, prerequisites, and process, whether you're a beginner or an experienced Laravel developer.

How to Build a Mobile App with NativePHP and Laravel

What is NativePHP?

NativePHP is an open-source and PHP-based framework that developers use to build mobile and desktop applications using Laravel. It uses Electron.js for creating cross-platform desktop applications, and for mobile app development, it uses native wrappers.

Key Features of NativePHP

NativePHP comes with some key features that make it a powerful tool for building mobile and desktop applications:

  • Cross platform: NativePHP allows developers to build applications that run on multiple platforms, including Windows, macOS, Andoird and iOS.
  • Laravel Based: NativePHP is based on Larevl so you do not need to learn other complex frameworks like flutter and React Native/
  • No Web Server Required: NativePHP applications do not require any web server to run as it runs entirely on-device.

Limitation of NativePHP

  • Only SQLite is supported: NativePHP currently only supports SQLite databases, which may limit its use in more complex applications.
  • Bugs: NativePHP is still in its early stages, so develpers may face bugs or performance issues.
  • Size : NativePHP applications can be larger in size as it use Electronjs.

Prerequisites of NativePHP for mobie app development

Before getting started with NativePHP make sure you fulfill the below reuirment :

  • PHP 8.3 or higher: NativePHP requires PHP 8.3 or higher to run.
  • Laravel 11 or higher: Going forward NativePHP requires Laravel 11. NativePHP support for Laravel 10 is no longer available as it was for the NativePHP v1 release.
  • Node.js 22 or higher: NativePHP requires Node.js 22 or higher to run.
  • Android Studio: For Android app development, you will need Android Studio installed.
  • Xcode: For iOS app development, you will need Xcode installed.

Step By Step Guide to Build Mobile App with NativePHP and Laravel

Follow the steps below to create your first mobile application using NativePHP and Laravel:

Step 1: Create a Laravel Project

Create a fresh Laravel application using Composer:

# Create a new Laravel project
composer create-project laravel/laravel nativephp-app

# Move into project directory
cd nativephp-app

Step 2: Add NativePHP Repository

Update your composer.json file and add the NativePHP repository:

"repositories": [
    {
        "type": "composer",
        "url": "https://nativephp.composer.sh"
    }
]

Step 3: Set App Identifier

Now set your app identifier inside the .env file:

NATIVEPHP_APP_ID=com.example.myapp

Step 4: Install NativePHP

Install NativePHP mobile package:

# Install NativePHP mobile package
composer require nativephp/mobile

Step 5: Setup NativePHP

Run the install command to publish configuration and prepare your app:

# Setup NativePHP
php artisan native:install

Step 6: Run Mobile App

Run your app on a connected device or emulator:

# Run the mobile application
php artisan native:run

Step 7: Build Production App

When your app is ready, generate a production build for Play Store or App Store:

# Create production build
php artisan native:package android --build-type=release

# Save build to custom directory
php artisan native:package android --build-type=release --output=./builds

# Skip preparation (useful for CI/CD)
php artisan native:package android --build-type=release --skip-prepare

Frequently Asked Questions

What is the difference between PHP and native PHP?+
Is native PHP free or paid?+