Files
static-php-cli/assets/en_guide_index.md.Chrx4Kg2.js

2 lines
6.3 KiB
JavaScript
Raw Normal View History

import{_ as t,c as a,o as i,aj as o}from"./chunks/framework.C2AwuPrQ.js";const u=JSON.parse('{"title":"Guide","description":"","frontmatter":{},"headers":[],"relativePath":"en/guide/index.md","filePath":"en/guide/index.md"}'),r={name:"en/guide/index.md"};function n(s,e,l,h,c,d){return i(),a("div",null,[...e[0]||(e[0]=[o('<h1 id="guide" tabindex="-1">Guide <a class="header-anchor" href="#guide" aria-label="Permalink to “Guide”"></a></h1><div class="warning custom-block"><p class="custom-block-title custom-block-title-default">WARNING</p><p>You are reading the documentation for StaticPHP v3. The v2 version will be deprecated after the stable release of v3. The 3.0 version is currently in the alpha stage, and you can view the v2 documentation <a href="https://static-php.github.io/v2-docs/" target="_blank" rel="noreferrer">here</a>.</p></div><h2 id="what-is-staticphp" tabindex="-1">What is StaticPHP? <a class="header-anchor" href="#what-is-staticphp" aria-label="Permalink to What is StaticPHP?"></a></h2><p>StaticPHP is a build tool that compiles the PHP interpreter together with any extensions you need into a single self-contained binary. The target system doesn&#39;t need PHP or any runtime libraries installed just copy the binary and run it. Builds target Linux, macOS, and Windows.</p><p>StaticPHP isn&#39;t limited to PHP. Built on the same infrastructure, it can also compile standalone static binaries for common tools like <code>curl</code>, <code>pkg-config</code>, and <code>htop</code> no dependencies required on the target machine. Support for more tools (including <code>openssl</code> and other frequently-used CLI utilities) is planned.</p><h2 id="why-bother-with-a-static-php-binary" tabindex="-1">Why bother with a static PHP binary? <a class="header-anchor" href="#why-bother-with-a-static-php-binary" aria-label="Permalink to Why bother with a static PHP binary?"></a></h2><p>A typical PHP installation is tightly coupled to the system: you install PHP, then extensions, then spend time dealing with version mismatches across distros. A static binary sidesteps all of that what you get is a single executable that runs on any machine of the same architecture, no setup required.</p><p>Common use cases:</p><ul><li><strong>Distributing CLI tools</strong> Ship tools like Composer, PHPStan, or your own CLI as a single file. Users don&#39;t need PHP installed.</li><li><strong>Leaner containers</strong> Replace a bloated <code>php:8.x</code> base image with a minimal image (or even <code>FROM scratch</code>) carrying just a static binary.</li><li><strong>Server applications</strong> Build a static binary with FPM or FrankenPHP baked in. Deployment becomes a file copy, with no dependency on the host environment.</li></ul><h2 id="phpmicro-ship-php-and-your-code-as-one-file" tabindex="-1">phpmicro: ship PHP and your code as one file <a class="header-anchor" href="#phpmicro-ship-php-and-your-code-as-one-file" aria-label="Permalink to phpmicro: ship PHP and your code as one file"></a></h2><p><a href="https://micro.static-php.dev" target="_blank" rel="noreferrer">phpmicro</a> is a third-party PHP SAPI that StaticPHP supports out of the box. It merges the PHP interpreter with your <code>.php</code> source or <code>.phar</code> archive into a single self-extracting executable (<code>.sfx</code>).</p><div class="language-"><button title="Copy Code" class="copy"></button><span class="lang"></span><pre class="shiki shiki-themes github-light github-dark" style="--shiki-light:#24292e;--shiki-dark:#e1e4e8;--shiki-light-bg:#fff;--shiki-dark-bg:#24292e;" tabindex="0" dir="ltr"><code><span class="line"><span>micro.sfx + your-app.phar = your-app # one file, zero dependencies</span></span></code></pre></div><p>This is ideal for distributing PHP-based CLI tools: the end user just gets an ordinary executable with no idea PHP is involved.</p><h2 id="improving-how-you-ship-and-deploy-php-projects" tabindex="-1">Improving how you ship and deploy PHP projects <a class="header-anchor" href="#impr