Running NativePHP on Windows: An Unofficial Developer’s Hack

NativePHP is an innovative approach to building native applications, leveraging the familiar tools of PHP. It revolutionizes the development process by letting you create powerful, native applications using the PHP language and environment you’re already comfortable with. No need for learning new languages or frameworks; with NativePHP, you can directly use your existing PHP skills to build high-performing, native apps. Whether you’re looking to create desktop, mobile, or web applications, NativePHP provides a unified, efficient, and intuitive way to realize your ideas.

If you’re eager to run NativePHP on Windows and can’t wait for the official support, there’s a workaround available. This method lets you bypass the wait and start developing with NativePHP on your Windows machine right away. It’s a practical solution for those who want to take advantage of NativePHP’s capabilities without delay.

Set up NativePHP by following the instructions below.

Install a fresh Laravel instance with the following command:

# Install a new copy of Laravel
laravel new nativephp

Navigate to the directory you just created using the command: cd nativephp

Add the NativePHP package by executing this command:

# Add NativePHP
composer require nativephp/electron

Lastly, initiate the installer by running:

# Run the installer
php artisan native:install

Make a new directory called vendor\nativephp\php-bin\bin\win

Download PHP from https://windows.php.net/download. (I used the VS16 x64 Thread Safe version.)

Unpack the downloaded archive into these two directories:

  • vendor\nativephp\php-bin\bin\win\x86
  • vendor\nativephp\electron\resources\js\resources

Copy the php.ini file into both of the above directories.

Modify the vendor\nativephp\electron\src\Commands\DevelopCommand.php file:

  • Replace all instances of bin/mac with bin/win.

  • If you’re using npm instead of yarn, replace all mentions of yarn with npm

In the vendor\nativephp\electron\resources\js\src\main\index.js file, add .exe after ../../resources/php.

Copy vendor\nativephp\php-bin\cacert.pem to vendor\nativephp\electron\resources\js\resources.

In the vendor\nativephp\electron\resources\js\node_modules\@nativephp\electron-plugin\dist\index.js file, comment out the line app.dock.setIcon(state_1.default.icon);

Finally, execute the command.

# Run the dev server
php artisan native:serve


It’s done !!!

Refeence: https://gist.github.com/ShaneShipston/8bb7cabc423cf0cc64da0eacafa53171

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.