8000 Add docs (#43) · SRWieZ/fork-nativephp.com@046abae · GitHub
[go: up one dir, main page]

Skip to content

Commit 046abae

Browse files
authored
Add docs (NativePHP#43)
1 parent bf7f8e0 commit 046abae

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed

public/img/docs/php-binaries.png

64 KB
Loading
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
---
2+
title: PHP Binaries
3+
order: 600
4+
---
5+
# Static PHP
6+
7+
At the heart of NativePHP are the platform-specific, single-file PHP binaries, which are portable, statically-compiled
8+
versions of PHP.
9+
10+
These allow us to ship PHP to a user's device without forcing them to compile from source or manage a sprawling set of
11+
dynamic libraries and configuration files.
12+
13+
It also means that your applications can each use an isolated version of PHP without depending on or interfering with
14+
the version of PHP the user may already have installed on their machine or in another NativePHP app.
15+
16+
The binaries that ship with NativePHP are built to have a _minimal_ set of the most common PHP extensions required to
17+
run almost any web application you can build with Laravel.
18+
19+
One key goal of NativePHP is to maintain feature parity across platforms so that you can reliably distribute your apps
20+
to users on any device. This means that we will only ship PHP with extensions that can be supported across Windows,
21+
macOS and Linux.
22+
23+
On top of this, fewer PHP extensions means a smaller application size and attack surface. Beware that installing more
24+
extensions has both performance & [security](security) implications for your apps.
25+
26+
The extensions that are included in the default binaries are defined in the
27+
[`php-extensions.txt`](https://github.com/NativePHP/php-bin/blob/main/php-extensions.txt) in the `php-bin` repo.
28+
29+
If you think an extension is missing that would make sense as a default extension, feel free to
30+
[make a feature request](https://github.com/nativephp/laravel/issues/new/choose) for it.
31+
32+
## Building custom binaries
33+
34+
NativePHP uses the awesome [`static-php-cli`](https://static-php.dev/) library to build distributable PHP binaries.
35+
36+
You may use this too to build your own binaries. Of course, you may build static binaries however you prefer.
37+
38+
Whichever method you use, you should aim to create a single-file executable that has statically linked all of its
39+
dependencies for each platform and architecture that you wish your app to run on.
40+
41+
### Building apps with custom binaries
42+
43+
In order to use your custom binaries, you will need to instruct NativePHP where to find them.
44+
45+
To do this, you may use the `NATIVEPHP_PHP_BINARY_PATH` environment variable. You can set this in your `.env` file.
46+
For example, if you store the binaries in a `bin` folder in the root of your application:
47+
48+
```dotenv
49+
NATIVEPHP_PHP_BINARY_PATH=/path/to/your-nativephp-app/bin/
50+
```
51+
52+
The binaries you are using need to be stored in a structure that mirrors the folder structure found in the `php-bin`
53+
package:
54+
55+
![PHP binary folder structure](/img/docs/php-binaries.png)
56+
57+
Note how the platform is the first folder (`linux`, `mac`, `win`) and the architecture is provided as a subfolder
58+
(`x64`, `arm64`, `x86`).
59+
60+
You do not need to build binaries for every PHP version or every platform; You only need binaries for the platforms you
61+
wish to support and for the version of PHP that your application requires.
62+
63+
Make sure the binaries are zipped and named like so:
64+
65+
```shell
66+
php-[PHP_MAJOR_VERSION].[PHP_MINOR_VERSION].zip
67+
```
68+
69+
NativePHP will then build your application using the relevant binaries found in this custom location.
70+
71+
## A note on safety & support
72+
73+
When using custom binaries, you should make every reasonable effort to secure your build pipeline so as not to allow an
74+
attacker to introduce vulnerabilities into your PHP executables.
75+
76+
Further, any apps that use custom binaries will not be eligible for support via GitHub Issues.

0 commit comments

Comments
 (0)
0