iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🌿

NativePHP for Desktop Officially Released: Installation and First Look

に公開

Introduction

Version 1.0.0 of NativePHP for desktop was officially released in April 2025 🎉

https://github.com/orgs/NativePHP/discussions/547

https://nativephp.com/docs/desktop/1/getting-started/releasenotes

I tried it out when the alpha version was released, but I couldn't get it to work no matter what, so I'm taking another shot at it this time!

https://zenn.dev/naopusyu/scraps/902dec44c5bb78

Installation

I will proceed with the installation steps as described in the documentation.

https://nativephp.com/docs/desktop/1/getting-started/installation

The required environment is as follows:

  1. PHP 8.3+
  2. Laravel 11 or higher
  3. Node 22+
  4. Windows 10+ / macOS 12+ / Linux

My local environment is as follows, so it should be fine:

  • PHP 8.4.6
  • Laravel 12.10.2
  • Node 23.11.0
  • macOS 15.4.1

Installing NativePHP

NativePHP is installed as a package using Composer.

composer require nativephp/electron

After the installation is complete, run the NativePHP installer.

php artisan native:install

When executed, the following logs will appear.

Service providers and config files are created.

  Publishing NativePHP Service Provider...

   INFO  Publishing [nativephp-provider] assets.

  Copying file [vendor/nativephp/laravel/resources/stubs/NativeAppServiceProvider.php.stub] to [app/Providers/NativeAppServiceProvider.php] ... DONE

   INFO  Publishing [nativephp-config] assets.

  Copying file [vendor/nativephp/laravel/config/nativephp.php] to [config/nativephp.php] ...................................................... DONE

 Installing `composer native:dev` script alias...

 native:dev script installed!

You will be asked whether to install the NativePHP NPM dependencies, so answer Yes.

 Would you like to install the NativePHP NPM dependencies? ───┐
 Yes
 └──────────────────────────────────────────────────────────────┘

Once everything is installed, it finally asks if you want to start the development server. Since it's right after installation, you can choose Yes to start it, but I'll choose No for now.

 Would you like to start the NativePHP development server ────┐
 No
 └──────────────────────────────────────────────────────────────┘

  NativePHP scaffolding installed successfully. 

This completes the installation.

Starting the Development Server

Choosing Yes earlier would execute the same command, but you can start the development server manually by running:

php artisan native:serve

If the installation was successful, a window like this should launch. 🎉

Note: The window size in the image above has been adjusted for better visibility.

Trying It Out

You can do various things by modifying the boot method of app/Providers/NativeAppServiceProvider.php, which was copied during installation.

Note: The following is the original source for NativeAppServiceProvider.php:

https://github.com/NativePHP/laravel/blob/1.0.0/resources/stubs/NativeAppServiceProvider.php.stub

Tweaking the Window

If you launch it without any changes, the default window size is 400 for both width and height, which is a bit narrow. (I manually changed the size in the earlier screenshot for better visibility.)

The definition is located around here:

https://github.com/NativePHP/laravel/blob/1.0.0/src/Concerns/HasDimensions.php#L7-L9

So, first, I would like to change this size.

It's easy to change: just call the width and height methods after executing Window::open().

Window::open()
    ->width(1000)
    ->height(700);

Next is the content to be displayed.
In the source code, the content is set around here:

https://github.com/NativePHP/laravel/blob/1.0.0/src/Windows/Window.php#L67-L73

  • $this->title is the window title
  • $this->url is the content to display (defaults to the Laravel welcome page)
  • $this->showDevTools toggles the browser developer tools

These can also be modified with specific methods after calling Window::open().

Window::open()
    ->title("Nao's Article List")   // Window title
    ->url('https://zenn.dev/naopusyu') // Content to display
    ->showDevTools(false); // Hide developer tools

Adding these changes to the boot method of app/Providers/NativeAppServiceProvider.php looks like this:

    public function boot(): void
    {
        Window::open()
             ->width(1000)
             ->height(700)
             ->title("Nao's Article List")
             ->url('https://zenn.dev/naopusyu')
             ->showDevTools(false);
    }

Restarting the app in this state looks like this:

Summary

Since it has been officially released, I gave it a quick try. It feels like a unique experience to build desktop applications using PHP.

I plan to continue exploring NativePHP at my own pace, as I expect it will become capable of even more in the future.

GitHubで編集を提案

Discussion