Skip to content

Commit 33b8ec6

Browse files
committed
Content updates
1 parent a5b784e commit 33b8ec6

File tree

7 files changed

+203
-25
lines changed

7 files changed

+203
-25
lines changed

resources/views/docs/1/digging-deeper/security.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ If your application allows users to connect _their own_ API keys for a service,
3232
care. If you choose to store them anywhere (either in a [File](/docs/digging-deeper/files) or
3333
[Database](/docs/digging-deeper/databases)), make sure you store them encrypted and decrypt them only when in use.
3434

35+
See [Environment Files](/getting-started/env-files#removing-sensitive-data-from-your-environment-files) for details on
36+
how to redact your `.env` files at build-time.
37+
3538
### Files and privileges
3639

3740
Your application runs in a privileged state thanks to the PHP runtime being executed as the user who is currently

resources/views/docs/1/getting-started/configuration.md

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,33 @@ return [
4949
*/
5050
'provider' => \App\Providers\NativeAppServiceProvider::class,
5151

52+
/**
53+
* A list of environment keys that should be removed from the
54+
* .env file when the application is bundled for production.
55+
* You may use wildcards to match multiple keys.
56+
*/
57+
'cleanup_env_keys' => [
58+
'AWS_*',
59+
'GITHUB_*',
60+
'DO_SPACES_*',
61+
'*_SECRET',
62+
'NATIVEPHP_UPDATER_PATH',
63+
'NATIVEPHP_APPLE_ID',
64+
'NATIVEPHP_APPLE_ID_PASS',
65+
'NATIVEPHP_APPLE_TEAM_ID',
66+
],
67+
68+
/**
69+
* A list of files and folders that should be removed from the
70+
* final app before it is bundled for production.
71+
* You may use glob / wildcard patterns here.
72+
*/
73+
'cleanup_exclude_files' => [
74+
'content',
75+
'storage/app/framework/{sessions,testing,cache}',
76+
'storage/logs/laravel.log',
77+
],
78+
5279
/**
5380
* The NativePHP updater configuration.
5481
*/
@@ -62,11 +89,22 @@ return [
6289

6390
/**
6491
* The updater provider to use.
65-
* Supported: "s3", "spaces"
92+
* Supported: "github", "s3", "spaces"
6693
*/
6794
'default' => env('NATIVEPHP_UPDATER_PROVIDER', 'spaces'),
6895

6996
'providers' => [
97+
'github' => [
98+
'driver' => 'github',
99+
'repo' => env('GITHUB_REPO'),
100+
'owner' => env('GITHUB_OWNER'),
101+
'token' => env('GITHUB_TOKEN'),
102+
'vPrefixedTagName' => env('GITHUB_V_PREFIXED_TAG_NAME', true),
103+
'private' => env('GITHUB_PRIVATE', false),
104+
'channel' => env('GITHUB_CHANNEL', 'latest'),
105+
'releaseType' => env('GITHUB_RELEASE_TYPE', 'draft'),
106+
],
107+
70108
's3' => [
71109
'driver' => 's3',
72110
'key' => env('AWS_ACCESS_KEY_ID'),
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
---
2+
title: Debugging
3+
order: 350
4+
---
5+
6+
# When things go wrong
7+
8+
Building native applications is a complex task with many moving parts. There will be errors, crashes and lots of
9+
head-scratching.
10+
11+
NativePHP works to hide much of the complexity, but sometimes you will need go under the hood to find out what's really
12+
going on.
13+
14+
**Remember that NativePHP is a relatively thin layer above a whole ocean of dependencies and tools that are built and
15+
maintained by many developers outside the NativePHP team.**
16+
17+
This means that while some issues can be solved within NativePHP it's also very likely that the problem lies elsewhere.
18+
19+
## The layers
20+
21+
- Your application, built on Laravel, using your local installations of PHP & Node.
22+
- NativePHP's development tools (`native:serve` and `native:build`) manage the Electron/Tauri build processes - this is
23+
what creates your Application Bundle.
24+
- NativePHP moves the appropriate version of a statically-compiled binary of PHP into your application's bundle - when
25+
your app boots, it's _this_ version of PHP that is being used to execute your PHP code, not your system's version of
26+
PHP.
27+
- Electron & Tauri use suites of platform-specific build tools and dependencies - Electron's ecosystem is mostly
28+
Javascript based, Tauri's is mostly Rust based. Much of this will be hidden away in your `vendor` directory.
29+
- The operating system (OS) and its architecture (arch) - you can't build an application for one architecture and
30+
distribute it to a different OS/arch. It won't work. You must build your application to match the OS+arch combination
31+
where you want it to run.
32+
33+
While you are not expected to know in-depth how all of these layers work and fit together, some familiarity with what's
34+
going on will help you find the root cause of issues and be able to raise meaningful tickets with the right people.
35+
36+
## Doing some digging
37+
38+
Here are some tips for debugging:
39+
40+
### Two or three copies
41+
Remember that when a build is generated (dev or prod), your whole Laravel application is _copied into_ the build folder.
42+
43+
The dev build copy is stored in `vendor` (holy inception, Batman!).
44+
45+
Prod builds get packed in the `dist` folder.
46+
47+
This means there are at least 2 versions of your code that could be running depending on what you're doing: the hot code
48+
that you edit in your IDE (your 'development environment') and the bundle code that actually gets executed when your app
49+
runs in either a dev build or a prod build.
50+
51+
Having a clear understanding about what context you're in when issues occur will help you to solve the problem faster.
52+
53+
### Verbose output
54+
Use `-v`, `-vv` or `-vvv` when running `native:serve` or `native:build` as this will provide more detail as to what's
55+
happening at each stage of a process.
56+
57+
### Check the logs
58+
Logs generated by running builds of your application are stored in `{appdata}/storage/logs/`.
59+
60+
Logs generated when running Artisan commands in your development environment are in `storage/logs/` (default Laravel).
61+
62+
### Step out
63+
Try running a step _outside_ of the runtime environment - reduce the layers to rule out environment-specific complications.
64+
65+
### Start from scratch
66+
Don't be afraid to delete builds and start again! The `dist` folder in your application's root may sometimes get into
67+
an unusual state and just needs wiping out.
68+
69+
Make sure there are no lingering processes - check your Activity Monitor/Task Manager to find stray processes that may
70+
hang around after a build has failed, and force them to quit.
71+
72+
### Check your app and PHP
73+
Errors that occur in PHP execution during the application's bootup sequence can cause the app to crash before it even
74+
starts.
75+
76+
A 500 error in your application code, for example, may prevent the main window from showing, but would leave the runtime's
77+
shell process running.
78+
79+
Try booting your application in a standard browser to see if there are any errors when hitting its entrypoint URL. If
80+
you're using Laravel Herd, for example, move your app development environment into your Herd root folder and go to
81+
`http://{your-app-folder-name}.test/` in your favorite browser.
82+
83+
Also make sure that the PHP version in the bundle is the same as the one you have installed on your machine
84+
85+
If you're running PHP8.2 on your machine, the PHP binary that is moved into the `dist` folder should be PHP8.2 for your
86+
current OS+arch. You can check this in the CLI:
87+
88+
#### For dev builds:
89+
M-series (ARM) Mac:
90+
```shell
91+
/path/to/your/app/vendor/nativephp/electron/resources/js/resources/php/php -v
92+
```
93+
Windows:
94+
```shell
95+
C:\path\to\your\app\vendor\nativephp\resources\js\resources\php\php.exe -v
96+
```
97+
98+
#### For production builds:
99+
M-series (ARM) Mac computer:
100+
```shell
101+
/path/to/your/app/dist/mac-arm/AppName/Contents/Resources/app.asar.unpacked/resources/php/php -v
102+
```
103+
104+
Windows:
105+
```shell
106+
C:\path\to\your\app\dist\win-unpacked\resources\app.asar.unpacked\resources\php\php.exe -v
107+
```

resources/views/docs/1/getting-started/development.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,25 @@ order: 300
55

66
# Development
77

8+
```shell
9+
php artisan native:serve
10+
```
11+
812
NativePHP isn't prescriptive about how you develop your application. You can build it in the way you're most comfortable
913
and familiar with, just as if you were building a traditional web application.
1014

1115
The only difference comes in the feedback cycle. Instead of switching to and refreshing your browser, you'll need to
1216
be serving your application using `php artisan native:serve` and refreshing (and in some cases restarting) your
1317
application to see changes.
1418

19+
This is known as 'running a dev build'.
20+
1521
## What does the `native:serve` command do?
1622

1723
The `native:serve` command runs the Electron/Tauri 'debug build' commands, which build your application with various
18-
debug options set to help make debugging easier, such as allowing you to show the Dev Tools.
24+
debug options set to help make debugging easier, such as allowing you to show the Dev Tools in the embedded web view.
1925

20-
It also keeps the connection to the terminal open so you can see and inspect useful output from your app, like logs,
26+
It also keeps the connection to the terminal open so you can see and inspect useful output from your app, such as logs,
2127
in real time.
2228

2329
These builds are unsigned and not meant for distribution. They do not go through various optimizations typically done
@@ -42,7 +48,6 @@ If you're using Vite, hot reloading will just work inside your app as long as yo
4248
[included the Vite script tag](https://laravel.com/docs/vite#loading-your-scripts-and-styles) in your views
4349
(ideally in your app's main layout file).
4450

45-
4651
You can do this easily in Blade using the `@@vite` directive.
4752

4853
Then, in a separate terminal session to your `php artisan native:serve`, from the root folder of your application, run:

resources/views/docs/1/getting-started/env-files.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@ order: 400
55

66
# Environment Files
77

8-
When NativePHP bundles your application, it will copy your entire application directory into the bundle, including your `.env`
9-
file. This means that your `.env` file will be accessible to anyone who has access to your application bundle.
8+
When NativePHP bundles your application, it will copy your entire application directory into the bundle, including your
9+
`.env` file.
1010

11-
You should be careful to not include any sensitive information in your `.env` file, such as API keys or passwords.
12-
Unlike a traditional web application, your `.env` file can be read by anyone who has access to your application bundle.
11+
**This means that your `.env` file will be accessible to anyone who has access to your application bundle.**
12+
13+
So you should be careful to not include any sensitive information in your `.env` file, such as API keys or passwords.
14+
This is quite unlike a traditional web application deployed to a server you control.
1315

1416
If you need to perform any sensitive operations, such as accessing an API or database, you should do so using a
15-
separate API that you create specifically for your application. You can then call this API from your application and
17+
separate API that you create specifically for your application. You can then call _this_ API from your application and
1618
have it perform the sensitive operations on your behalf.
1719

20+
See [Security](/digging-deeper/security) for more tips.
21+
1822
## Removing sensitive data from your environment files
1923

2024
There are certain environment variables that NativePHP uses internally, for example to configure your application's

resources/views/docs/1/getting-started/installation.md

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,56 @@ order: 100
55

66
# Requirements
77

8-
1. PHP 8.1
8+
1. PHP 8.1+
99
2. Laravel 10 or higher
10-
3. NPM
11-
4. Linux/MacOS
10+
3. Node 20+
11+
4. Windows 10+ / macOS 12+ / Linux
1212

13-
# Installation
13+
## PHP & Node
1414

15-
```bash
16-
composer require nativephp/electron
17-
```
15+
The best development experience for NativePHP is to have PHP and Node running on your development machine directly.
1816

19-
# Install Laravel
17+
If you're using Mac or Windows, the most painless way to get PHP and Node up and running on your system is with
18+
[Laravel Herd](https://herd.laravel.com). It's fast and free!
2019

21-
NativePHP is a Laravel Package. You can install it on an existing Laravel application, or [start a new one](https://laravel.com/docs/10.x/installation)
20+
Please note that, whilst it's possible to develop and run your application from a virtualized environment or container,
21+
you may encounter more unexpected issues and have more manual steps to create working builds.
2222

23+
## Laravel
2324

24-
# Run the installer
25+
NativePHP is built to work best with Laravel. You can install it into an existing Laravel application, or
26+
[start a new one](https://laravel.com/docs/10.x/installation).
2527

26-
The NativePHP installer takes care of publishing the NativePHP service provider, which takes care of bootstrapping your
27-
native application. It also publishes the NativePHP configuration file.
28+
## Install a NativePHP runtime
29+
30+
```bash
31+
composer require nativephp/electron
32+
```
33+
34+
The Tauri runtime is coming soon.
35+
36+
## Run the NativePHP installer
2837

2938
```bash
3039
php artisan native:install
3140
```
3241

33-
# Start the development server
42+
The NativePHP installer takes care of publishing the NativePHP service provider, which bootstraps the necessary
43+
dependencies for your application to work with the runtime you're using: Electron or Tauri. It also publishes the
44+
NativePHP configuration file to `config/nativephp.php`.
45+
46+
Finally, it installs any other dependencies needed for the specific runtime you're using, e.g. for Electron it installs
47+
the NPM dependencies.
48+
49+
**Whenever you set up NativePHP on a new machine or in CI, you should run the installer to make sure all of the
50+
necessary dependencies are in place to build your application.**
51+
52+
## Start the development server
3453

3554
```bash
3655
php artisan native:serve
3756
```
3857

39-
And that's it! You should now see your application running in a native desktop window.
58+
This spins up a development build of your application for local testing.
59+
60+
And that's it! You should now see your Laravel application running in a native desktop window.

resources/views/docs/1/getting-started/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ makes you and your team feel most productive.
3636
Building a React front-end? No problem. Vue? Sure. Livewire or Inertia? Doesn't matter! Plain old HTML and CSS?
3737
You got it. Tailwind? Bootstrap? Material UI? Whatever you want.
3838

39-
NativePHP is not some new custom fork of PHP. This is the good old PHP you know and love.
39+
NativePHP is not some new custom fork of PHP. This is the good new PHP you know and love.
4040

4141
## What's in the box?
4242

@@ -65,7 +65,7 @@ that puts cowboy hats on every smiley-face emoji it sees.
6565
Go read the docs! We've tried to make them as comprehensive as possible, but if you find something missing, please
6666
feel free to [contribute](https://github.com/nativephp/nativephp.com).
6767

68-
This site and all the NativePHP are open source and available on [GitHub](https://github.com/nativephp).
68+
This site and all the NativePHP repositories are open source and available on [GitHub](https://github.com/nativephp).
6969

7070
Ready to jump in? [Let's get started](installation).
7171

0 commit comments

Comments
 (0)