mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-02 22:35:43 +08:00
Compare commits
4 Commits
2.8.3
...
bash-versi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cecf204f7b | ||
|
|
8391d3a60c | ||
|
|
1a516a13dd | ||
|
|
62bee67274 |
@@ -1,16 +0,0 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
charset = utf-8
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
indent_size = 2
|
||||
|
||||
[*.{yml,yaml,vue,ts}]
|
||||
indent_size = 2
|
||||
15
.github/FUNDING.yml
vendored
15
.github/FUNDING.yml
vendored
@@ -1,15 +0,0 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: [crazywhalecc]# Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
# ko_fi: crazywhalecc # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
|
||||
# noinspection YAMLSchemaValidation
|
||||
buy_me_a_coffee: # crazywhalecc
|
||||
custom: 'https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md' # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
||||
17
.github/ISSUE_TEMPLATE/bug_report.md
vendored
17
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@@ -1,17 +0,0 @@
|
||||
---
|
||||
name: Bug report
|
||||
about: Build PHP or library failed, download failed, doesn't seem to work...
|
||||
title: ''
|
||||
labels: bug
|
||||
body:
|
||||
- type: textarea
|
||||
id: what-happened
|
||||
attributes:
|
||||
label: What happened?
|
||||
description: |
|
||||
Please tell us what you do, what you get and what you expected.
|
||||
Provide with some step-by-step instructions to reproduce the issue.
|
||||
If possible, attach a screenshot or log files in ./log directory.
|
||||
validations:
|
||||
required: true
|
||||
---
|
||||
8
.github/ISSUE_TEMPLATE/feature_request.md
vendored
8
.github/ISSUE_TEMPLATE/feature_request.md
vendored
@@ -1,8 +0,0 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: new feature
|
||||
assignees: crazywhalecc
|
||||
|
||||
---
|
||||
10
.github/ISSUE_TEMPLATE/something-want-to-know.md
vendored
10
.github/ISSUE_TEMPLATE/something-want-to-know.md
vendored
@@ -1,10 +0,0 @@
|
||||
---
|
||||
name: Something want to know
|
||||
about: Describe your question about static-php, we will reply ASAP
|
||||
title: ''
|
||||
labels: question
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
|
||||
17
.github/pull_request_template.md
vendored
17
.github/pull_request_template.md
vendored
@@ -1,17 +0,0 @@
|
||||
## What does this PR do?
|
||||
|
||||
|
||||
|
||||
## Checklist before merging
|
||||
|
||||
> If your PR involves the changes mentioned below and completed the action, please tick the corresponding option.
|
||||
> If a modification is not involved, please skip it directly.
|
||||
|
||||
- If you modified `*.php` or `*.json`, run them locally to ensure your changes are valid:
|
||||
- [ ] `composer cs-fix`
|
||||
- [ ] `composer analyse`
|
||||
- [ ] `composer test`
|
||||
- [ ] `bin/spc dev:sort-config`
|
||||
- If it's an extension or dependency update, please ensure the following:
|
||||
- [ ] Add your test combination to `src/globals/test-extensions.php`.
|
||||
- [ ] If adding new or fixing bugs, add commit message containing `extension test` or `test extensions` to trigger full test suite.
|
||||
67
.github/workflows/build-php.yml
vendored
Normal file
67
.github/workflows/build-php.yml
vendored
Normal file
@@ -0,0 +1,67 @@
|
||||
name: Build PHP
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
paths:
|
||||
- ".github/workflows/**.yml"
|
||||
- "docker/**"
|
||||
|
||||
jobs:
|
||||
integration:
|
||||
name: Build PHP ${{ matrix.php-versions }} for ${{ matrix.arch }}
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
php-versions: [ "7.4.30", "8.0.23", "8.1.10", "8.2.0" ]
|
||||
arch: [ "x86_64", "aarch64", "armv7l" ]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- name: Check Dockerfile to ${{ matrix.arch }}
|
||||
run: |
|
||||
cd docker/
|
||||
if [[ "${{ matrix.arch }}" != "x86_64" ]]; then
|
||||
if [[ "${{ matrix.arch }}" = "armv7l" ]]; then
|
||||
sed -ie 's/alpine:latest/multiarch\/alpine:armv7-latest-stable/g' Dockerfile
|
||||
else
|
||||
sed -ie 's/alpine:latest/multiarch\/alpine:${{ matrix.arch }}-v3.16/g' Dockerfile
|
||||
fi
|
||||
docker run --rm --privileged multiarch/qemu-user-static:register --reset
|
||||
fi
|
||||
- name: Build micro and PHP distribution ${{ matrix.php-versions }} for ${{ matrix.arch }}
|
||||
id: buildphp
|
||||
run: |
|
||||
cd docker/ && docker build . --tag static-php --build-arg USE_BACKUP_ADDRESS=yes && \
|
||||
mkdir ../dist && \
|
||||
docker run --rm -v $(pwd)/../dist:/dist/ static-php build-php original ${{ matrix.php-versions }} all /dist/
|
||||
- name: Fail if anything failed
|
||||
if: steps.buildphp == 'failure'
|
||||
run: |
|
||||
false
|
||||
- name: Upload Artifacts
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: static-php-cli_${{ matrix.php-versions }}_${{ matrix.arch }}
|
||||
path: |
|
||||
dist
|
||||
- name: Pack PHP ${{ matrix.php-versions }} to archive
|
||||
run: |
|
||||
cd dist
|
||||
tar -zcvf "php-${{ matrix.php-versions }}-static-bin-${{ matrix.arch }}.tar.gz" ./php && rm ./php
|
||||
if [ -f "./micro.sfx" ]; then
|
||||
tar -zcvf "micro-${{ matrix.php-versions }}-${{ matrix.arch }}.tar.gz" ./micro.sfx && rm ./micro.sfx
|
||||
fi
|
||||
- name: Deploy to Zhamao Server
|
||||
uses: easingthemes/ssh-deploy@main
|
||||
env:
|
||||
SSH_PRIVATE_KEY: ${{ secrets.DEPLOY_SERVER_SECRET_KEY }}
|
||||
ARGS: "-rltgoDzvO"
|
||||
SOURCE: "dist/"
|
||||
REMOTE_HOST: ${{ secrets.DEPLOY_SERVER_HOST }}
|
||||
REMOTE_PORT: ${{ secrets.DEPLOY_SERVER_PORT }}
|
||||
REMOTE_USER: ${{ secrets.DEPLOY_SERVER_USER }}
|
||||
TARGET: ${{ secrets.DEPLOY_SERVER_TARGET }}
|
||||
- name: Remove dist directory
|
||||
run: |
|
||||
rm -rf dist/
|
||||
docker images | grep -v REPOSITORY | awk '{print $3}' | xargs docker rmi --force
|
||||
335
.github/workflows/build-unix.yml
vendored
335
.github/workflows/build-unix.yml
vendored
@@ -1,335 +0,0 @@
|
||||
name: "CI on Unix"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
os:
|
||||
required: true
|
||||
description: Build target OS
|
||||
default: 'linux-x86_64'
|
||||
type: choice
|
||||
options:
|
||||
- 'linux-x86_64'
|
||||
- 'linux-aarch64'
|
||||
- 'linux-x86_64-glibc'
|
||||
- 'linux-aarch64-glibc'
|
||||
- 'macos-x86_64'
|
||||
- 'macos-aarch64'
|
||||
php-version:
|
||||
required: true
|
||||
description: PHP version to compile
|
||||
default: '8.4'
|
||||
type: choice
|
||||
options:
|
||||
- '8.4'
|
||||
- '8.3'
|
||||
- '8.2'
|
||||
- '8.1'
|
||||
extensions:
|
||||
description: Extensions to build (comma separated)
|
||||
required: true
|
||||
type: string
|
||||
shared-extensions:
|
||||
description: Shared extensions to build (optional, comma separated)
|
||||
type: string
|
||||
extra-libs:
|
||||
description: Extra libraries to build (optional, comma separated)
|
||||
type: string
|
||||
build-cli:
|
||||
description: Build cli binary
|
||||
default: true
|
||||
type: boolean
|
||||
build-micro:
|
||||
description: Build phpmicro binary
|
||||
type: boolean
|
||||
build-fpm:
|
||||
description: Build fpm binary
|
||||
type: boolean
|
||||
build-frankenphp:
|
||||
description: Build frankenphp binary (requires ZTS)
|
||||
type: boolean
|
||||
default: false
|
||||
enable-zts:
|
||||
description: Enable ZTS
|
||||
type: boolean
|
||||
default: false
|
||||
prefer-pre-built:
|
||||
description: Prefer pre-built binaries (reduce build time)
|
||||
type: boolean
|
||||
default: true
|
||||
with-suggested-libs:
|
||||
description: Build with suggested libs
|
||||
type: boolean
|
||||
default: false
|
||||
debug:
|
||||
description: Show full build logs
|
||||
type: boolean
|
||||
no-strip:
|
||||
description: Keep debug symbols for debugging
|
||||
type: boolean
|
||||
default: false
|
||||
workflow_call:
|
||||
inputs:
|
||||
os:
|
||||
required: true
|
||||
description: Build target OS
|
||||
default: 'linux-x86_64'
|
||||
type: string
|
||||
php-version:
|
||||
required: true
|
||||
description: PHP version to compile
|
||||
default: '8.4'
|
||||
type: string
|
||||
extensions:
|
||||
description: Extensions to build (comma separated)
|
||||
required: true
|
||||
type: string
|
||||
shared-extensions:
|
||||
description: Shared extensions to build (optional, comma separated)
|
||||
type: string
|
||||
extra-libs:
|
||||
description: Extra libraries to build (optional, comma separated)
|
||||
type: string
|
||||
build-cli:
|
||||
description: Build cli binary
|
||||
default: true
|
||||
type: boolean
|
||||
build-micro:
|
||||
description: Build phpmicro binary
|
||||
type: boolean
|
||||
build-fpm:
|
||||
description: Build fpm binary
|
||||
type: boolean
|
||||
build-frankenphp:
|
||||
description: Build frankenphp binary (requires ZTS)
|
||||
type: boolean
|
||||
default: false
|
||||
enable-zts:
|
||||
description: Enable ZTS
|
||||
type: boolean
|
||||
default: false
|
||||
prefer-pre-built:
|
||||
description: Prefer pre-built binaries (reduce build time)
|
||||
type: boolean
|
||||
default: true
|
||||
with-suggested-libs:
|
||||
description: Include suggested libs
|
||||
type: boolean
|
||||
default: false
|
||||
debug:
|
||||
description: Show full build logs
|
||||
type: boolean
|
||||
no-strip:
|
||||
description: Keep debug symbols for debugging
|
||||
type: boolean
|
||||
default: false
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
jobs:
|
||||
define-build:
|
||||
name: "Define Build Scripts"
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
run: ${{ steps.gendef.outputs.run }}
|
||||
download: ${{ steps.gendef.outputs.download }}
|
||||
build: ${{ steps.gendef.outputs.build }}
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Define"
|
||||
id: gendef
|
||||
run: |
|
||||
case "${{ inputs.os }}" in
|
||||
linux-x86_64)
|
||||
DOWN_CMD="./bin/spc-alpine-docker download"
|
||||
BUILD_CMD="./bin/spc-alpine-docker build"
|
||||
RUNS_ON="ubuntu-latest"
|
||||
;;
|
||||
linux-aarch64)
|
||||
DOWN_CMD="./bin/spc-alpine-docker download"
|
||||
BUILD_CMD="./bin/spc-alpine-docker build"
|
||||
RUNS_ON="ubuntu-24.04-arm"
|
||||
;;
|
||||
linux-x86_64-glibc)
|
||||
DOWN_CMD="./bin/spc-gnu-docker download"
|
||||
BUILD_CMD="./bin/spc-gnu-docker build"
|
||||
RUNS_ON="ubuntu-22.04"
|
||||
;;
|
||||
linux-aarch64-glibc)
|
||||
DOWN_CMD="./bin/spc-gnu-docker download"
|
||||
BUILD_CMD="./bin/spc-gnu-docker build"
|
||||
RUNS_ON="ubuntu-22.04-arm"
|
||||
;;
|
||||
macos-x86_64)
|
||||
DOWN_CMD="composer update --no-dev --classmap-authoritative && ./bin/spc doctor --auto-fix && ./bin/spc download"
|
||||
BUILD_CMD="./bin/spc build"
|
||||
RUNS_ON="macos-15-intel"
|
||||
;;
|
||||
macos-aarch64)
|
||||
DOWN_CMD="composer update --no-dev --classmap-authoritative && ./bin/spc doctor --auto-fix && ./bin/spc download"
|
||||
BUILD_CMD="./bin/spc build"
|
||||
RUNS_ON="macos-15"
|
||||
;;
|
||||
esac
|
||||
STATIC_EXTS="${{ inputs.extensions }}"
|
||||
SHARED_EXTS="${{ inputs['shared-extensions'] }}"
|
||||
BUILD_FRANKENPHP="${{ inputs['build-frankenphp'] }}"
|
||||
ENABLE_ZTS="${{ inputs['enable-zts'] }}"
|
||||
ALL_EXTS="$STATIC_EXTS"
|
||||
if [ -n "$SHARED_EXTS" ]; then
|
||||
ALL_EXTS="$ALL_EXTS,$SHARED_EXTS"
|
||||
fi
|
||||
DOWN_CMD="$DOWN_CMD --with-php=${{ inputs.php-version }} --for-extensions=$ALL_EXTS --ignore-cache-sources=php-src"
|
||||
BUILD_CMD="$BUILD_CMD $STATIC_EXTS"
|
||||
if [ -n "$SHARED_EXTS" ]; then
|
||||
BUILD_CMD="$BUILD_CMD --build-shared=$SHARED_EXTS"
|
||||
fi
|
||||
if [ -n "${{ inputs.extra-libs }}" ]; then
|
||||
DOWN_CMD="$DOWN_CMD --for-libs=${{ inputs.extra-libs }}"
|
||||
BUILD_CMD="$BUILD_CMD --with-libs=${{ inputs.extra-libs }}"
|
||||
fi
|
||||
if [ ${{ inputs.debug }} == true ]; then
|
||||
DOWN_CMD="$DOWN_CMD --debug"
|
||||
BUILD_CMD="$BUILD_CMD --debug"
|
||||
fi
|
||||
if [ ${{ inputs.prefer-pre-built }} == true ]; then
|
||||
DOWN_CMD="$DOWN_CMD --prefer-pre-built"
|
||||
fi
|
||||
if [ ${{ inputs.with-suggested-libs }} == true ]; then
|
||||
BUILD_CMD="$BUILD_CMD --with-suggested-libs"
|
||||
fi
|
||||
if [ ${{ inputs.build-cli }} == true ]; then
|
||||
BUILD_CMD="$BUILD_CMD --build-cli"
|
||||
fi
|
||||
if [ ${{ inputs.build-micro }} == true ]; then
|
||||
BUILD_CMD="$BUILD_CMD --build-micro"
|
||||
fi
|
||||
if [ ${{ inputs.build-fpm }} == true ]; then
|
||||
BUILD_CMD="$BUILD_CMD --build-fpm"
|
||||
fi
|
||||
if [ "$BUILD_FRANKENPHP" = "true" ]; then
|
||||
BUILD_CMD="$BUILD_CMD --build-frankenphp"
|
||||
fi
|
||||
if [ "$ENABLE_ZTS" = "true" ]; then
|
||||
BUILD_CMD="$BUILD_CMD --enable-zts"
|
||||
fi
|
||||
echo 'download='"$DOWN_CMD" >> "$GITHUB_OUTPUT"
|
||||
echo 'build='"$BUILD_CMD" >> "$GITHUB_OUTPUT"
|
||||
echo 'run='"$RUNS_ON" >> "$GITHUB_OUTPUT"
|
||||
build:
|
||||
name: "Build ${{ inputs.version }} on ${{ inputs.os }}"
|
||||
runs-on: ${{ needs.define-build.outputs.run }}
|
||||
needs: define-build
|
||||
timeout-minutes: 240
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.4
|
||||
tools: pecl, composer
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
env:
|
||||
phpts: nts
|
||||
|
||||
- if: ${{ inputs['build-frankenphp'] == true }}
|
||||
name: "Install go-xcaddy for FrankenPHP"
|
||||
run: |
|
||||
case "${{ inputs.os }}" in
|
||||
linux-x86_64|linux-aarch64)
|
||||
./bin/spc-alpine-docker install-pkg go-xcaddy
|
||||
;;
|
||||
linux-x86_64-glibc|linux-aarch64-glibc)
|
||||
./bin/spc-gnu-docker install-pkg go-xcaddy
|
||||
;;
|
||||
macos-x86_64|macos-aarch64)
|
||||
composer update --no-dev --classmap-authoritative
|
||||
./bin/spc doctor --auto-fix
|
||||
./bin/spc install-pkg go-xcaddy
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported OS for go-xcaddy install: ${{ inputs.os }}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Cache downloaded source
|
||||
- id: cache-download
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-dependencies-${{ inputs.os }}
|
||||
- name: "Download sources"
|
||||
run: ${{ needs.define-build.outputs.download }}
|
||||
- name: "Build PHP"
|
||||
run: ${{ needs.define-build.outputs.build }}
|
||||
# - name: Setup tmate session
|
||||
# if: ${{ failure() }}
|
||||
# uses: mxschmitt/action-tmate@v3
|
||||
|
||||
# Upload debug logs
|
||||
- if: ${{ inputs.debug && failure() }}
|
||||
name: "Upload build logs on failure"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: spc-logs-${{ inputs.php-version }}-${{ inputs.os }}
|
||||
path: log/*.log
|
||||
|
||||
# Upload cli executable
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
name: "Upload PHP cli SAPI"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-cli-${{ inputs.php-version }}-${{ inputs.os }}
|
||||
path: buildroot/bin/php
|
||||
|
||||
# Upload micro self-extracted executable
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
name: "Upload PHP micro SAPI"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-micro-${{ inputs.php-version }}-${{ inputs.os }}
|
||||
path: buildroot/bin/micro.sfx
|
||||
|
||||
# Upload fpm executable
|
||||
- if: ${{ inputs.build-fpm == true }}
|
||||
name: "Upload PHP fpm SAPI"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-fpm-${{ inputs.php-version }}-${{ inputs.os }}
|
||||
path: buildroot/bin/php-fpm
|
||||
|
||||
# Upload frankenphp executable
|
||||
- if: ${{ inputs['build-frankenphp'] == true }}
|
||||
name: "Upload FrankenPHP SAPI"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-frankenphp-${{ inputs.php-version }}-${{ inputs.os }}
|
||||
path: buildroot/bin/frankenphp
|
||||
|
||||
# Upload extensions metadata
|
||||
- if: ${{ inputs['shared-extensions'] != '' }}
|
||||
name: "Upload shared extensions"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-shared-ext-${{ inputs.php-version }}-${{ inputs.os }}
|
||||
path: |
|
||||
buildroot/modules/*.so
|
||||
- uses: actions/upload-artifact@v4
|
||||
name: "Upload License Files"
|
||||
with:
|
||||
name: license-files-${{ inputs.php-version }}-${{ inputs.os }}
|
||||
path: buildroot/license/
|
||||
- uses: actions/upload-artifact@v4
|
||||
name: "Upload Build Metadata"
|
||||
with:
|
||||
name: build-meta-${{ inputs.php-version }}-${{ inputs.os }}
|
||||
path: |
|
||||
buildroot/build-extensions.json
|
||||
buildroot/build-libraries.json
|
||||
115
.github/workflows/build-windows-x86_64.yml
vendored
115
.github/workflows/build-windows-x86_64.yml
vendored
@@ -1,115 +0,0 @@
|
||||
name: CI on x86_64 Windows
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
version:
|
||||
required: true
|
||||
description: php version to compile
|
||||
default: '8.4'
|
||||
type: choice
|
||||
options:
|
||||
- '8.4'
|
||||
- '8.3'
|
||||
- '8.2'
|
||||
- '8.1'
|
||||
- '8.0'
|
||||
build-cli:
|
||||
description: build cli binary
|
||||
default: true
|
||||
type: boolean
|
||||
build-micro:
|
||||
description: build phpmicro binary
|
||||
type: boolean
|
||||
extensions:
|
||||
description: extensions to compile (comma separated)
|
||||
required: true
|
||||
type: string
|
||||
prefer-pre-built:
|
||||
description: prefer pre-built binaries (reduce build time)
|
||||
type: boolean
|
||||
default: true
|
||||
debug:
|
||||
description: enable debug logs
|
||||
type: boolean
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: build ${{ inputs.version }} on Windows x86_64
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
# Cache composer dependencies
|
||||
- id: cache-composer-deps
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: composer-dependencies
|
||||
|
||||
# If there's no Composer cache, install dependencies
|
||||
- if: steps.cache-composer-deps.outputs.cache-hit != 'true'
|
||||
run: composer update --no-dev --classmap-authoritative
|
||||
|
||||
- name: Generate hashed key for download cache
|
||||
shell: bash
|
||||
run: |
|
||||
INPUT_HASH=$(echo "${{ runner.os }}-${{ inputs.version }}-${{ inputs.extensions }}" | sha256sum | awk '{print $1}')
|
||||
echo "INPUT_HASH=${INPUT_HASH}" >> "$GITHUB_ENV"
|
||||
|
||||
# Cache downloaded source
|
||||
- id: cache-download
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-${{ env.INPUT_HASH }}
|
||||
|
||||
# With or without debug
|
||||
- if: inputs.debug == true
|
||||
run: echo "SPC_BUILD_DEBUG=--debug" >> $env:GITHUB_ENV
|
||||
- if: inputs.prefer-pre-built == true
|
||||
run: echo "SPC_PRE_BUILT=--prefer-pre-built" >> $env:GITHUB_ENV
|
||||
|
||||
# With target select: cli, micro or both
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
run: echo "SPC_BUILD_CLI=--build-cli" >> $env:GITHUB_ENV
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
run: echo "SPC_BUILD_MICRO=--build-micro" >> $env:GITHUB_ENV
|
||||
|
||||
- run: ./bin/spc doctor
|
||||
|
||||
# If there's no dependencies cache, fetch sources, with or without debug
|
||||
- if: steps.cache-download.outputs.cache-hit != 'true'
|
||||
run: ./bin/spc download --with-php="${{ inputs.version }}" --for-extensions="${{ inputs.extensions }}" ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_PRE_BUILT }}
|
||||
|
||||
# Run build command
|
||||
- run: ./bin/spc build "${{ inputs.extensions }}" ${{ env.SPC_BUILD_DEBUG }} ${{ env.SPC_BUILD_CLI }} ${{ env.SPC_BUILD_MICRO }} ${{ env.SPC_BUILD_FPM }}
|
||||
|
||||
# Upload cli executable
|
||||
- if: ${{ inputs.build-cli == true }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: php-${{ inputs.version }}
|
||||
path: buildroot/bin/php.exe
|
||||
|
||||
# Upload micro self-extracted executable
|
||||
- if: ${{ inputs.build-micro == true }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: micro-${{ inputs.version }}
|
||||
path: buildroot/bin/micro.sfx
|
||||
|
||||
# Upload extensions metadata
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: license-files
|
||||
path: buildroot/license/
|
||||
- uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-meta
|
||||
path: |
|
||||
buildroot/build-extensions.json
|
||||
buildroot/build-libraries.json
|
||||
139
.github/workflows/ext-matrix-tests.yml
vendored
139
.github/workflows/ext-matrix-tests.yml
vendored
@@ -1,139 +0,0 @@
|
||||
name: "Extension Matrix Tests"
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: "${{ matrix.extension }} (PHP ${{ matrix.php-version }} on ${{ matrix.operating-system }})"
|
||||
runs-on: ${{ matrix.operating-system }}
|
||||
if: contains(github.event.head_commit.message, 'extension test') || contains(github.event.head_commit.message, 'test extensions')
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
extension:
|
||||
- amqp
|
||||
- apcu
|
||||
- bcmath
|
||||
- bz2
|
||||
- calendar
|
||||
- ctype
|
||||
- curl
|
||||
- dba
|
||||
- dom
|
||||
- ds
|
||||
- event
|
||||
- exif
|
||||
- filter
|
||||
- fileinfo
|
||||
- ftp
|
||||
- gd
|
||||
- gettext
|
||||
- gmp
|
||||
- iconv
|
||||
- igbinary
|
||||
- imagick
|
||||
- imap
|
||||
- intl
|
||||
- ldap
|
||||
- mbstring,mbregex
|
||||
- memcache
|
||||
- mysqli,mysqlnd,pdo_mysql
|
||||
- opcache
|
||||
- openssl
|
||||
- pcntl
|
||||
- password-argon2
|
||||
- pcntl
|
||||
- pdo
|
||||
- pgsql,pdo_pgsql
|
||||
- phar
|
||||
- posix
|
||||
- rar
|
||||
- protobuf
|
||||
- readline
|
||||
- redis
|
||||
- session
|
||||
- shmop
|
||||
- simdjson
|
||||
- simplexml,xml
|
||||
- snappy
|
||||
- soap
|
||||
- sockets
|
||||
- sodium
|
||||
- sqlite3,pdo_sqlite
|
||||
- sqlsrv
|
||||
- ssh2
|
||||
- swoole
|
||||
- swoole,swoole-hook-pgsql,swoole-hook-mysql,swoole-hook-sqlite,swoole-hook-odbc
|
||||
- swow
|
||||
- sysvmsg,sysvsem,sysvshm
|
||||
- tidy
|
||||
- tokenizer
|
||||
- uuid
|
||||
- uv
|
||||
- xhprof
|
||||
- xlswriter
|
||||
- xmlwriter,xmlreader
|
||||
- xsl
|
||||
- yac
|
||||
- yaml
|
||||
- zip
|
||||
- zlib
|
||||
- zstd
|
||||
php-version:
|
||||
- "8.4"
|
||||
operating-system:
|
||||
- "ubuntu-latest"
|
||||
#- "macos-15-intel"
|
||||
#- "debian-arm64-self-hosted"
|
||||
- "macos-15"
|
||||
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v4"
|
||||
|
||||
- name: OS type
|
||||
id: os-type
|
||||
run: |
|
||||
OS=""
|
||||
if [ "${{ matrix.operating-system }}" = "ubuntu-latest" ]; then
|
||||
OS="linux-x86_64"
|
||||
elif [ "${{ matrix.operating-system }}" = "macos-15-intel" ]; then
|
||||
OS="macos-x86_64"
|
||||
elif [ "${{ matrix.operating-system }}" = "debian-arm64-self-hosted" ]; then
|
||||
OS="linux-aarch64"
|
||||
elif [ "${{ matrix.operating-system }}" = "macos-15" ]; then
|
||||
OS="macos-aarch64"
|
||||
fi
|
||||
echo "OS=$OS" >> $GITHUB_ENV
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.4
|
||||
tools: pecl, composer
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
env:
|
||||
phpts: nts
|
||||
|
||||
- name: "Install Dependencies"
|
||||
run: composer update -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
|
||||
- id: cache-download
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-${{ matrix.php-version }}-dependencies-for-tests
|
||||
|
||||
# If there's no dependencies cache, fetch sources
|
||||
- name: "Download sources"
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: ./bin/spc download --with-php=${{ matrix.php-version }} --for-extensions=${{ matrix.extension }} --debug --ignore-cache-sources=php-src
|
||||
|
||||
- name: "Build library: ${{ matrix.library }}"
|
||||
run: |
|
||||
SPC_USE_SUDO=yes ./bin/spc doctor --auto-fix
|
||||
./bin/spc build --build-cli --build-micro --build-fpm ${{ matrix.extension }} --debug --with-suggested-libs --with-suggested-exts
|
||||
175
.github/workflows/release-build.yml
vendored
175
.github/workflows/release-build.yml
vendored
@@ -1,175 +0,0 @@
|
||||
name: Build SPC Binary
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main" ]
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
paths:
|
||||
- '.github/workflows/release-build.yml'
|
||||
release:
|
||||
types:
|
||||
- published
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
PHP_VERSION: 8.4
|
||||
MICRO_VERSION: 8.4.11
|
||||
|
||||
jobs:
|
||||
build-release-artifacts:
|
||||
name: "Build SPC Binary for ${{ matrix.operating-system.name }}"
|
||||
runs-on: ${{ matrix.operating-system.os }}
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system:
|
||||
- name: "linux-x86_64"
|
||||
os: "ubuntu-latest"
|
||||
filename: "spc-linux-x86_64.tar.gz"
|
||||
- name: "macos-x86_64"
|
||||
os: "macos-15-intel"
|
||||
filename: "spc-macos-x86_64.tar.gz"
|
||||
- name: "linux-aarch64"
|
||||
os: "ubuntu-latest"
|
||||
filename: "spc-linux-aarch64.tar.gz"
|
||||
- name: "macos-aarch64"
|
||||
os: "macos-14"
|
||||
filename: "spc-macos-aarch64.tar.gz"
|
||||
- name: "windows-x64"
|
||||
os: "ubuntu-latest"
|
||||
filename: "spc-windows-x64.exe"
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: "actions/checkout@v4"
|
||||
|
||||
- if: inputs.debug == true
|
||||
run: echo "SPC_BUILD_DEBUG=--debug" >> $GITHUB_ENV
|
||||
|
||||
- name: "Install PHP for official runners"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
coverage: none
|
||||
tools: composer:v2
|
||||
php-version: "${{ env.PHP_VERSION }}"
|
||||
ini-values: memory_limit=-1
|
||||
extensions: curl, openssl, mbstring
|
||||
|
||||
- name: "Get Composer Cache Directory"
|
||||
id: composer-cache
|
||||
run: |
|
||||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: "Cache Composer dependencies"
|
||||
uses: "actions/cache@v4"
|
||||
with:
|
||||
path: "${{ steps.composer-cache.outputs.dir }}"
|
||||
key: "php-${{ env.PHP_VERSION }}-locked-composer-${{ hashFiles('**/composer.lock') }}"
|
||||
restore-keys: |
|
||||
php-${{ env.PHP_VERSION }}-locked-composer
|
||||
|
||||
- name: "Install Locked Dependencies"
|
||||
run: "composer install --no-interaction --no-progress"
|
||||
|
||||
- name: "Build PHAR File"
|
||||
run: "composer build:phar"
|
||||
|
||||
- name: "Download Minimal Combination"
|
||||
run: |
|
||||
if [ "${{ matrix.operating-system.name }}" = "windows-x64" ]; then
|
||||
curl -fsSL https://dl.static-php.dev/static-php-cli/windows/spc-min/php-${{ env.MICRO_VERSION }}-micro-win.zip -o tmp.zip
|
||||
unzip tmp.zip
|
||||
else
|
||||
curl -fsSL https://dl.static-php.dev/static-php-cli/minimal/php-${{ env.MICRO_VERSION }}-micro-${{ matrix.operating-system.name }}.tar.gz -o tmp.tgz
|
||||
tar -zxvf tmp.tgz
|
||||
fi
|
||||
|
||||
- name: "Generate Executable"
|
||||
run: |
|
||||
bin/spc micro:combine spc.phar -M micro.sfx -O spc -I "memory_limit=2G"
|
||||
if [ "${{ matrix.operating-system.name }}" = "windows-x64" ]; then
|
||||
mv spc spc.exe
|
||||
else
|
||||
chmod +x spc
|
||||
fi
|
||||
if [ "${{ matrix.operating-system.name }}" = "macos-aarch64" ] || [ "${{ matrix.operating-system.name }}" = "macos-x86_64" ]; then
|
||||
sudo xattr -cr ./spc
|
||||
fi
|
||||
|
||||
- name: "Archive Executable and Validate Binary"
|
||||
run: |
|
||||
if [ "${{ matrix.operating-system.name }}" != "windows-x64" ]; then
|
||||
tar -czf ${{ matrix.operating-system.filename }} spc
|
||||
# validate spc binary
|
||||
if [ "${{ matrix.operating-system.name }}" == "linux-x86_64" ]; then
|
||||
./spc dev:extensions
|
||||
fi
|
||||
fi
|
||||
|
||||
- name: "Copy file"
|
||||
run: |
|
||||
if [ "${{ matrix.operating-system.name }}" != "windows-x64" ]; then
|
||||
mkdir dist/ && cp ${{ matrix.operating-system.filename }} dist/ && cp spc dist/spc-${{ matrix.operating-system.name }}
|
||||
else
|
||||
mkdir dist/ && cp spc.exe dist/${{ matrix.operating-system.filename }}
|
||||
echo "SUFFIX=.exe" >> $GITHUB_ENV
|
||||
fi
|
||||
|
||||
- name: "Upload Binaries to Release"
|
||||
uses: softprops/action-gh-release@v1
|
||||
if: ${{startsWith(github.ref, 'refs/tags/') }}
|
||||
with:
|
||||
files: dist/${{ matrix.operating-system.filename }}
|
||||
|
||||
- name: "Deploy to self-hosted OSS"
|
||||
# only run this step if the repository is static-php-cli and the branch is main
|
||||
if: github.repository == 'crazywhalecc/static-php-cli' && github.ref == 'refs/heads/main'
|
||||
uses: static-php/upload-s3-action@v1.0.0
|
||||
with:
|
||||
aws_key_id: ${{ secrets.AWS_KEY_ID }}
|
||||
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
|
||||
aws_bucket: ${{ secrets.AWS_BUCKET }}
|
||||
source_dir: "dist/"
|
||||
destination_dir: static-php-cli/spc-bin/nightly/
|
||||
endpoint: ${{ secrets.AWS_ENDPOINT }}
|
||||
|
||||
- name: "Upload Artifact"
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
path: spc${{ env.SUFFIX }}
|
||||
name: spc-${{ matrix.operating-system.name }}${{ env.SUFFIX }}
|
||||
test-spc:
|
||||
name: "Test SPC Binary for ${{ matrix.operating-system.name }}"
|
||||
runs-on: ${{ matrix.operating-system.os }}
|
||||
needs: [build-release-artifacts]
|
||||
strategy:
|
||||
matrix:
|
||||
operating-system:
|
||||
- name: "linux-x86_64"
|
||||
os: "ubuntu-latest"
|
||||
- name: "macos-x86_64"
|
||||
os: "macos-15-intel"
|
||||
- name: "linux-aarch64"
|
||||
os: "ubuntu-24.04-arm"
|
||||
- name: "macos-aarch64"
|
||||
os: "macos-15"
|
||||
- name: "windows-x64"
|
||||
os: "windows-latest"
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Download Artifact"
|
||||
uses: actions/download-artifact@v4
|
||||
env:
|
||||
SUFFIX: ${{ matrix.operating-system.name == 'windows-x64' && '.exe' || '' }}
|
||||
with:
|
||||
name: spc-${{ matrix.operating-system.name }}${{ env.SUFFIX }}
|
||||
|
||||
- name: "Chmod"
|
||||
if: matrix.operating-system.name != 'windows-x64'
|
||||
run: chmod +x spc
|
||||
|
||||
- name: "Run SPC Tests"
|
||||
env:
|
||||
SUFFIX: ${{ matrix.operating-system.name == 'windows-x64' && '.exe' || '' }}
|
||||
run: ./spc${{ env.SUFFIX }} dev:extensions
|
||||
214
.github/workflows/tests.yml
vendored
214
.github/workflows/tests.yml
vendored
@@ -1,214 +0,0 @@
|
||||
name: Tests
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
types: [ opened, synchronize, reopened ]
|
||||
paths:
|
||||
- 'src/**'
|
||||
- 'config/**'
|
||||
- '.github/workflows/tests.yml'
|
||||
- 'bin/**'
|
||||
- 'composer.json'
|
||||
- 'box.json'
|
||||
- '.php-cs-fixer.php'
|
||||
|
||||
permissions: read-all
|
||||
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
jobs:
|
||||
php-cs-fixer:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
tools: pecl, composer, php-cs-fixer
|
||||
|
||||
- name: Run PHP-CS-Fixer fix
|
||||
run: php-cs-fixer fix --dry-run --diff --ansi
|
||||
|
||||
phpstan:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.4'
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
tools: composer
|
||||
env:
|
||||
phpts: zts
|
||||
|
||||
- name: "Cache Composer packages"
|
||||
id: composer-cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-phpstan-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-phpstan-
|
||||
|
||||
- name: "Install Dependencies"
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
|
||||
- name: "Run phpstan"
|
||||
run: vendor/bin/phpstan analyse
|
||||
|
||||
phpunit:
|
||||
name: "PHPUnit (PHP ${{ matrix.php }})"
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 10
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- php: '8.4'
|
||||
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: "${{ matrix.php }}"
|
||||
tools: pecl, composer
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
|
||||
- name: "Cache Composer packages"
|
||||
id: composer-cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-php
|
||||
|
||||
- name: "Install Dependencies"
|
||||
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
|
||||
|
||||
- name: "Run PHPUnit Tests"
|
||||
run: SPC_LIBC=glibc vendor/bin/phpunit tests/ --no-coverage
|
||||
|
||||
define-matrix:
|
||||
name: "Define Matrix"
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
php: ${{ steps.gendef.outputs.php }}
|
||||
os: ${{ steps.gendef.outputs.os }}
|
||||
steps:
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.4
|
||||
extensions: curl, openssl, mbstring
|
||||
|
||||
- name: Define
|
||||
id: gendef
|
||||
run: |
|
||||
PHP_VERSIONS=$(php src/globals/test-extensions.php php)
|
||||
OS_VERSIONS=$(php src/globals/test-extensions.php os)
|
||||
echo 'php='"$PHP_VERSIONS" >> "$GITHUB_OUTPUT"
|
||||
echo 'os='"$OS_VERSIONS" >> "$GITHUB_OUTPUT"
|
||||
|
||||
|
||||
build:
|
||||
name: "Build PHP Test (PHP ${{ matrix.php }} ${{ matrix.os }})"
|
||||
runs-on: ${{ matrix.os }}
|
||||
needs: [define-matrix, php-cs-fixer, phpstan, phpunit]
|
||||
timeout-minutes: 120
|
||||
strategy:
|
||||
matrix:
|
||||
php: ${{ fromJSON(needs.define-matrix.outputs.php) }}
|
||||
os: ${{ fromJSON(needs.define-matrix.outputs.os) }}
|
||||
fail-fast: false
|
||||
steps:
|
||||
- name: "Update runner packages"
|
||||
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
|
||||
run: sudo apt-get update && sudo apt-get install -y ca-certificates
|
||||
|
||||
- name: "Checkout"
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.4
|
||||
tools: pecl, composer
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
env:
|
||||
phpts: nts
|
||||
|
||||
- name: "Cache composer packages"
|
||||
id: composer-cache
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: vendor
|
||||
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-php-
|
||||
|
||||
# Cache downloaded source
|
||||
- id: cache-download
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: downloads
|
||||
key: php-dependencies-${{ matrix.os }}
|
||||
|
||||
- name: "Install Dependencies"
|
||||
run: composer update -vvv --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist --no-plugins
|
||||
|
||||
- name: "Run Build Tests (doctor)"
|
||||
run: php src/globals/test-extensions.php doctor_cmd ${{ matrix.os }} ${{ matrix.php }}
|
||||
|
||||
- name: "Prepare UPX for Windows"
|
||||
if: ${{ startsWith(matrix.os, 'windows-') }}
|
||||
run: |
|
||||
php src/globals/test-extensions.php install_upx_cmd ${{ matrix.os }} ${{ matrix.php }}
|
||||
echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $env:GITHUB_ENV
|
||||
|
||||
- name: "Prepare UPX for Linux"
|
||||
if: ${{ startsWith(matrix.os, 'ubuntu-') }}
|
||||
run: |
|
||||
php src/globals/test-extensions.php install_upx_cmd ${{ matrix.os }} ${{ matrix.php }}
|
||||
echo "UPX_CMD=$(php src/globals/test-extensions.php upx)" >> $GITHUB_ENV
|
||||
|
||||
- name: "Run Build Tests (download)"
|
||||
run: php src/globals/test-extensions.php download_cmd ${{ matrix.os }} ${{ matrix.php }}
|
||||
|
||||
- name: "Run Build Tests (build)"
|
||||
run: php src/globals/test-extensions.php build_cmd ${{ matrix.os }} ${{ matrix.php }}
|
||||
|
||||
- name: "Run Build Tests (build - embed for non-windows)"
|
||||
if: ${{ !startsWith(matrix.os, 'windows-') }}
|
||||
run: php src/globals/test-extensions.php build_embed_cmd ${{ matrix.os }} ${{ matrix.php }}
|
||||
|
||||
- name: "Upload logs"
|
||||
if: ${{ always() && hashFiles('log/**') != '' }}
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: build-logs-${{ matrix.os }}-${{ matrix.php }}
|
||||
path: log
|
||||
|
||||
# - name: Setup tmate session
|
||||
# if: ${{ failure() }}
|
||||
# uses: mxschmitt/action-tmate@v3
|
||||
71
.github/workflows/vitepress-deploy.yml
vendored
71
.github/workflows/vitepress-deploy.yml
vendored
@@ -1,71 +0,0 @@
|
||||
name: Docs Auto Deploy
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
paths:
|
||||
- 'config/**.json'
|
||||
- 'docs/**'
|
||||
- 'package.json'
|
||||
- 'yarn.lock'
|
||||
- '.github/workflows/vitepress-deploy.yml'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Deploy docs
|
||||
runs-on: ubuntu-latest
|
||||
if: github.repository == 'crazywhalecc/static-php-cli'
|
||||
steps:
|
||||
- name: Checkout master
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- uses: actions/setup-node@v3
|
||||
with:
|
||||
cache: yarn
|
||||
|
||||
- run: yarn install --frozen-lockfile
|
||||
|
||||
- name: "Copy Config Files"
|
||||
run: |
|
||||
mkdir -p docs/.vitepress/config
|
||||
cp -r config/* docs/.vitepress/config/
|
||||
|
||||
- name: "Install PHP for official runners"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
coverage: none
|
||||
tools: composer:v2
|
||||
php-version: 8.4
|
||||
ini-values: memory_limit=-1
|
||||
extensions: curl, openssl, mbstring
|
||||
|
||||
- name: "Get Composer Cache Directory"
|
||||
id: composer-cache
|
||||
run: |
|
||||
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: "Cache Composer dependencies"
|
||||
uses: "actions/cache@v4"
|
||||
with:
|
||||
path: "${{ steps.composer-cache.outputs.dir }}"
|
||||
key: "php-8.2-locked-composer-${{ hashFiles('**/composer.lock') }}"
|
||||
restore-keys: |
|
||||
php-8.2-locked-composer
|
||||
|
||||
- name: "Install Locked Dependencies"
|
||||
run: "composer install --no-interaction --no-progress"
|
||||
|
||||
- name: "Generate Extension Support List"
|
||||
run: |
|
||||
bin/spc dev:gen-ext-docs > docs/extensions.md
|
||||
bin/spc dev:gen-ext-dep-docs > docs/deps-map-ext.md
|
||||
bin/spc dev:gen-lib-dep-docs > docs/deps-map-lib.md
|
||||
|
||||
- name: Build
|
||||
run: yarn docs:build
|
||||
|
||||
- name: Deploy to GitHub Pages
|
||||
uses: peaceiris/actions-gh-pages@v3
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: docs/.vitepress/dist
|
||||
58
.gitignore
vendored
58
.gitignore
vendored
@@ -3,61 +3,3 @@ runtime/
|
||||
docker/libraries/
|
||||
docker/extensions/
|
||||
docker/source/
|
||||
|
||||
# Vendor files
|
||||
/vendor/**
|
||||
|
||||
# default source extract directory
|
||||
/source/**
|
||||
|
||||
# built by shared embed tests
|
||||
/locale/
|
||||
|
||||
# default source download directory
|
||||
/downloads/**
|
||||
|
||||
# default source build root directory
|
||||
/buildroot/**
|
||||
|
||||
# default package root directory
|
||||
/pkgroot/**
|
||||
|
||||
# Windows PHP SDK binary tools
|
||||
/php-sdk-binary-tools/**
|
||||
|
||||
# default pack:lib and release directory
|
||||
/dist/**
|
||||
packlib_files.txt
|
||||
|
||||
# tools cache files
|
||||
.php-cs-fixer.cache
|
||||
.phpunit.result.cache
|
||||
|
||||
# exclude self-runtime
|
||||
/bin/*
|
||||
!/bin/spc*
|
||||
!/bin/setup-runtime*
|
||||
!/bin/docker-entrypoint.sh
|
||||
|
||||
# exclude windows build tools
|
||||
/php-sdk-binary-tools/
|
||||
|
||||
# default test directory
|
||||
/tests/var/
|
||||
|
||||
# VitePress
|
||||
/node_modules/
|
||||
/docs/.vitepress/dist/
|
||||
/docs/.vitepress/cache/
|
||||
package-lock.json
|
||||
pnpm-lock.yaml
|
||||
|
||||
# craft
|
||||
craft.yml
|
||||
|
||||
# SPC logs
|
||||
log/
|
||||
|
||||
# spc.phar
|
||||
spc.phar
|
||||
spc.exe
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return (new PhpCsFixer\Config())
|
||||
->setRiskyAllowed(true)
|
||||
->setUnsupportedPhpVersionAllowed(true)
|
||||
->setRules([
|
||||
'@PSR12' => true,
|
||||
'@Symfony' => true,
|
||||
'@PhpCsFixer' => true,
|
||||
'array_syntax' => [
|
||||
'syntax' => 'short',
|
||||
],
|
||||
'list_syntax' => [
|
||||
'syntax' => 'short',
|
||||
],
|
||||
'concat_space' => [
|
||||
'spacing' => 'one',
|
||||
],
|
||||
'blank_line_before_statement' => [
|
||||
'statements' => [
|
||||
'declare',
|
||||
],
|
||||
],
|
||||
'ordered_imports' => [
|
||||
'imports_order' => [
|
||||
'class',
|
||||
'function',
|
||||
'const',
|
||||
],
|
||||
'sort_algorithm' => 'alpha',
|
||||
],
|
||||
'single_line_comment_style' => [
|
||||
'comment_types' => [
|
||||
],
|
||||
],
|
||||
'yoda_style' => [
|
||||
'always_move_variable' => false,
|
||||
'equal' => false,
|
||||
'identical' => false,
|
||||
],
|
||||
'multiline_whitespace_before_semicolons' => [
|
||||
'strategy' => 'no_multi_line',
|
||||
],
|
||||
'constant_case' => [
|
||||
'case' => 'lower',
|
||||
],
|
||||
'class_attributes_separation' => true,
|
||||
'combine_consecutive_unsets' => true,
|
||||
'declare_strict_types' => true,
|
||||
'linebreak_after_opening_tag' => true,
|
||||
'lowercase_static_reference' => true,
|
||||
'no_useless_else' => true,
|
||||
'no_unused_imports' => true,
|
||||
'not_operator_with_successor_space' => false,
|
||||
'not_operator_with_space' => false,
|
||||
'ordered_class_elements' => true,
|
||||
'php_unit_strict' => false,
|
||||
'phpdoc_separation' => false,
|
||||
'single_quote' => true,
|
||||
'standardize_not_equals' => true,
|
||||
'multiline_comment_opening_closing' => true,
|
||||
'phpdoc_summary' => false,
|
||||
'php_unit_test_class_requires_covers' => false,
|
||||
'phpdoc_var_without_name' => false,
|
||||
'fully_qualified_strict_types' => false,
|
||||
'operator_linebreak' => false,
|
||||
'php_unit_data_provider_method_order' => false,
|
||||
])
|
||||
->setFinder(
|
||||
PhpCsFixer\Finder::create()->in([__DIR__ . '/src', __DIR__ . '/tests/SPC'])
|
||||
)
|
||||
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect());
|
||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2022-2023 Jerry Ma
|
||||
Copyright (c) 2022 Jerry Ma
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
||||
186
README-en.md
186
README-en.md
@@ -1,3 +1,187 @@
|
||||
# static-php-cli
|
||||
|
||||
English README has been moved to [README.md](README.md).
|
||||
Compile A Statically Linked PHP With Swoole and other Popular Extensions.
|
||||
|
||||
Compile A Single Binary With PHP Code.
|
||||
|
||||
[]()
|
||||

|
||||
|
||||
## Refactoring
|
||||
|
||||
The current project is under reconstruction, and this branch is an older version.
|
||||
The refactored version supports many new features. The following is the current progress of refactoring:
|
||||
|
||||
- **Discussion:https://github.com/crazywhalecc/static-php-cli/discussions/29**
|
||||
- **Branch:[refactor](https://github.com/crazywhalecc/static-php-cli/tree/refactor)**
|
||||
- **Bugs and TODOs:https://github.com/crazywhalecc/static-php-cli/issues/32**
|
||||
|
||||
## Compilation Requirements
|
||||
|
||||
- Supporting architecture: `x86_64`, `arm64(aarch64)`, `armv7(armv7l)`
|
||||
- Docker required (or alpine linux 3.13+)
|
||||
- PHP version from 7.2 to 8.1
|
||||
- Micro Package requires PHP >= 8.0
|
||||
|
||||
## Runtime Requirements
|
||||
|
||||
Linux
|
||||
|
||||
## Usage
|
||||
|
||||
1. Directly download static binary from this link or [Actions uploaded artifacts](https://github.com/crazywhalecc/static-php-cli/actions).
|
||||
|
||||
<https://dl.zhamao.xin/php-bin/file/>
|
||||
|
||||
2. Use fast install script `install-runtime.sh` to download static php and composer distribution into `runtime/` directory
|
||||
|
||||
But this script has some Chinese comments and prompts, if you cannot understand or have to use it in English, I will make an pure international version! :)
|
||||
|
||||
```bash
|
||||
bash -c "`curl -fsSL https://raw.githubusercontent.com/crazywhalecc/static-php-cli/master/install-runtime.sh`"
|
||||
```
|
||||
|
||||
## Packing PHP Code into a Static Binary
|
||||
|
||||
From v1.5.0, we support packing PHP code into a static binary. You can pack your PHP code into a static binary by micro.
|
||||
|
||||
You can directly download `micro-` prefix file, untar it and you will get file `micro.sfx`.
|
||||
|
||||
Here's a simple example to use it:
|
||||
|
||||
```bash
|
||||
echo "<?php echo 'Hello world' . PHP_EOL;" > code.php
|
||||
cat micro.sfx code.php > single-app && chmod +x single-app
|
||||
./single-app
|
||||
|
||||
# If packing phar into a static binary, just change code.php to your phar path.
|
||||
```
|
||||
> Note: It means that your PHP code won't be compiled and you can't protect your source code by using micro!
|
||||
>
|
||||
> If you are looking for compiling PHP code or encrypting code, here's not your solution.
|
||||
>
|
||||
> Special thanks: <https://github.com/dixyes/phpmicro>
|
||||
|
||||
## Compiling
|
||||
|
||||
Here's help command to compile it yourself:
|
||||
|
||||
```bash
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git
|
||||
cd static-php-cli/docker
|
||||
docker build -t static-php . --build-arg USE_BACKUP_ADDRESS=yes
|
||||
# Making a directory to put binary files
|
||||
mkdir dist
|
||||
# It will ask you for PHP version, extensions, and compile static binaries
|
||||
docker run --rm -v $(pwd)/dist:/dist/ -it static-php build-php
|
||||
```
|
||||
|
||||
After compilation you can use command to get static php binary file.
|
||||
|
||||
```bash
|
||||
cd dist
|
||||
file ./php
|
||||
```
|
||||
|
||||
If you don't want to use docker, a single script for compiling in **Alpine Linux**:
|
||||
|
||||
```bash
|
||||
cd docker
|
||||
# Change PHP Version
|
||||
export VER_PHP="8.1.7"
|
||||
# Use Original download link (Default is China mainland mirror link, for others please use 'yes' for original link)
|
||||
export USE_BACKUP="yes"
|
||||
./fast-compiler.sh
|
||||
```
|
||||
|
||||
To customize PHP extensions, edit `docker/extensions.txt` file, and rules below:
|
||||
- Use `^` as deselect, to mark not install. Use `#` as comments.
|
||||
- extensions name uses lower case, and default file contains all supported extensions, if u need other extensions, consider write an Issue
|
||||
|
||||
## Supported PHP extensions
|
||||
| Support | PHP Ext Name | Version | Comments |
|
||||
| ------- | ------------ | ------- | ---------------------------------------- |
|
||||
| yes | bcmath | * | |
|
||||
| yes | calendar | * | |
|
||||
| yes | ctype | * | |
|
||||
| yes | curl | * | |
|
||||
| yes | dom | * | |
|
||||
| yes | event | >=3.0.8 | author's bitbucket version, not pecl |
|
||||
| yes | exif | * | |
|
||||
| yes | filter | * | |
|
||||
| yes | fileinfo | * | |
|
||||
| yes | gd | * | |
|
||||
| yes | hash | * | |
|
||||
| yes | iconv | * | |
|
||||
| yes | inotify | 3.0.0 | |
|
||||
| yes | json | * | |
|
||||
| yes | libxml | * | |
|
||||
| yes | mbstring | * | |
|
||||
| yes | mongodb | >=1.9.1 | not tested |
|
||||
| | mysqli | | |
|
||||
| yes | mysqlnd | * | |
|
||||
| yes | openssl | * | |
|
||||
| yes | pcntl | * | |
|
||||
| yes | pdo | * | |
|
||||
| yes | pdo_mysql | * | |
|
||||
| yes | pdo_sqlite | * | |
|
||||
| | pdo_pgsql | * | |
|
||||
| yes | phar | * | |
|
||||
| yes | posix | * | |
|
||||
| yes, not compiled | protobuf | * | Not compiled and enabled as default |
|
||||
| yes | readline | * | Not support `./php -a` |
|
||||
| yes | redis | * | |
|
||||
| yes | shmop | * | |
|
||||
| yes | simplexml | * | |
|
||||
| yes | soap | * | |
|
||||
| yes | sockets | * | |
|
||||
| yes | sqlite3 | * | |
|
||||
| yes | swoole | >=4.6.6 | support mysqlnd, sockets, openssl, redis |
|
||||
| yes | tokenizer | * | |
|
||||
| yes | xml | * | |
|
||||
| yes | xmlreader | * | |
|
||||
| yes | xmlwriter | * | |
|
||||
| yes | zip | * | not support `bzip2`, `lzma` compression |
|
||||
| yes | zlib | * | |
|
||||
|
||||
## Customization
|
||||
- If you are going to run without prompt, Just add it to the end of `docker run xxx` cmd according to the parameters given below.
|
||||
|
||||
> 1st parameter `original` represents that you are using global original download address to fetch dependencies, if you are in mainland China, use `mirror`.
|
||||
>
|
||||
> 2nd parameter `8.1.7` is your PHP version you are compiling.
|
||||
>
|
||||
> 3rd parameter `all` represents that you will compile all supported extensions.
|
||||
>
|
||||
> 4th parameter `/dist/` is your binary output directory.
|
||||
>
|
||||
> For example, `docker run --rm -v $(pwd)/dist:/dist/ -it static-php build-php original 8.1.7 all /dist/`
|
||||
|
||||
- `docker/extensions.txt` edit extensions.
|
||||
- `docker/compile-php.sh` file `php_compile_args` function to adjust PHP configure arguments.
|
||||
- `docker/check-extensions.sh` file `check_in_configure` function to adjust extensions' configure arguments.
|
||||
- `docker/config.json` edit extensions and dependencies version and download links.
|
||||
|
||||
## Current Issue
|
||||
- [X] Not support event(libevent), because of its `config.m4` and code.
|
||||
- [ ] Swoole not support `--enable-swoole-curl`.
|
||||
- [X] Not support readline, maybe caused by ncurses library.
|
||||
- [X] Not support curl (solved)
|
||||
- [X] Customize extensions to compile
|
||||
- [X] php.ini integration
|
||||
- [X] i18n (including README and scripts)
|
||||
|
||||
## Running preview
|
||||
|
||||
### Using static binary
|
||||
|
||||
<img width="881" alt="未命名" src="https://user-images.githubusercontent.com/20330940/168441751-e62cb8d4-a3c8-42d9-b34e-d804b39756a1.png">
|
||||
|
||||
### Using swoole application packed with micro
|
||||
|
||||
<img width="937" alt="all" src="https://user-images.githubusercontent.com/20330940/168557743-b8f92263-712f-490e-9fe0-831597741595.png">
|
||||
|
||||
## References
|
||||
- <https://blog.terrywh.net/post/2019/php-static-openssl/>
|
||||
- <https://stackoverflow.com/a/37245653>
|
||||
- <http://blog.gaoyuan.xyz/2014/04/09/statically-compile-php/>
|
||||
|
||||
172
README-zh.md
172
README-zh.md
@@ -1,172 +0,0 @@
|
||||
# static-php-cli
|
||||
|
||||
[](README.md)
|
||||
[](README-zh.md)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/releases)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
|
||||
|
||||
**static-php-cli** 是一个用于构建静态、独立 PHP 运行时的强大工具,支持众多流行扩展。
|
||||
|
||||
## 特性
|
||||
|
||||
- :elephant: **支持多 PHP 版本** - 支持 PHP 8.1, 8.2, 8.3, 8.4, 8.5
|
||||
- :handbag: **单文件 PHP 可执行文件** - 构建零依赖的独立 PHP
|
||||
- :hamburger: **phpmicro 集成** - 构建 **[phpmicro](https://github.com/dixyes/phpmicro)** 自解压可执行文件(将 PHP 二进制文件和源代码合并为一个文件)
|
||||
- :pill: **智能环境检查器** - 自动构建环境检查器,具备自动修复功能
|
||||
- :zap: **跨平台支持** - 支持 Linux、macOS、FreeBSD 和 Windows
|
||||
- :wrench: **可配置补丁** - 可自定义的源代码补丁系统
|
||||
- :books: **智能依赖管理** - 自动处理构建依赖
|
||||
- 📦 **自包含工具** - 提供使用 [box](https://github.com/box-project/box) 构建的 `spc` 可执行文件
|
||||
- :fire: **广泛的扩展支持** - 支持 75+ 流行 [扩展](https://static-php.dev/zh/guide/extensions.html)
|
||||
- :floppy_disk: **UPX 压缩** - 减小二进制文件大小 30-50%(仅 Linux/Windows)
|
||||
|
||||
**单文件独立 php-cli:**
|
||||
|
||||
<img width="700" alt="out1" src="https://github.com/crazywhalecc/static-php-cli/assets/20330940/01a2e60f-13b0-4242-a645-f7afa4936396">
|
||||
|
||||
**使用 phpmicro 将 PHP 代码与 PHP 解释器结合:**
|
||||
|
||||
<img width="700" alt="out2" src="https://github.com/crazywhalecc/static-php-cli/assets/20330940/46b7128d-fb72-4169-957e-48564c3ff3e2">
|
||||
|
||||
## 快速开始
|
||||
|
||||
### 1. 下载 spc 二进制文件
|
||||
|
||||
```bash
|
||||
# Linux x86_64
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64
|
||||
# Linux aarch64
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-aarch64
|
||||
# macOS x86_64 (Intel)
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-x86_64
|
||||
# macOS aarch64 (Apple)
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-aarch64
|
||||
# Windows (x86_64, win10 build 17063 或更高版本,请先安装 VS2022)
|
||||
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe
|
||||
```
|
||||
|
||||
对于 macOS 和 Linux,请先添加执行权限:
|
||||
|
||||
```bash
|
||||
chmod +x ./spc
|
||||
```
|
||||
|
||||
### 2. 构建静态 PHP
|
||||
|
||||
首先,创建一个 `craft.yml` 文件,并从 [扩展列表](https://static-php.dev/zh/guide/extensions.html) 或 [命令生成器](https://static-php.dev/zh/guide/cli-generator.html) 中指定要包含的扩展:
|
||||
|
||||
```yml
|
||||
# PHP 版本支持:8.1, 8.2, 8.3, 8.4, 8.5
|
||||
php-version: 8.4
|
||||
# 在此处放置您的扩展列表
|
||||
extensions: "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib"
|
||||
sapi:
|
||||
- cli
|
||||
- micro
|
||||
- fpm
|
||||
download-options:
|
||||
prefer-pre-built: true
|
||||
```
|
||||
|
||||
运行命令:
|
||||
|
||||
```bash
|
||||
./spc craft
|
||||
|
||||
# 输出完整控制台日志
|
||||
./spc craft --debug
|
||||
```
|
||||
|
||||
### 3. 静态 PHP 使用
|
||||
|
||||
现在您可以将 static-php-cli 构建的二进制文件复制到另一台机器上,无需依赖即可运行:
|
||||
|
||||
```
|
||||
# php-cli
|
||||
buildroot/bin/php -v
|
||||
|
||||
# phpmicro
|
||||
echo '<?php echo "Hello world!\n";' > a.php
|
||||
./spc micro:combine a.php -O my-app
|
||||
./my-app
|
||||
|
||||
# php-fpm
|
||||
buildroot/bin/php-fpm -v
|
||||
```
|
||||
|
||||
## 文档
|
||||
|
||||
当前 README 包含基本用法。有关 static-php-cli 的所有功能,
|
||||
请访问 <https://static-php.dev>。
|
||||
|
||||
## 直接下载
|
||||
|
||||
如果您不想构建或想先测试,可以从 [Actions](https://github.com/static-php/static-php-cli-hosted/actions/workflows/build-php-bulk.yml) 下载示例预编译工件,或从自托管服务器下载。
|
||||
|
||||
以下是几个具有不同扩展组合的预编译静态 PHP 二进制文件,
|
||||
您可以根据需要直接下载。
|
||||
|
||||
| 组合名称 | 扩展数量 | 系统 | 备注 |
|
||||
|----------------------------------------------------------------------|----------------------------------------------------------------------------|--------------|--------------------|
|
||||
| [common](https://dl.static-php.dev/static-php-cli/common/) | [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) | Linux, macOS | 二进制文件大小约为 7.5MB |
|
||||
| [bulk](https://dl.static-php.dev/static-php-cli/bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux, macOS | 二进制文件大小约为 25MB |
|
||||
| [gnu-bulk](https://dl.static-php.dev/static-php-cli/gnu-bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux, macOS | 使用 glibc 的 bulk 组合 |
|
||||
| [minimal](https://dl.static-php.dev/static-php-cli/minimal/) | [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) | Linux, macOS | 二进制文件大小约为 3MB |
|
||||
| [spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/) | [5](https://dl.static-php.dev/static-php-cli/windows/spc-min/README.txt) | Windows | 二进制文件大小约为 3MB |
|
||||
| [spc-max](https://dl.static-php.dev/static-php-cli/windows/spc-max/) | [40+](https://dl.static-php.dev/static-php-cli/windows/spc-max/README.txt) | Windows | 二进制文件大小约为 8.5MB |
|
||||
|
||||
> Linux 和 Windows 支持对二进制文件进行 UPX 压缩,可以将二进制文件大小减少 30% 到 50%。
|
||||
> macOS 不支持 UPX 压缩,因此 mac 的预构建二进制文件大小较大。
|
||||
|
||||
### 在线构建(使用 GitHub Actions)
|
||||
|
||||
上方直接下载的二进制不能满足需求时,可使用 GitHub Action 可以轻松构建静态编译的 PHP,
|
||||
同时自行定义要编译的扩展。
|
||||
|
||||
1. Fork 本项目。
|
||||
2. 进入项目的 Actions 并选择 `CI`。
|
||||
3. 选择 `Run workflow`,填入您要编译的 PHP 版本、目标类型和扩展列表。(扩展用逗号分隔,例如 `bcmath,curl,mbstring`)
|
||||
4. 等待一段时间后,进入相应的任务并获取 `Artifacts`。
|
||||
|
||||
如果您启用 `debug`,构建时将输出所有日志,包括编译日志,以便故障排除。
|
||||
|
||||
## 贡献
|
||||
|
||||
如果您需要的扩展缺失,可以创建 issue。
|
||||
如果您熟悉本项目,也欢迎发起 pull request。
|
||||
|
||||
如果您想贡献文档,请直接编辑 `docs/` 目录。
|
||||
|
||||
现在有一个 [static-php](https://github.com/static-php) 组织,用于存储与项目相关的仓库。
|
||||
|
||||
## 赞助本项目
|
||||
|
||||
您可以从 [GitHub Sponsor](https://github.com/crazywhalecc) 赞助我或我的项目。您捐赠的一部分将用于维护 **static-php.dev** 服务器。
|
||||
|
||||
**特别感谢以下赞助商**:
|
||||
|
||||
<a href="https://beyondco.de/"><img src="/docs/public/images/beyondcode-seeklogo.png" width="300" alt="Beyond Code Logo" /></a>
|
||||
|
||||
<a href="https://nativephp.com/"><img src="/docs/public/images/nativephp-logo.svg" width="300" alt="NativePHP Logo" /></a>
|
||||
|
||||
## 开源许可证
|
||||
|
||||
本项目本身基于 MIT 许可证,
|
||||
一些新添加的扩展和依赖可能来自其他项目,
|
||||
这些代码文件的头部也会给出额外的许可证和作者说明。
|
||||
|
||||
这些是类似的项目:
|
||||
|
||||
- [dixyes/lwmbs](https://github.com/dixyes/lwmbs)
|
||||
- [swoole/swoole-cli](https://github.com/swoole/swoole-cli)
|
||||
|
||||
本项目使用了 [dixyes/lwmbs](https://github.com/dixyes/lwmbs) 的一些代码,例如 Windows 静态构建目标和 libiconv 支持。
|
||||
lwmbs 基于 [Mulan PSL 2](http://license.coscl.org.cn/MulanPSL2) 许可证。
|
||||
|
||||
由于本项目的特殊性,
|
||||
项目编译过程中会使用许多其他开源项目,如 curl 和 protobuf,
|
||||
它们都有自己的开源许可证。
|
||||
|
||||
请在编译后使用 `bin/spc dump-license` 命令导出项目中使用的开源许可证,
|
||||
并遵守相应项目的 LICENSE。
|
||||
289
README.md
289
README.md
@@ -1,174 +1,225 @@
|
||||
# static-php-cli
|
||||
Compile A Statically Linked PHP With Swoole and other Extensions. [English README](README-en.md)
|
||||
|
||||
[](README-zh.md)
|
||||
[](README.md)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/releases)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/actions/workflows/tests.yml)
|
||||
[](https://github.com/crazywhalecc/static-php-cli/blob/main/LICENSE)
|
||||
编译纯静态的 PHP Binary 二进制文件,带有各种扩展,让 PHP-cli 应用变得更便携!
|
||||
|
||||
**static-php-cli** is a powerful tool designed for building static, standalone PHP runtime
|
||||
with popular extensions.
|
||||
同时可以使用 micro 二进制文件,将 PHP 源码和 PHP 二进制构建为一个文件分发!
|
||||
|
||||
## Features
|
||||
注:只能编译 CLI 模式,暂不支持 CGI 和 FPM 模式
|
||||
|
||||
- :elephant: Support multiple PHP versions - PHP 8.1, 8.2, 8.3, 8.4, 8.5
|
||||
- :handbag: Build single-file PHP executable with zero dependencies
|
||||
- :hamburger:Build **[phpmicro](https://github.com/dixyes/phpmicro)** self-extracting executables (combines PHP binary and source code into one file)
|
||||
- :pill: Automatic build environment checker with auto-fix capabilities
|
||||
- :zap: `Linux`, `macOS`, `FreeBSD`, `Windows` support
|
||||
- :wrench: Configurable source code patching
|
||||
- :books: Intelligent dependency management
|
||||
- 📦 Self-contained `spc` executable (built with [box](https://github.com/box-project/box))
|
||||
- :fire: Support 100+ popular [extensions](https://static-php.dev/en/guide/extensions.html)
|
||||
- :floppy_disk: UPX compression support (reduces binary size by 30-50%)
|
||||
[]()
|
||||
[]()
|
||||

|
||||
|
||||
**Single-file standalone php-cli:**
|
||||
## 重构
|
||||
|
||||
<img width="700" alt="out1" src="https://github.com/crazywhalecc/static-php-cli/assets/20330940/01a2e60f-13b0-4242-a645-f7afa4936396">
|
||||
本分支为旧版。重构版支持很多新特性。下面是目前重构的进度:
|
||||
|
||||
**Combine PHP code with PHP interpreter using phpmicro:**
|
||||
- **关于重构版的讨论:https://github.com/crazywhalecc/static-php-cli/discussions/29**
|
||||
- **重构的分支:[refactor](https://github.com/crazywhalecc/static-php-cli/tree/refactor)**
|
||||
- **重构的问题和待办:https://github.com/crazywhalecc/static-php-cli/issues/32**
|
||||
|
||||
<img width="700" alt="out2" src="https://github.com/crazywhalecc/static-php-cli/assets/20330940/46b7128d-fb72-4169-957e-48564c3ff3e2">
|
||||
**目前重构版已经完成本分支的所有扩展,并且还支持更多扩展**。
|
||||
|
||||
## Quickstart
|
||||
## 编译环境需求
|
||||
|
||||
### 1. Download spc binary
|
||||
- 目前支持 arm64、x86_64、armv7l 架构
|
||||
- 需要 Docker(也可以直接在 Alpine Linux 上使用)
|
||||
- 脚本支持编译的 PHP 版本(7.2 ~ 8.1)
|
||||
|
||||
## 运行环境需求
|
||||
|
||||
Linux
|
||||
|
||||
## 直接使用
|
||||
|
||||
1. 可以直接下面的托管服务器或到 `Actions` 找到最新的构建项目下载 Actions 构建的文件。
|
||||
|
||||
<https://dl.zhamao.xin/php-bin/file/>
|
||||
|
||||
2. 可以直接使用快速脚本 `install-runtime.sh`,将静态 PHP 二进制及 Composer 下载到当前目录的 `runtime/` 子目录下:
|
||||
|
||||
```bash
|
||||
# For Linux x86_64
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64
|
||||
# For Linux aarch64
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-aarch64
|
||||
# macOS x86_64 (Intel)
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-x86_64
|
||||
# macOS aarch64 (Apple)
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-aarch64
|
||||
# Windows (x86_64, win10 build 17063 or later, please install VS2022 first)
|
||||
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe
|
||||
# 可以使用 export ZM_DOWN_PHP_VERION=8.0 来切换 PHP 版本
|
||||
bash <(curl -fsSL https://dl.zhamao.xin/php-bin/install-runtime.sh)
|
||||
```
|
||||
|
||||
For macOS and Linux, add execute permission first:
|
||||
## PHP 代码打包使用
|
||||
|
||||
v1.5.0 脚本开始,脚本新增了对 PHP 代码打包的支持,可以将 PHP 代码打包为一个文件分发,方便在 Linux 系统使用。(仅支持 PHP >= 8.0)
|
||||
|
||||
1. 可以直接在上面的下载链接中下载 `micro-` 开头的文件并解压,获得 `micro.sfx` 文件后,使用以下命令和 PHP 源码或 PHAR 结合:
|
||||
|
||||
```bash
|
||||
chmod +x ./spc
|
||||
echo "<?php echo 'Hello world' . PHP_EOL;" > code.php
|
||||
cat micro.sfx code.php > single-app && chmod +x single-app
|
||||
./single-app
|
||||
|
||||
# 如果打包 PHAR 文件,仅需把 code.php 更换为 phar 文件路径即可
|
||||
```
|
||||
|
||||
### 2. Build Static PHP
|
||||
2. 如果打包项目,可以先将项目打包为 phar + entry,然后结合打包 micro 与 phar 文件即可。
|
||||
|
||||
First, create a `craft.yml` file and specify which extensions you want to include from [extension list](https://static-php.dev/en/guide/extensions.html) or [command generator](https://static-php.dev/en/guide/cli-generator.html):
|
||||
> 关于如何将项目打包为 phar,见项目 [php-cli-helper](https://github.com/crazywhalecc/php-cli-helper)。
|
||||
|
||||
```yml
|
||||
# PHP version support: 8.1, 8.2, 8.3, 8.4, 8.5
|
||||
php-version: 8.4
|
||||
# Put your extension list here
|
||||
extensions: "apcu,bcmath,calendar,ctype,curl,dba,dom,exif,fileinfo,filter,gd,iconv,mbregex,mbstring,mysqli,mysqlnd,opcache,openssl,pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,readline,redis,session,simplexml,sockets,sodium,sqlite3,tokenizer,xml,xmlreader,xmlwriter,xsl,zip,zlib"
|
||||
sapi:
|
||||
- cli
|
||||
- micro
|
||||
- fpm
|
||||
download-options:
|
||||
prefer-pre-built: true
|
||||
```
|
||||
> 感谢 <https://github.com/dixyes/phpmicro> 项目提供的支持
|
||||
|
||||
Run command:
|
||||
## 自行编译
|
||||
|
||||
可以自己使用 Dockerfile 进行编译构建:
|
||||
|
||||
```bash
|
||||
./spc craft
|
||||
|
||||
# Output full console log
|
||||
./spc craft --debug
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git
|
||||
cd static-php-cli/docker
|
||||
export DOCKER_BUILDKIT=1
|
||||
docker build -t static-php . --build-arg USE_BACKUP_ADDRESS=no
|
||||
# 新建一个用于放置构建好的二进制的文件夹
|
||||
mkdir dist
|
||||
# 终端会引导你进行编译安装,可选择 PHP 版本、要编译的扩展
|
||||
docker run --rm -v $(pwd)/dist:/dist/ -it static-php build-php
|
||||
```
|
||||
|
||||
### 3. Static PHP usage
|
||||
编译之后可以使用下方命令将二进制 PHP 提取出来,用以下方式:
|
||||
|
||||
Now you can copy binaries built by static-php-cli to another machine and run with no dependencies:
|
||||
|
||||
```
|
||||
# php-cli
|
||||
buildroot/bin/php -v
|
||||
|
||||
# phpmicro
|
||||
echo '<?php echo "Hello world!\n";' > a.php
|
||||
./spc micro:combine a.php -O my-app
|
||||
./my-app
|
||||
|
||||
# php-fpm
|
||||
buildroot/bin/php-fpm -v
|
||||
```bash
|
||||
cd dist
|
||||
file ./php
|
||||
# 如果是 PHP 8.0 以上,同时会输出 micro 构建版本
|
||||
file ./micro.sfx
|
||||
```
|
||||
|
||||
## Documentation
|
||||
如果你不想使用 Docker,想从Alpine环境直接编译,可以使用预置相同编译配置的脚本 `fast-compiler.sh`:
|
||||
|
||||
The current README contains basic usage. For all the features of static-php-cli,
|
||||
see <https://static-php.dev> .
|
||||
```bash
|
||||
cd docker
|
||||
# 用于切换编译的PHP版本
|
||||
export VER_PHP="8.1.7"
|
||||
./fast-compiler.sh
|
||||
```
|
||||
|
||||
## Direct Download
|
||||
如果要选择安装的扩展,可以修改 `docker/extensions.txt` 文件,具体规则如下:
|
||||
- 文件内使用 `^` 可以表示默认不安装该扩展,`#` 开头可以编写注释
|
||||
- 扩展名一律使用小写,目前默认状态下文件内所列的扩展为支持的扩展,其他扩展暂不支持,如有需求请提 Issue 添加
|
||||
|
||||
If you don't want to build or want to test first, you can download example pre-compiled artifact from [Actions](https://github.com/static-php/static-php-cli-hosted/actions/workflows/build-php-bulk.yml), or from self-hosted server.
|
||||
## 支持的扩展表
|
||||
| 是否支持 | PHP 扩展名称 | 支持版本 | 备注 |
|
||||
| -------- | ------------ | -------- | ------------------------------------------------------- |
|
||||
| yes, enabled | bcmath | * | |
|
||||
| yes, enabled | calendar | * | |
|
||||
| yes, enabled | ctype | * | |
|
||||
| yes, enabled | curl | * | 自带下载编译 curl 库 |
|
||||
| yes, enabled | dom | * | |
|
||||
| yes, enabled | event | >=3.0.8 | 从 BitBucket 作者仓库下载,非 pecl 版本 |
|
||||
| yes, enabled | exif | * | |
|
||||
| yes, enabled | filter | * | |
|
||||
| yes, enabled | fileinfo | * | |
|
||||
| yes, enabled | gd | * | |
|
||||
| yes, enabled | hash | * | |
|
||||
| yes, enabled | iconv | * | |
|
||||
| yes, enabled | inotify | 3.0.0 | 从 pecl 或镜像站下载的源码 |
|
||||
| yes, enabled | json | * | |
|
||||
| yes, enabled | libxml | * | 自带下载编译 libxml2 库 |
|
||||
| yes, enabled | mbstring | * | |
|
||||
| yes, enabled | mongodb | >=1.9.1 | 未测试,从 pecl 或镜像站下载的源码 |
|
||||
| | mysqli | | |
|
||||
| yes, enabled | mysqlnd | * | |
|
||||
| yes, enabled | openssl | * | |
|
||||
| yes, enabled | pcntl | * | |
|
||||
| yes, enabled | pdo | * | |
|
||||
| yes, enabled | pdo_mysql | * | |
|
||||
| yes, enabled | pdo_sqlite | * | |
|
||||
| | pdo_pgsql | * | |
|
||||
| yes, enabled | phar | * | |
|
||||
| yes, enabled | posix | * | |
|
||||
| yes, not enabled | protobuf | * | 默认不编译 |
|
||||
| yes, enabled | readline | * | 不支持 `./php -a` |
|
||||
| yes, enabled | redis | * | 从 pecl 或镜像站下载的源码 |
|
||||
| yes, enabled | shmop | * | |
|
||||
| yes, enabled | simplexml | * | |
|
||||
| yes, enabled | soap | * | |
|
||||
| yes, enabled | sockets | * | |
|
||||
| yes, enabled | sqlite3 | * | |
|
||||
| yes, enabled | swoole | >=4.6.6 | 使用参数 `--enable-openssl --with-openssl --with-openssl-dir=/usr`,从 pecl 或镜像站下载的源码 |
|
||||
| yes, enabled | tokenizer | * | |
|
||||
| yes, enabled | xml | * | |
|
||||
| yes, enabled | xmlreader | * | |
|
||||
| yes, enabled | xmlwriter | * | |
|
||||
| yes, enabled | zip | * | 因链接库原因已关闭 `libzip` 库的 `bzip2` 和 `lzma` 支持 |
|
||||
| yes, enabled | zlib | * | |
|
||||
|
||||
Below are several precompiled static-php binaries with different extension combinations,
|
||||
which can be downloaded directly according to your needs.
|
||||
## 自定义
|
||||
- 从 Docker 运行编译,会依次询问下载地址、PHP 版本、要编译的扩展、编译输出文件夹。
|
||||
- 如果不想弹出终端交互框,只需按照下方给出的参数加到字符串的后面。
|
||||
|
||||
| Combination | Extension Count | OS | Comment |
|
||||
|----------------------------------------------------------------------|----------------------------------------------------------------------------|--------------|--------------------------------|
|
||||
| [common](https://dl.static-php.dev/static-php-cli/common/) | [30+](https://dl.static-php.dev/static-php-cli/common/README.txt) | Linux, macOS | The binary size is about 7.5MB |
|
||||
| [bulk](https://dl.static-php.dev/static-php-cli/bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux, macOS | The binary size is about 25MB |
|
||||
| [gnu-bulk](https://dl.static-php.dev/static-php-cli/gnu-bulk/) | [50+](https://dl.static-php.dev/static-php-cli/bulk/README.txt) | Linux, macOS | Using shared glibc |
|
||||
| [minimal](https://dl.static-php.dev/static-php-cli/minimal/) | [5](https://dl.static-php.dev/static-php-cli/minimal/README.txt) | Linux, macOS | The binary size is about 3MB |
|
||||
| [spc-min](https://dl.static-php.dev/static-php-cli/windows/spc-min/) | [5](https://dl.static-php.dev/static-php-cli/windows/spc-min/README.txt) | Windows | The binary size is about 3MB |
|
||||
| [spc-max](https://dl.static-php.dev/static-php-cli/windows/spc-max/) | [40+](https://dl.static-php.dev/static-php-cli/windows/spc-max/README.txt) | Windows | The binary size is about 8.5MB |
|
||||
> `参数1`: `original` 代表使用原始地址,如果你位于中国大陆,可使用 `mirror` 加快下载。
|
||||
>
|
||||
> `参数2`: `8.1.7` 是你要编译的 PHP 版本。
|
||||
>
|
||||
> `参数3`: `all` 代表你要编译所有非反选的扩展,不询问。
|
||||
>
|
||||
> `参数4`: `/dist/` 是你编译后输出二进制 PHP 和 micro 的文件夹
|
||||
>
|
||||
> 基本例子: `docker run --rm -v $(pwd)/dist:/dist/ -it static-php build-php original 8.1.7 all /dist/`
|
||||
|
||||
> Linux and Windows supports UPX compression for binaries, which can reduce the size of the binary by 30% to 50%.
|
||||
> macOS does not support UPX compression, so the size of the pre-built binaries for mac is larger.
|
||||
- `docker/extensions.txt` 指定要编译安装的扩展。
|
||||
- `docker/extensions.txt` 中,`^` 开头的扩展名为反选,反选的扩展将出现在编译的扩展列表中,但默认不选中。
|
||||
- `docker/compile-php.sh` 中的 `php_compile_args` 函数来调整 PHP 编译参数。
|
||||
- `docker/check-extensions.sh` 中的 `check_in_configure` 函数可调整 PHP 扩展编译的参数。
|
||||
- `docker/config.json` 可调整要下载的扩展和依赖库版本和链接。
|
||||
- `docker/fast-compiler.sh` 可以在 Alpine Linux 系统下直接运行。
|
||||
|
||||
### Build Online (using GitHub Actions)
|
||||
## 目前的问题(对勾为已解决)
|
||||
- [X] 不支持 event(libevent) 扩展,event 扩展的 sockets 支持不能在静态编译中使用,因为静态内嵌编译暂时没办法调整扩展编译顺序,同时其本身也不支持静态编译。
|
||||
- [ ] Swoole 扩展不支持 `--enable-swoole-curl`,也是因为编译顺序和加载顺序的问题。
|
||||
- [X] 不支持 readline 扩展,readline 扩展安装后无法正常使用 `php -a`,原因还没有弄清楚,可能是静态编译造成的 ncurses 库出现了问题。
|
||||
- [X] curl/libcurl 扩展静态编译
|
||||
- [X] 可自行选择不需要编译进入的扩展
|
||||
- [X] php.ini 内嵌或分发
|
||||
- [X] i18n(国际化脚本本身和 README)
|
||||
|
||||
When the above direct download binaries cannot meet your needs,
|
||||
you can use GitHub Action to easily build a statically compiled PHP,
|
||||
and at the same time define the extensions to be compiled by yourself.
|
||||
如果你对以上问题有解决方案,请提出 Issue 或 PR!
|
||||
|
||||
1. Fork me.
|
||||
2. Go to the Actions of the project and select `CI`.
|
||||
3. Select `Run workflow`, fill in the PHP version you want to compile, the target type, and the list of extensions. (extensions comma separated, e.g. `bcmath,curl,mbstring`)
|
||||
4. After waiting for about a period of time, enter the corresponding task and get `Artifacts`.
|
||||
如果你对此脚本比较感兴趣,未来会在此编写脚本中涉及内容的解析和说明。
|
||||
|
||||
If you enable `debug`, all logs will be output at build time, including compiled logs, for troubleshooting.
|
||||
## 运行示例
|
||||
|
||||
## Contribution
|
||||
### 静态 PHP 运行脚本
|
||||
|
||||
If the extension you need is missing, you can create an issue.
|
||||
If you are familiar with this project, you are also welcome to initiate a pull request.
|
||||
<img width="881" alt="未命名" src="https://user-images.githubusercontent.com/20330940/168441751-e62cb8d4-a3c8-42d9-b34e-d804b39756a1.png">
|
||||
|
||||
If you want to contribute documentation, please just edit in `docs/`.
|
||||
### micro 打包运行 Swoole
|
||||
|
||||
Now there is a [static-php](https://github.com/static-php) organization, which is used to store the repo related to the project.
|
||||
<img width="937" alt="all" src="https://user-images.githubusercontent.com/20330940/168557743-b8f92263-712f-490e-9fe0-831597741595.png">
|
||||
|
||||
## Sponsor this project
|
||||
## 原理
|
||||
|
||||
You can sponsor me or my project from [GitHub Sponsor](https://github.com/crazywhalecc). A portion of your donation will be used to maintain the **static-php.dev** server.
|
||||
静态编译是一项比较多见于 Golang 的编译方式,在传统的 Linux 系统下,正常的程序和库基本是动态编译链接(Dynamically linked)的,也就是说,不同程序引用同样的库可以共用,减少资源重复。
|
||||
|
||||
**Special thanks to sponsors below**:
|
||||
但是由于不少系统软件环境配置复杂,或者依赖的库版本冲突,一般使用 Docker 等容器技术可以解决这一问题。但 Docker 等容器也需要拉取镜像,体积较大,对于程序有便携需求的人(比如网络安全员做渗透测试等)需要很多程序可以像 Windows 上的绿色程序一样随处打包运行。
|
||||
|
||||
<a href="https://beyondco.de/"><img src="/docs/public/images/beyondcode-seeklogo.png" width="300" alt="Beyond Code Logo" /></a>
|
||||
PHP 是最好的编程语言,它编写容易,易于部署和开发,倘若将 PHP 编译为静态的文件,并且将 Swoole 或 libevent 等库同样内嵌,那 PHP 不仅将可以编写便携的 Web 服务器,还能做很多想不到的事!
|
||||
|
||||
<a href="https://nativephp.com/"><img src="/docs/public/images/nativephp-logo.svg" width="300" alt="NativePHP Logo" /></a>
|
||||
编译静态 PHP 大致分为以下几个步骤:
|
||||
1. 下载 PHP 源码
|
||||
2. 下载需要静态编译的额外扩展源码(如 inotify、mongodb、redis 等)
|
||||
3. 将额外扩展源码放入 PHP 源码中
|
||||
4. 生成 `configure` 并使用 `-static` 的 FLAG 进行生成 makefile
|
||||
5. 修改 Makefile 中的编译参数,增加 `-all-static` 和去掉 dynamic 相关的参数
|
||||
6. 使用 `make` 构建静态 PHP
|
||||
7. 使用 `make install` 安装到指定目录,再使用 `strip` 去除符号表缩小体积
|
||||
|
||||
## Open-Source License
|
||||
对于第二步,如果额外扩展中有依赖 Linux 的其他库(比如 curl 依赖 libcurl),则需要在第二步之前编译安装对应库的静态版本(比如 libxml2.a)
|
||||
|
||||
This project itself is based on MIT License,
|
||||
some newly added extensions and dependencies may originate from the the other projects,
|
||||
and the headers of these code files will also be given additional instructions LICENSE and AUTHOR.
|
||||
而此处出问题最多的部分就是安装额外扩展的依赖上,很多库不支持静态编译,而互联网很难找到对对应库进行静态编译的资料。
|
||||
|
||||
These are similar projects:
|
||||
脚本和 Dockerfile 统一采用 Alpine 的目的就是,apk 包管理下有很多库提供了 `*-static` 静态版本,直接使用包管理安装就可以使用,而即使没有,也可以使用 musl-libc 进行静态编译,避免 glibc 下的 `libnss` 等无法静态编译的问题。
|
||||
|
||||
- [dixyes/lwmbs](https://github.com/dixyes/lwmbs)
|
||||
- [swoole/swoole-cli](https://github.com/swoole/swoole-cli)
|
||||
第二种要面对比较棘手的问题就是 PHP 扩展可能本身不支持静态编译(如 curl 扩展),有些通过绕过手段可以静态编译,但有些只能通过对扩展源码进行修改才能使其支持。
|
||||
|
||||
The project uses some code from [dixyes/lwmbs](https://github.com/dixyes/lwmbs), such as windows static build target and libiconv support.
|
||||
lwmbs is licensed under the [Mulan PSL 2](http://license.coscl.org.cn/MulanPSL2).
|
||||
所以这个项目中涉及的脚本,最大的问题就在于对其他依赖的处理,而不是 PHP 编译本身。PHP 如果不启用任何扩展(即使用 `--disable-all`),则可以很方便地静态编译。
|
||||
|
||||
Due to the special nature of this project,
|
||||
many other open source projects such as curl and protobuf will be used during the project compilation process,
|
||||
and they all have their own open source licenses.
|
||||
|
||||
Please use the `bin/spc dump-license` command to export the open source licenses used in the project after compilation,
|
||||
and comply with the corresponding project's LICENSE.
|
||||
## 参考资料
|
||||
- <https://blog.terrywh.net/post/2019/php-static-openssl/>
|
||||
- <https://stackoverflow.com/a/37245653>
|
||||
- <http://blog.gaoyuan.xyz/2014/04/09/statically-compile-php/>
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
TARGET_DIR="/app/pkgroot/$(uname -m)-linux"
|
||||
BACKUP_DIR="/app/pkgroot-private"
|
||||
# copy private pkgroot to pkgroot if pkgroot is empty
|
||||
if [ ! -d "$TARGET_DIR" ] || [ -z "$(ls -A "$TARGET_DIR")" ]; then
|
||||
echo "* Copying private pkgroot to pkgroot ..."
|
||||
rm -rf "$TARGET_DIR"
|
||||
cp -r "$BACKUP_DIR" "$TARGET_DIR"
|
||||
fi
|
||||
exec "$@"
|
||||
@@ -1,74 +0,0 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
# set error-quit, verbose, non-variable-quit
|
||||
set -eu
|
||||
# see what system used
|
||||
__OS__=$(uname -s)
|
||||
# see what arch used
|
||||
__ARCH__=$(uname -m)
|
||||
# format arch name
|
||||
case $__ARCH__ in
|
||||
arm64 | aarch64) __ARCH__=aarch64 ;;
|
||||
x86_64|x64) __ARCH__=x86_64 ;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
# format uname
|
||||
case $__OS__ in
|
||||
Darwin) __OS_FIXED__=macos ;;
|
||||
Linux) __OS_FIXED__=linux ;;
|
||||
*) echo "Current OS is not supported" && exit 1 ;;
|
||||
esac
|
||||
|
||||
# set project dir
|
||||
__DIR__=$(cd "$(dirname "$0")" && pwd)
|
||||
__PROJECT__=$(cd "${__DIR__}"/../ && pwd)
|
||||
|
||||
# set download dir
|
||||
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.4.12-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar"
|
||||
|
||||
# use china mirror
|
||||
# bash bin/setup-runtime --mirror china
|
||||
mirror=''
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--mirror)
|
||||
mirror="$2"
|
||||
;;
|
||||
--*)
|
||||
echo "Illegal option $1"
|
||||
;;
|
||||
esac
|
||||
shift $(($# > 0 ? 1 : 0))
|
||||
done
|
||||
|
||||
case "$mirror" in
|
||||
china)
|
||||
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.4.12-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__COMPOSER_URL__="https://mirrors.tencent.com/composer/composer.phar"
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
if ! command -v curl > /dev/null && command -v apk > /dev/null; then
|
||||
apk add --no-cache curl
|
||||
fi
|
||||
|
||||
test -d "${__PROJECT__}"/downloads || mkdir "${__PROJECT__}"/downloads
|
||||
# download static php binary
|
||||
test -f "${__PROJECT__}"/downloads/runtime.tar.gz || { echo "Downloading $__PHP_RUNTIME_URL__ ..." && curl -#fSL -o "${__PROJECT__}"/downloads/runtime.tar.gz "$__PHP_RUNTIME_URL__" ; }
|
||||
test -f "${__DIR__}"/php || { tar -xf "${__PROJECT__}"/downloads/runtime.tar.gz -C "${__DIR__}"/ ; }
|
||||
chmod +x "${__DIR__}"/php
|
||||
# download composer
|
||||
test -f "${__DIR__}"/composer || { echo "Downloading Composer from $__COMPOSER_URL__" && curl -#fSL -o "${__DIR__}"/composer "$__COMPOSER_URL__" ; }
|
||||
chmod +x "${__DIR__}"/composer
|
||||
# sanity check for php and composer
|
||||
"${__DIR__}"/php -v >/dev/null || { echo "Failed to run php" && exit 1; }
|
||||
"${__DIR__}"/php "${__DIR__}"/composer --version >/dev/null || { echo "Failed to run composer" && exit 1; }
|
||||
|
||||
echo "Setup runtime OK!"
|
||||
echo "runtime bin path needs to add manually by command below:"
|
||||
echo ""
|
||||
echo " export PATH=\"${__DIR__}:\$PATH\""
|
||||
echo ""
|
||||
@@ -1,116 +0,0 @@
|
||||
param (
|
||||
[string] ${action}
|
||||
)
|
||||
|
||||
function AddToPath {
|
||||
param (
|
||||
[string]$pathToAdd
|
||||
)
|
||||
|
||||
$currentPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
|
||||
if ($currentPath -notlike "*$pathToAdd*") {
|
||||
$newPath = $currentPath + ";$pathToAdd"
|
||||
[System.Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
|
||||
Write-Host "Added '$pathToAdd' to Path."
|
||||
Write-Host "To remove path, use: " -NoNewline
|
||||
Write-Host "bin/setup-runtime remove-path" -ForegroundColor Cyan
|
||||
} else {
|
||||
Write-Host "Path already exists."
|
||||
}
|
||||
}
|
||||
|
||||
function RemoveFromPath {
|
||||
param (
|
||||
[string]$pathToRemove
|
||||
)
|
||||
|
||||
$currentPath = [System.Environment]::GetEnvironmentVariable('Path', 'User')
|
||||
|
||||
if ($currentPath -like "*$pathToRemove*") {
|
||||
$newPath = $currentPath -replace [regex]::Escape(';' + $pathToRemove), ''
|
||||
[System.Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
|
||||
Write-Host "Removed Path '$pathToRemove'"
|
||||
} else {
|
||||
Write-Host "Path '$pathToRemove' not in Path"
|
||||
}
|
||||
}
|
||||
|
||||
# working dir
|
||||
$WorkingDir = (Split-Path -Parent (Split-Path -Parent $MyInvocation.MyCommand.Definition))
|
||||
|
||||
if ($action -eq 'add-path') {
|
||||
AddToPath ($WorkingDir + '\runtime')
|
||||
exit 0
|
||||
} elseif ($action -eq 'remove-path') {
|
||||
RemoveFromPath ($WorkingDir + '\runtime')
|
||||
exit 0
|
||||
} elseif (-not($action -eq '')) {
|
||||
Write-Host ("Invalid action: " + $action) -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
|
||||
# get php 8.1 specific version
|
||||
|
||||
# php windows download
|
||||
$PHPRuntimeUrl = "https://windows.php.net/downloads/releases/archives/php-8.4.4-nts-Win32-vs17-x64.zip"
|
||||
Write-Host "Downloading PHP from: " -NoNewline
|
||||
Write-Host $PHPRuntimeUrl -ForegroundColor Cyan
|
||||
$ComposerUrl = "https://getcomposer.org/download/latest-stable/composer.phar"
|
||||
|
||||
# create dir
|
||||
New-Item -Path "downloads" -ItemType Directory -Force | Out-Null
|
||||
|
||||
# download php
|
||||
if (-not(Test-Path "downloads\php.zip"))
|
||||
{
|
||||
Write-Host "Downloading PHP ..."
|
||||
Invoke-WebRequest $PHPRuntimeUrl -OutFile "downloads\php.zip"
|
||||
}
|
||||
|
||||
# extract php
|
||||
New-Item -Path "runtime" -ItemType Directory -Force | Out-Null
|
||||
Write-Host "Extracting php.zip ..."
|
||||
Expand-Archive -Path "downloads/php.zip" -DestinationPath "runtime" -Force
|
||||
# make php.ini
|
||||
Move-Item -Path "runtime\php.ini-production" -Destination "runtime\php.ini" -Force
|
||||
$OriginINI = Get-Content -Path "runtime\php.ini" -Raw
|
||||
$OriginINI = $OriginINI -replace ';extension=openssl', 'extension=openssl'
|
||||
$OriginINI = $OriginINI -replace ';extension=curl', 'extension=curl'
|
||||
$OriginINI = $OriginINI -replace ';extension=mbstring', 'extension=mbstring'
|
||||
$OriginINI = $OriginINI -replace ';extension=sodium', 'extension=sodium'
|
||||
$OriginINI = $OriginINI -replace ';extension_dir = "./"', ('extension_dir = "' + (Split-Path -Parent $MyInvocation.MyCommand.Definition) + '\..\runtime\ext"')
|
||||
$OriginINI | Set-Content -Path "runtime\php.ini"
|
||||
|
||||
# download composer
|
||||
if (-not(Test-Path "runtime\composer.phar"))
|
||||
{
|
||||
Write-Host "Downloading composer ..."
|
||||
Invoke-WebRequest $ComposerUrl -OutFile "downloads\composer.phar"
|
||||
Move-Item -Path "downloads\composer.phar" -Destination "runtime\composer.phar" -Force
|
||||
}
|
||||
|
||||
# create runtime\composer.ps1
|
||||
$ComposerContent = '
|
||||
$WorkingDir = (Split-Path -Parent $MyInvocation.MyCommand.Definition)
|
||||
& ($WorkingDir + "\php.exe") (Join-Path $WorkingDir "\composer.phar") @args
|
||||
'
|
||||
$ComposerContent | Set-Content -Path 'runtime\composer.ps1' -Encoding UTF8
|
||||
|
||||
Write-Host "Successfully downloaded PHP and Composer !" -ForegroundColor Green
|
||||
Write-Host "Use static-php-cli: " -NoNewline
|
||||
Write-Host "bin/spc" -ForegroundColor Cyan
|
||||
Write-Host "Use php: " -NoNewline
|
||||
Write-Host "runtime/php" -ForegroundColor Cyan
|
||||
Write-Host "Use composer: " -NoNewline
|
||||
Write-Host "runtime/composer" -ForegroundColor Cyan
|
||||
Write-Host ""
|
||||
Write-Host "Don't forget installing composer dependencies '" -NoNewline
|
||||
Write-Host "runtime/composer install" -ForegroundColor Cyan -NoNewline
|
||||
Write-Host "' before using static-php-cli !"
|
||||
Write-Host ""
|
||||
Write-Host "If you want to use this PHP for quality tools (like phpstan, php-cs-fixer) or other project,"
|
||||
Write-Host "or use PHP, Composer as system executable,"
|
||||
Write-Host "use '" -NoNewline
|
||||
Write-Host "bin/setup-runtime add-path" -ForegroundColor Cyan -NoNewline
|
||||
Write-Host "' to add runtime dir in Path."
|
||||
35
bin/spc
35
bin/spc
@@ -1,35 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
use SPC\ConsoleApplication;
|
||||
use SPC\exception\ExceptionHandler;
|
||||
|
||||
// Load custom php if exists
|
||||
if (PHP_OS_FAMILY !== 'Windows' && PHP_BINARY !== (__DIR__ . '/php') && file_exists(__DIR__ . '/php') && is_executable(__DIR__ . '/php')) {
|
||||
pcntl_exec(__DIR__ . '/php', $argv);
|
||||
}
|
||||
|
||||
if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) {
|
||||
// Current: ./bin (git/project mode)
|
||||
require_once dirname(__DIR__) . '/vendor/autoload.php';
|
||||
} else {
|
||||
// Current: ./vendor/crazywhalecc/static-php-cli/bin (composer library mode)
|
||||
require_once dirname(__DIR__, 3) . '/autoload.php';
|
||||
}
|
||||
|
||||
// 防止 Micro 打包状态下不支持中文的显示(虽然这个项目目前好像没输出过中文?)
|
||||
if (PHP_OS_FAMILY === 'Windows' && Phar::running()) {
|
||||
exec('CHCP 65001');
|
||||
}
|
||||
|
||||
// Print deprecation notice on PHP < 8.4, use red and highlight background
|
||||
if (PHP_VERSION_ID < 80400) {
|
||||
echo "\e[43mDeprecation Notice: PHP < 8.4 is deprecated, please upgrade your PHP version.\e[0m\n";
|
||||
}
|
||||
|
||||
try {
|
||||
(new ConsoleApplication())->run();
|
||||
} catch (Exception $e) {
|
||||
ExceptionHandler::getInstance()->handle($e);
|
||||
exit(1);
|
||||
}
|
||||
@@ -1,227 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
# This file is using docker to run commands
|
||||
SPC_DOCKER_VERSION=v6
|
||||
|
||||
# Detect docker can run
|
||||
if ! which docker >/dev/null; then
|
||||
echo "Docker is not installed, please install docker first !"
|
||||
exit 1
|
||||
fi
|
||||
DOCKER_EXECUTABLE="docker"
|
||||
# shellcheck disable=SC2046
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
if [ "$SPC_USE_SUDO" != "yes" ]; then
|
||||
echo "Docker command requires sudo"
|
||||
# shellcheck disable=SC2039
|
||||
echo -n 'To use sudo to run docker, run "export SPC_USE_SUDO=yes" and run command again'
|
||||
exit 1
|
||||
fi
|
||||
DOCKER_EXECUTABLE="sudo docker"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Convert uname to gnu arch
|
||||
CURRENT_ARCH=$(uname -m)
|
||||
if [ "$CURRENT_ARCH" = "arm64" ]; then
|
||||
CURRENT_ARCH=aarch64
|
||||
fi
|
||||
if [ -z "$SPC_USE_ARCH" ]; then
|
||||
SPC_USE_ARCH=$CURRENT_ARCH
|
||||
fi
|
||||
# parse SPC_USE_ARCH
|
||||
case $SPC_USE_ARCH in
|
||||
x86_64|amd64)
|
||||
SPC_USE_ARCH=x86_64
|
||||
if [ "$CURRENT_ARCH" != "x86_64" ]; then
|
||||
PLATFORM_ARG="--platform linux/amd64"
|
||||
ALPINE_FROM=multiarch/alpine:x86_64-edge
|
||||
fi
|
||||
;;
|
||||
aarch64|arm64)
|
||||
SPC_USE_ARCH=aarch64
|
||||
if [ "$CURRENT_ARCH" != "aarch64" ]; then
|
||||
PLATFORM_ARG="--platform linux/arm64"
|
||||
ALPINE_FROM=multiarch/alpine:aarch64-edge
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Current arch is not supported to run in docker: $SPC_USE_ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
# if ALPINE_FROM is not set, use alpine:3.21
|
||||
if [ -z "$ALPINE_FROM" ]; then
|
||||
ALPINE_FROM=alpine:3.21
|
||||
fi
|
||||
if [ "$SPC_USE_ARCH" != "$CURRENT_ARCH" ]; then
|
||||
echo "* Using different arch needs to setup qemu-static for docker !"
|
||||
ALPINE_FROM=multiarch/alpine:$SPC_USE_ARCH-edge
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
$DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static:register --reset > /dev/null
|
||||
fi
|
||||
else
|
||||
ALPINE_FROM=alpine:3.21
|
||||
fi
|
||||
|
||||
if [ "$SPC_USE_MIRROR" = "yes" ]; then
|
||||
SPC_USE_MIRROR="RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories"
|
||||
else
|
||||
SPC_USE_MIRROR="RUN echo 'Using original repo'"
|
||||
fi
|
||||
|
||||
# Detect docker env is setup
|
||||
if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION; then
|
||||
echo "Docker container does not exist. Building docker image ..."
|
||||
$DOCKER_EXECUTABLE build $PLATFORM_ARG -t cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION -f- . <<EOF
|
||||
FROM $ALPINE_FROM
|
||||
$SPC_USE_MIRROR
|
||||
RUN apk update; \
|
||||
apk upgrade -a; \
|
||||
apk add --no-cache \
|
||||
autoconf \
|
||||
automake \
|
||||
gettext \
|
||||
bash \
|
||||
binutils \
|
||||
bison \
|
||||
build-base \
|
||||
cmake \
|
||||
curl \
|
||||
file \
|
||||
flex \
|
||||
g++ \
|
||||
gcc \
|
||||
git \
|
||||
jq \
|
||||
libgcc \
|
||||
libtool \
|
||||
libstdc++ \
|
||||
linux-headers \
|
||||
m4 \
|
||||
make \
|
||||
pkgconfig \
|
||||
re2c \
|
||||
wget \
|
||||
xz \
|
||||
gettext-dev \
|
||||
binutils-gold
|
||||
|
||||
RUN curl -#fSL https://dl.static-php.dev/static-php-cli/bulk/php-8.4.4-cli-linux-\$(uname -m).tar.gz | tar -xz -C /usr/local/bin && \
|
||||
chmod +x /usr/local/bin/php
|
||||
|
||||
RUN curl -#fSL https://getcomposer.org/download/latest-stable/composer.phar -o /usr/local/bin/composer && \
|
||||
chmod +x /usr/local/bin/composer
|
||||
|
||||
WORKDIR /app
|
||||
ADD ./src /app/src
|
||||
COPY ./composer.* /app/
|
||||
ADD ./bin /app/bin
|
||||
RUN composer install --no-dev
|
||||
ADD ./config /app/config
|
||||
RUN bin/spc doctor --auto-fix
|
||||
RUN bin/spc install-pkg upx
|
||||
|
||||
RUN mv /app/pkgroot/\$(uname -m)-linux /app/pkgroot-private
|
||||
ADD bin/docker-entrypoint.sh /bin/docker-entrypoint.sh
|
||||
RUN chmod +x /bin/docker-entrypoint.sh
|
||||
ENTRYPOINT ["/bin/docker-entrypoint.sh"]
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Check if in ci (local terminal can execute with -it)
|
||||
if [ -t 0 ]; then
|
||||
INTERACT=-it
|
||||
else
|
||||
INTERACT=''
|
||||
fi
|
||||
|
||||
# Mounting volumes
|
||||
MOUNT_LIST=""
|
||||
# shellcheck disable=SC2089
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/config:/app/config"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/src:/app/src"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/buildroot:/app/buildroot"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/log:/app/log"
|
||||
if [ -f "$(pwd)/craft.yml" ]; then
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/craft.yml:/app/craft.yml"
|
||||
fi
|
||||
|
||||
# Environment variable passthrough
|
||||
ENV_LIST=""
|
||||
ENV_LIST="$ENV_LIST -e SPC_FIX_DEPLOY_ROOT="$(pwd)""
|
||||
if [ ! -z "$GITHUB_TOKEN" ]; then
|
||||
ENV_LIST="$ENV_LIST -e GITHUB_TOKEN=$GITHUB_TOKEN"
|
||||
fi
|
||||
|
||||
# Intercept and rewrite --with-frankenphp-app option, and mount host path to /app/app
|
||||
FRANKENPHP_APP_PATH=""
|
||||
NEW_ARGS=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--with-frankenphp-app=*)
|
||||
FRANKENPHP_APP_PATH="${1#*=}"
|
||||
NEW_ARGS+=("--with-frankenphp-app=/app/app")
|
||||
shift
|
||||
;;
|
||||
--with-frankenphp-app)
|
||||
if [ -n "${2:-}" ]; then
|
||||
FRANKENPHP_APP_PATH="$2"
|
||||
NEW_ARGS+=("--with-frankenphp-app=/app/app")
|
||||
shift 2
|
||||
else
|
||||
NEW_ARGS+=("$1")
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
NEW_ARGS+=("$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Normalize the path and add mount if provided
|
||||
if [ -n "$FRANKENPHP_APP_PATH" ]; then
|
||||
# expand ~ to $HOME
|
||||
if [ "${FRANKENPHP_APP_PATH#~}" != "$FRANKENPHP_APP_PATH" ]; then
|
||||
FRANKENPHP_APP_PATH="$HOME${FRANKENPHP_APP_PATH#~}"
|
||||
fi
|
||||
# make absolute if relative
|
||||
case "$FRANKENPHP_APP_PATH" in
|
||||
/*) ABS_APP_PATH="$FRANKENPHP_APP_PATH" ;;
|
||||
*) ABS_APP_PATH="$(pwd)/$FRANKENPHP_APP_PATH" ;;
|
||||
esac
|
||||
MOUNT_LIST="$MOUNT_LIST -v $ABS_APP_PATH:/app/app"
|
||||
fi
|
||||
|
||||
# Run docker
|
||||
# shellcheck disable=SC2068
|
||||
# shellcheck disable=SC2086
|
||||
# shellcheck disable=SC2090
|
||||
if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
|
||||
echo "* Debug mode enabled, run docker in interactive mode."
|
||||
echo "* You can use 'exit' to exit the docker container."
|
||||
echo "* You can use 'bin/spc' like normal builds."
|
||||
echo "*"
|
||||
echo "* Mounted directories:"
|
||||
echo "* ./config: $(pwd)/config"
|
||||
echo "* ./src: $(pwd)/src"
|
||||
echo "* ./buildroot: $(pwd)/buildroot"
|
||||
echo "* ./source: $(pwd)/source"
|
||||
echo "* ./dist: $(pwd)/dist"
|
||||
echo "* ./downloads: $(pwd)/downloads"
|
||||
echo "* ./pkgroot: $(pwd)/pkgroot"
|
||||
echo "*"
|
||||
set -ex
|
||||
$DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION /bin/bash
|
||||
else
|
||||
$DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc "${NEW_ARGS[@]}"
|
||||
fi
|
||||
@@ -1,236 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
|
||||
# This file is using docker to run commands
|
||||
SPC_DOCKER_VERSION=v6
|
||||
|
||||
# Detect docker can run
|
||||
if ! which docker >/dev/null; then
|
||||
echo "Docker is not installed, please install docker first !"
|
||||
exit 1
|
||||
fi
|
||||
DOCKER_EXECUTABLE="docker"
|
||||
# shellcheck disable=SC2046
|
||||
if [ $(id -u) -ne 0 ]; then
|
||||
if ! docker info > /dev/null 2>&1; then
|
||||
if [ "$SPC_USE_SUDO" != "yes" ] && [ "$SPC_DOCKER_DEBUG" != "yes" ]; then
|
||||
echo "Docker command requires sudo"
|
||||
# shellcheck disable=SC2039
|
||||
echo -n 'To use sudo to run docker, run "export SPC_USE_SUDO=yes" and run command again'
|
||||
exit 1
|
||||
fi
|
||||
DOCKER_EXECUTABLE="sudo docker"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Convert uname to gnu arch
|
||||
CURRENT_ARCH=$(uname -m)
|
||||
if [ "$CURRENT_ARCH" = "arm64" ]; then
|
||||
CURRENT_ARCH=aarch64
|
||||
fi
|
||||
if [ -z "$SPC_USE_ARCH" ]; then
|
||||
SPC_USE_ARCH=$CURRENT_ARCH
|
||||
fi
|
||||
# parse SPC_USE_ARCH
|
||||
case $SPC_USE_ARCH in
|
||||
x86_64|amd64)
|
||||
SPC_USE_ARCH=x86_64
|
||||
SPC_USE_ARCH_DOCKER=amd64
|
||||
if [ "$CURRENT_ARCH" != "x86_64" ]; then
|
||||
PLATFORM_ARG="--platform linux/amd64"
|
||||
fi
|
||||
;;
|
||||
aarch64|arm64)
|
||||
SPC_USE_ARCH=aarch64
|
||||
SPC_USE_ARCH_DOCKER=arm64
|
||||
if [ "$CURRENT_ARCH" != "aarch64" ]; then
|
||||
PLATFORM_ARG="--platform linux/arm64"
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Current arch is not supported to run in docker: $SPC_USE_ARCH"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
# detect if we need to use qemu-static
|
||||
if [ "$SPC_USE_ARCH" != "$CURRENT_ARCH" ]; then
|
||||
if [ "$(uname -s)" = "Linux" ]; then
|
||||
echo "* Using different arch needs to setup qemu-static for docker !"
|
||||
$DOCKER_EXECUTABLE run --rm --privileged multiarch/qemu-user-static --reset -p yes > /dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
# Detect docker env is setup
|
||||
if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-gnu-$SPC_USE_ARCH-$SPC_DOCKER_VERSION; then
|
||||
echo "Docker container does not exist. Building docker image ..."
|
||||
$DOCKER_EXECUTABLE buildx build $PLATFORM_ARG -t cwcc-spc-gnu-$SPC_USE_ARCH-$SPC_DOCKER_VERSION -f- . <<EOF
|
||||
FROM centos:7
|
||||
RUN sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo && \
|
||||
sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \
|
||||
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo
|
||||
RUN yum clean all && \
|
||||
yum makecache && \
|
||||
yum update -y && \
|
||||
localedef -c -i en_US -f UTF-8 en_US.UTF-8
|
||||
|
||||
RUN yum install -y centos-release-scl
|
||||
|
||||
RUN if [ "$SPC_USE_ARCH" = "aarch64" ]; then \
|
||||
sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo ; \
|
||||
sed -i 's|mirror.centos.org/centos|vault.centos.org/altarch|g' /etc/yum.repos.d/CentOS-SCLo-scl.repo ; \
|
||||
else \
|
||||
sed -i 's/mirror.centos.org/vault.centos.org/g' /etc/yum.repos.d/*.repo ; \
|
||||
fi
|
||||
RUN sed -i 's/^#.*baseurl=http/baseurl=http/g' /etc/yum.repos.d/*.repo && \
|
||||
sed -i 's/^mirrorlist=http/#mirrorlist=http/g' /etc/yum.repos.d/*.repo && \
|
||||
sed -i 's|http://|https://|g' /etc/yum.repos.d/*.repo
|
||||
|
||||
RUN yum update -y && \
|
||||
yum install -y devtoolset-10-gcc-* devtoolset-10-libatomic-devel
|
||||
RUN echo "source scl_source enable devtoolset-10" >> /etc/bashrc
|
||||
RUN source /etc/bashrc
|
||||
RUN yum install -y which
|
||||
|
||||
RUN curl -o cmake.tgz -#fSL https://github.com/Kitware/CMake/releases/download/v3.31.4/cmake-3.31.4-linux-$SPC_USE_ARCH.tar.gz && \
|
||||
mkdir /cmake && \
|
||||
tar -xzf cmake.tgz -C /cmake --strip-components 1
|
||||
|
||||
WORKDIR /app
|
||||
COPY ./composer.* /app/
|
||||
ADD ./bin/setup-runtime /app/bin/setup-runtime
|
||||
ADD ./bin/spc /app/bin/spc
|
||||
RUN /app/bin/setup-runtime
|
||||
ADD ./src /app/src
|
||||
RUN /app/bin/php /app/bin/composer install --no-dev
|
||||
ENV SPC_LIBC=glibc
|
||||
ENV PATH="/app/bin:/cmake/bin:/opt/rh/devtoolset-10/root/usr/bin:\$PATH"
|
||||
|
||||
ADD ./config /app/config
|
||||
RUN CC=gcc bin/spc doctor --auto-fix --debug
|
||||
RUN bin/spc install-pkg upx
|
||||
RUN if [ -f /app/buildroot/bin/re2c ]; then \
|
||||
cp /app/buildroot/bin/re2c /usr/local/bin/re2c ;\
|
||||
fi
|
||||
|
||||
RUN curl -o make.tgz -fsSL https://ftp.gnu.org/gnu/make/make-4.4.tar.gz && \
|
||||
tar -zxvf make.tgz && \
|
||||
cd make-4.4 && \
|
||||
./configure && \
|
||||
make && \
|
||||
make install && \
|
||||
ln -sf /usr/local/bin/make /usr/bin/make
|
||||
|
||||
RUN curl -o automake.tgz -fsSL https://ftp.gnu.org/gnu/automake/automake-1.17.tar.xz && \
|
||||
tar -xvf automake.tgz && \
|
||||
cd automake-1.17 && \
|
||||
./configure && \
|
||||
make && \
|
||||
make install && \
|
||||
ln -sf /usr/local/bin/automake /usr/bin/automake
|
||||
|
||||
RUN mv /app/pkgroot/\$(uname -m)-linux /app/pkgroot-private
|
||||
ADD bin/docker-entrypoint.sh /bin/docker-entrypoint.sh
|
||||
RUN chmod +x /bin/docker-entrypoint.sh
|
||||
ENTRYPOINT ["/bin/docker-entrypoint.sh"]
|
||||
EOF
|
||||
fi
|
||||
|
||||
# Check if in ci (local terminal can execute with -it)
|
||||
if [ -t 0 ]; then
|
||||
INTERACT=-it
|
||||
else
|
||||
INTERACT=''
|
||||
fi
|
||||
|
||||
# Mounting volumes
|
||||
MOUNT_LIST=""
|
||||
# shellcheck disable=SC2089
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/config:/app/config"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/src:/app/src"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/buildroot:/app/buildroot"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/source:/app/source"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/dist:/app/dist"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/downloads:/app/downloads"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/log:/app/log"
|
||||
if [ -f "$(pwd)/craft.yml" ]; then
|
||||
MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/craft.yml:/app/craft.yml"
|
||||
fi
|
||||
|
||||
# Apply env in temp env file
|
||||
echo 'SPC_DEFAULT_C_FLAGS=-fPIC' > /tmp/spc-gnu-docker.env
|
||||
echo 'SPC_LIBC=glibc' >> /tmp/spc-gnu-docker.env
|
||||
|
||||
# Environment variable passthrough
|
||||
ENV_LIST=""
|
||||
ENV_LIST="$ENV_LIST -e SPC_FIX_DEPLOY_ROOT="$(pwd)""
|
||||
if [ ! -z "$GITHUB_TOKEN" ]; then
|
||||
ENV_LIST="$ENV_LIST -e GITHUB_TOKEN=$GITHUB_TOKEN"
|
||||
fi
|
||||
|
||||
# Intercept and rewrite --with-frankenphp-app option, and mount host path to /app/app
|
||||
FRANKENPHP_APP_PATH=""
|
||||
NEW_ARGS=()
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--with-frankenphp-app=*)
|
||||
FRANKENPHP_APP_PATH="${1#*=}"
|
||||
NEW_ARGS+=("--with-frankenphp-app=/app/app")
|
||||
shift
|
||||
;;
|
||||
--with-frankenphp-app)
|
||||
if [ -n "${2:-}" ]; then
|
||||
FRANKENPHP_APP_PATH="$2"
|
||||
NEW_ARGS+=("--with-frankenphp-app=/app/app")
|
||||
shift 2
|
||||
else
|
||||
NEW_ARGS+=("$1")
|
||||
shift
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
NEW_ARGS+=("$1")
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# Normalize the path and add mount if provided
|
||||
if [ -n "$FRANKENPHP_APP_PATH" ]; then
|
||||
# expand ~ to $HOME
|
||||
if [ "${FRANKENPHP_APP_PATH#~}" != "$FRANKENPHP_APP_PATH" ]; then
|
||||
FRANKENPHP_APP_PATH="$HOME${FRANKENPHP_APP_PATH#~}"
|
||||
fi
|
||||
# make absolute if relative
|
||||
case "$FRANKENPHP_APP_PATH" in
|
||||
/*) ABS_APP_PATH="$FRANKENPHP_APP_PATH" ;;
|
||||
*) ABS_APP_PATH="$(pwd)/$FRANKENPHP_APP_PATH" ;;
|
||||
esac
|
||||
MOUNT_LIST="$MOUNT_LIST -v $ABS_APP_PATH:/app/app"
|
||||
fi
|
||||
|
||||
# Run docker
|
||||
# shellcheck disable=SC2068
|
||||
# shellcheck disable=SC2086
|
||||
# shellcheck disable=SC2090
|
||||
|
||||
if [ "$SPC_DOCKER_DEBUG" = "yes" ]; then
|
||||
echo "* Debug mode enabled, run docker in interactive mode."
|
||||
echo "* You can use 'exit' to exit the docker container."
|
||||
echo "* You can use 'bin/spc' like normal builds."
|
||||
echo "*"
|
||||
echo "* Mounted directories:"
|
||||
echo "* ./config: $(pwd)/config"
|
||||
echo "* ./src: $(pwd)/src"
|
||||
echo "* ./buildroot: $(pwd)/buildroot"
|
||||
echo "* ./source: $(pwd)/source"
|
||||
echo "* ./dist: $(pwd)/dist"
|
||||
echo "* ./downloads: $(pwd)/downloads"
|
||||
echo "* ./pkgroot: $(pwd)/pkgroot"
|
||||
echo "*"
|
||||
set -ex
|
||||
$DOCKER_EXECUTABLE run $PLATFORM_ARG --privileged --rm -it $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH-$SPC_DOCKER_VERSION /bin/bash
|
||||
else
|
||||
$DOCKER_EXECUTABLE run $PLATFORM_ARG --rm $INTERACT $ENV_LIST --env-file /tmp/spc-gnu-docker.env $MOUNT_LIST cwcc-spc-gnu-$SPC_USE_ARCH-$SPC_DOCKER_VERSION bin/spc "${NEW_ARGS[@]}"
|
||||
fi
|
||||
12
bin/spc.ps1
12
bin/spc.ps1
@@ -1,12 +0,0 @@
|
||||
$PHP_Exec = ".\runtime\php.exe"
|
||||
|
||||
if (-not(Test-Path $PHP_Exec)) {
|
||||
$PHP_Exec = Get-Command php.exe -ErrorAction SilentlyContinue | Select-Object -ExpandProperty Definition
|
||||
if (-not $PHP_Exec) {
|
||||
Write-Host "Error: PHP not found, you need to install PHP on your system or use 'bin/setup-runtime'." -ForegroundColor Red
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
& "$PHP_Exec" ("bin/spc") @args
|
||||
exit $LASTEXITCODE
|
||||
19
box.json
19
box.json
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"alias": "spc-php.phar",
|
||||
"banner": false,
|
||||
"blacklist": [
|
||||
".github"
|
||||
],
|
||||
"compression": "GZ",
|
||||
"directories": [
|
||||
"config",
|
||||
"src",
|
||||
"vendor/psr",
|
||||
"vendor/laravel/prompts",
|
||||
"vendor/illuminate",
|
||||
"vendor/symfony",
|
||||
"vendor/zhamao"
|
||||
],
|
||||
"git-commit-short": "git_commit_short",
|
||||
"output": "spc.phar"
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
{
|
||||
"pre-push": {
|
||||
"enabled": true,
|
||||
"actions": [
|
||||
{
|
||||
"action": "composer analyse"
|
||||
}
|
||||
]
|
||||
},
|
||||
"pre-commit": {
|
||||
"enabled": true,
|
||||
"actions": [
|
||||
{
|
||||
"action": "composer cs-fix -- --config=.php-cs-fixer.php --dry-run --diff {$STAGED_FILES|of-type:php}",
|
||||
"conditions": [
|
||||
{
|
||||
"exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType",
|
||||
"args": ["php"]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"post-change": {
|
||||
"enabled": true,
|
||||
"actions": [
|
||||
{
|
||||
"action": "composer install",
|
||||
"options": [],
|
||||
"conditions": [
|
||||
{
|
||||
"exec": "\\CaptainHook\\App\\Hook\\Condition\\FileChanged\\Any",
|
||||
"args": [
|
||||
[
|
||||
"composer.json",
|
||||
"composer.lock"
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
{
|
||||
"name": "crazywhalecc/static-php-cli",
|
||||
"description": "Build single static PHP binary, with PHP project together, with popular extensions included.",
|
||||
"license": "MIT",
|
||||
"authors": [
|
||||
{
|
||||
"name": "jerry",
|
||||
"email": "admin@zhamao.me"
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">= 8.3",
|
||||
"ext-mbstring": "*",
|
||||
"ext-zlib": "*",
|
||||
"laravel/prompts": "^0.1.12",
|
||||
"symfony/console": "^5.4 || ^6 || ^7",
|
||||
"symfony/process": "^7.2",
|
||||
"symfony/yaml": "^7.2",
|
||||
"zhamao/logger": "^1.1.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"captainhook/captainhook-phar": "^5.23",
|
||||
"captainhook/hook-installer": "^1.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.60",
|
||||
"humbug/box": "^4.5.0 || ^4.6.0",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
"phpunit/phpunit": "^10.3 || ^9.5"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"SPC\\": "src/SPC"
|
||||
},
|
||||
"files": [
|
||||
"src/globals/defines.php",
|
||||
"src/globals/functions.php"
|
||||
]
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"SPC\\Tests\\": "tests/SPC"
|
||||
}
|
||||
},
|
||||
"bin": [
|
||||
"bin/spc"
|
||||
],
|
||||
"scripts": {
|
||||
"analyse": "phpstan analyse --memory-limit 300M",
|
||||
"cs-fix": "php-cs-fixer fix",
|
||||
"test": "vendor/bin/phpunit tests/ --no-coverage",
|
||||
"build:phar": "vendor/bin/box compile"
|
||||
},
|
||||
"config": {
|
||||
"allow-plugins": {
|
||||
"phpstan/extension-installer": true,
|
||||
"captainhook/hook-installer": true,
|
||||
"captainhook/plugin-composer": true,
|
||||
"captainhook/captainhook-phar": true
|
||||
},
|
||||
"optimize-autoloader": true,
|
||||
"sort-packages": true
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"type": "other",
|
||||
"url": "https://github.com/crazywhalecc/crazywhalecc/blob/master/FUNDING.md"
|
||||
}
|
||||
]
|
||||
}
|
||||
7577
composer.lock
generated
7577
composer.lock
generated
File diff suppressed because it is too large
Load Diff
159
config/env.ini
159
config/env.ini
@@ -1,159 +0,0 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; static-php-cli (spc) env configuration
|
||||
;
|
||||
; This file is used to set default env vars for static-php-cli build.
|
||||
; As dynamic build process, some of these vars can be overwritten by CLI options.
|
||||
; And you can also overwrite these vars by setting them in your shell environment.
|
||||
; The value should be changed only if you know what you are doing. Otherwise, please leave them as default.
|
||||
;
|
||||
; We need to use some pre-defined internal env vars, like `BUILD_ROOT_PATH`, `DOWNLOAD_PATH`, etc.
|
||||
; Please note that these vars cannot be defined in this file, they should only be defined before static-php-cli running.
|
||||
;
|
||||
; Here's a list of env vars, these variables will be defined if not defined:
|
||||
;
|
||||
; BUILD_ROOT_PATH: the root path of the build process. (default: `$(pwd)/buildroot`)
|
||||
; BUILD_INCLUDE_PATH: the path of the include files. (default: `$BUILD_ROOT_PATH/include`)
|
||||
; BUILD_LIB_PATH: the path of the lib files. (default: `$BUILD_ROOT_PATH/lib`)
|
||||
; BUILD_BIN_PATH: the path of the bin files. (default: `$BUILD_ROOT_PATH/bin`)
|
||||
; BUILD_MODULES_PATH: the path of the php modules (shared extensions) files. (default: `$BUILD_ROOT_PATH/modules`)
|
||||
; PKG_ROOT_PATH: the root path of the package files. (default: `$(pwd)/pkgroot/$GNU_ARCH-{darwin|linux|windows}`)
|
||||
; SOURCE_PATH: the path of the source files. (default: `$(pwd)/source`)
|
||||
; DOWNLOAD_PATH: the path of the download files. (default: `$(pwd)/downloads`)
|
||||
; PATH: (*nix only) static-php-cli will add `$BUILD_BIN_PATH` to PATH.
|
||||
; PKG_CONFIG_PATH: (*nix only) static-php-cli will set `$BUILD_LIB_PATH/pkgconfig` to PKG_CONFIG_PATH.
|
||||
;
|
||||
; Here's a list of env vars, these variables is defined in SPC and cannot be changed anywhere:
|
||||
;
|
||||
; SPC_VERSION: the version of static-php-cli.
|
||||
; WORKING_DIR: the working directory of the build process. (default: `$(pwd)`)
|
||||
; ROOT_DIR: the root directory of static-php-cli. (default: `/path/to/static-php-cli`, when running in phar or micro mode: `phar://path/to/spc.phar`)
|
||||
; CPU_COUNT: the count of the CPU cores. (default: `$(nproc)`)
|
||||
; SPC_ARCH: the arch of the current system, for some libraries needed `--host=XXX` args. (default: `$(uname -m)`, e.g. `x86_64`, `aarch64`, `arm64`)
|
||||
; GNU_ARCH: the GNU arch of the current system. (default: `$(uname -m)`, e.g. `x86_64`, `aarch64`)
|
||||
; MAC_ARCH: the MAC arch of the current system. (default: `$(uname -m)`, e.g. `x86_64`, `arm64`)
|
||||
; PKG_CONFIG: (*nix only) static-php-cli will set `$BUILD_BIN_PATH/pkg-config` to PKG_CONFIG.
|
||||
; SPC_LINUX_DEFAULT_CC: (linux only) the default compiler for linux. (For alpine linux: `gcc`, default: `$GNU_ARCH-linux-musl-gcc`)
|
||||
; SPC_LINUX_DEFAULT_CXX: (linux only) the default c++ compiler for linux. (For alpine linux: `g++`, default: `$GNU_ARCH-linux-musl-g++`)
|
||||
; SPC_LINUX_DEFAULT_AR: (linux only) the default archiver for linux. (For alpine linux: `ar`, default: `$GNU_ARCH-linux-musl-ar`)
|
||||
; SPC_EXTRA_PHP_VARS: (linux only) the extra vars for building php, used in `configure` and `make` command.
|
||||
|
||||
[global]
|
||||
; Build concurrency for make -jN, default is CPU_COUNT, this value are used in every libs.
|
||||
SPC_CONCURRENCY=${CPU_COUNT}
|
||||
; Ignore PHP version check before building some extensions
|
||||
SPC_SKIP_PHP_VERSION_CHECK="no"
|
||||
; Ignore some check item for bin/spc doctor command, comma separated (e.g. SPC_SKIP_DOCTOR_CHECK_ITEMS="if homebrew has installed")
|
||||
SPC_SKIP_DOCTOR_CHECK_ITEMS=""
|
||||
; extra modules that xcaddy will include in the FrankenPHP build
|
||||
SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES="--with github.com/dunglas/mercure/caddy --with github.com/dunglas/vulcain/caddy --with github.com/dunglas/caddy-cbrotli"
|
||||
; The display message for php version output (PHP >= 8.4 available)
|
||||
PHP_BUILD_PROVIDER="static-php-cli ${SPC_VERSION}"
|
||||
|
||||
; EXTENSION_DIR where the built php will look for extension when a .ini instructs to load them
|
||||
; only useful for builds targeting not pure-static linking
|
||||
; default paths
|
||||
; Ubuntu/Debian: /usr/lib/php/{PHP_VERSION}/
|
||||
; RHEL: /usr/lib64/php/modules
|
||||
; Alpine: /usr/lib/php{PHP_VERSION}/modules
|
||||
; where {PHP_VERSION} is 84 for php 8.4
|
||||
; EXTENSION_DIR=
|
||||
|
||||
[windows]
|
||||
; build target: win7-static
|
||||
SPC_TARGET=native-windows
|
||||
; php-sdk-binary-tools path
|
||||
PHP_SDK_PATH="${WORKING_DIR}\php-sdk-binary-tools"
|
||||
; upx executable path
|
||||
UPX_EXEC="${PKG_ROOT_PATH}\bin\upx.exe"
|
||||
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
|
||||
SPC_MICRO_PATCHES=static_extensions_win32,cli_checks,disable_huge_page,vcruntime140,win32,zend_stream,cli_static,win32_api
|
||||
|
||||
[linux]
|
||||
; Linux can use different build toolchains.
|
||||
; - musl (default, when SPC_LIBC=musl): used for general linux distros, can build `musl` (statically linked) only.
|
||||
; - zig (will become default): usable on all Linux distros, can build `-musl`, `arch-linux-musl -dynamic` and `arch-linux-gnu` targets. Can specify version such as `x86_64-linux-gnu.2.17`.
|
||||
; - musl-native: used for alpine linux, can build `musl` and `musl -dynamic` target.
|
||||
; - gnu-native: used for general linux distros, can build gnu target for the installed glibc version only.
|
||||
|
||||
; option to specify the target, superceded by SPC_TARGET if set
|
||||
SPC_LIBC=musl
|
||||
; uncomment to link libc dynamically on musl
|
||||
; SPC_MUSL_DYNAMIC=true
|
||||
|
||||
; Recommended: specify your target here. Zig toolchain will be used.
|
||||
; examples:
|
||||
; `native-native-gnu` - links against glibc, current OS version
|
||||
; `native-native-gnu.2.17` - links against glibc, version 2.17
|
||||
; `native-native` - links against system libc dynamically
|
||||
; `native-native-musl` - links against musl libc statically
|
||||
; `native-native-musl -dynamic` - links against musl libc dynamically
|
||||
; SPC_TARGET=
|
||||
|
||||
; compiler environments
|
||||
CC=${SPC_LINUX_DEFAULT_CC}
|
||||
CXX=${SPC_LINUX_DEFAULT_CXX}
|
||||
AR=${SPC_LINUX_DEFAULT_AR}
|
||||
LD=${SPC_LINUX_DEFAULT_LD}
|
||||
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
|
||||
SPC_DEFAULT_C_FLAGS="-fPIC -Os"
|
||||
SPC_DEFAULT_CXX_FLAGS="-fPIC -Os"
|
||||
SPC_DEFAULT_LD_FLAGS=""
|
||||
; upx executable path
|
||||
UPX_EXEC=${PKG_ROOT_PATH}/bin/upx
|
||||
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
|
||||
SPC_MICRO_PATCHES=cli_checks,disable_huge_page
|
||||
|
||||
; *** default build command for building php ***
|
||||
; buildconf command
|
||||
SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
|
||||
; configure command
|
||||
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --disable-shared --enable-static --disable-all --disable-phpdbg --with-pic"
|
||||
|
||||
; *** default build vars for building php ***
|
||||
; embed type for php, static (libphp.a) or shared (libphp.so)
|
||||
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
|
||||
; EXTRA_CFLAGS for `configure` and `make` php
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fno-ident -fPIE ${SPC_DEFAULT_C_FLAGS}"
|
||||
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
|
||||
|
||||
; optional, path to openssl conf. This affects where openssl will look for the default CA.
|
||||
; default on Debian/Alpine: /etc/ssl, default on RHEL: /etc/pki/tls
|
||||
OPENSSLDIR=""
|
||||
|
||||
[macos]
|
||||
; build target: macho or macho (possibly we could support macho-universal in the future)
|
||||
; Currently we do not support universal and cross-compilation for macOS.
|
||||
SPC_TARGET=native-macos
|
||||
; compiler environments
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
AR=ar
|
||||
LD=ld
|
||||
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
|
||||
SPC_DEFAULT_C_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os"
|
||||
SPC_DEFAULT_CXX_FLAGS="--target=${MAC_ARCH}-apple-darwin -Os"
|
||||
SPC_DEFAULT_LD_FLAGS=""
|
||||
; phpmicro patches, for more info, see: https://github.com/easysoft/phpmicro/tree/master/patches
|
||||
SPC_MICRO_PATCHES=cli_checks,macos_iconv
|
||||
|
||||
; *** default build command for building php ***
|
||||
; buildconf command
|
||||
SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
|
||||
; configure command
|
||||
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-phpdbg"
|
||||
|
||||
; *** default build vars for building php ***
|
||||
; embed type for php, static (libphp.a) or shared (libphp.dylib)
|
||||
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
|
||||
; EXTRA_CFLAGS for `configure` and `make` php
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -fstack-protector-strong -fpic -fpie -Werror=unknown-warning-option ${SPC_DEFAULT_C_FLAGS}"
|
||||
; EXTRA_LDFLAGS for `make` php, can use -release to set a soname for libphp.so
|
||||
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS=""
|
||||
; minimum compatible macOS version (LLVM vars, availability not guaranteed)
|
||||
MACOSX_DEPLOYMENT_TARGET=12.0
|
||||
|
||||
[freebsd]
|
||||
; compiler environments
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
1292
config/ext.json
1292
config/ext.json
File diff suppressed because it is too large
Load Diff
1064
config/lib.json
1064
config/lib.json
File diff suppressed because it is too large
Load Diff
105
config/pkg.json
105
config/pkg.json
@@ -1,105 +0,0 @@
|
||||
{
|
||||
"go-xcaddy-aarch64-linux": {
|
||||
"type": "custom"
|
||||
},
|
||||
"go-xcaddy-aarch64-macos": {
|
||||
"type": "custom"
|
||||
},
|
||||
"go-xcaddy-x86_64-linux": {
|
||||
"type": "custom"
|
||||
},
|
||||
"go-xcaddy-x86_64-macos": {
|
||||
"type": "custom"
|
||||
},
|
||||
"musl-toolchain-aarch64-linux": {
|
||||
"type": "url",
|
||||
"url": "https://dl.static-php.dev/static-php-cli/deps/musl-toolchain/aarch64-musl-toolchain.tgz"
|
||||
},
|
||||
"musl-toolchain-x86_64-linux": {
|
||||
"type": "url",
|
||||
"url": "https://dl.static-php.dev/static-php-cli/deps/musl-toolchain/x86_64-musl-toolchain.tgz"
|
||||
},
|
||||
"nasm-x86_64-win": {
|
||||
"type": "url",
|
||||
"url": "https://dl.static-php.dev/static-php-cli/deps/nasm/nasm-2.16.01-win64.zip",
|
||||
"extract-files": {
|
||||
"nasm.exe": "{php_sdk_path}/bin/nasm.exe",
|
||||
"ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
|
||||
}
|
||||
},
|
||||
"pkg-config-aarch64-linux": {
|
||||
"type": "ghrel",
|
||||
"repo": "static-php/static-php-cli-hosted",
|
||||
"match": "pkg-config-aarch64-linux-musl-1.2.5.txz",
|
||||
"extract-files": {
|
||||
"bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
|
||||
}
|
||||
},
|
||||
"pkg-config-aarch64-macos": {
|
||||
"type": "ghrel",
|
||||
"repo": "static-php/static-php-cli-hosted",
|
||||
"match": "pkg-config-aarch64-darwin.txz",
|
||||
"extract-files": {
|
||||
"bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
|
||||
}
|
||||
},
|
||||
"pkg-config-x86_64-linux": {
|
||||
"type": "ghrel",
|
||||
"repo": "static-php/static-php-cli-hosted",
|
||||
"match": "pkg-config-x86_64-linux-musl-1.2.5.txz",
|
||||
"extract-files": {
|
||||
"bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
|
||||
}
|
||||
},
|
||||
"pkg-config-x86_64-macos": {
|
||||
"type": "ghrel",
|
||||
"repo": "static-php/static-php-cli-hosted",
|
||||
"match": "pkg-config-x86_64-darwin.txz",
|
||||
"extract-files": {
|
||||
"bin/pkg-config": "{pkg_root_path}/bin/pkg-config"
|
||||
}
|
||||
},
|
||||
"strawberry-perl-x86_64-win": {
|
||||
"type": "url",
|
||||
"url": "https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/download/SP_5380_5361/strawberry-perl-5.38.0.1-64bit-portable.zip"
|
||||
},
|
||||
"upx-aarch64-linux": {
|
||||
"type": "ghrel",
|
||||
"repo": "upx/upx",
|
||||
"match": "upx.+-arm64_linux\\.tar\\.xz",
|
||||
"extract-files": {
|
||||
"upx": "{pkg_root_path}/bin/upx"
|
||||
}
|
||||
},
|
||||
"upx-x86_64-linux": {
|
||||
"type": "ghrel",
|
||||
"repo": "upx/upx",
|
||||
"match": "upx.+-amd64_linux\\.tar\\.xz",
|
||||
"extract-files": {
|
||||
"upx": "{pkg_root_path}/bin/upx"
|
||||
}
|
||||
},
|
||||
"upx-x86_64-win": {
|
||||
"type": "ghrel",
|
||||
"repo": "upx/upx",
|
||||
"match": "upx.+-win64\\.zip",
|
||||
"extract-files": {
|
||||
"upx.exe": "{pkg_root_path}/bin/upx.exe"
|
||||
}
|
||||
},
|
||||
"zig-aarch64-linux": {
|
||||
"type": "custom"
|
||||
},
|
||||
"zig-aarch64-macos": {
|
||||
"type": "custom"
|
||||
},
|
||||
"zig-x86_64-linux": {
|
||||
"type": "custom"
|
||||
},
|
||||
"zig-x86_64-macos": {
|
||||
"type": "custom"
|
||||
},
|
||||
"zig-x86_64-win": {
|
||||
"type": "custom"
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
{
|
||||
"repo": "static-php/static-php-cli-hosted",
|
||||
"prefer-stable": true,
|
||||
"match-pattern-linux": "{name}-{arch}-{os}-{libc}-{libcver}.txz",
|
||||
"match-pattern-macos": "{name}-{arch}-{os}.txz",
|
||||
"match-pattern-windows": "{name}-{arch}-{os}.tgz"
|
||||
}
|
||||
1295
config/source.json
1295
config/source.json
File diff suppressed because it is too large
Load Diff
89
docker/Dockerfile
Executable file
89
docker/Dockerfile
Executable file
@@ -0,0 +1,89 @@
|
||||
FROM alpine:3.16
|
||||
|
||||
# define script basic information
|
||||
# Version of this Dockerfile
|
||||
ENV SCRIPT_VERSION=1.5.1
|
||||
# Download address uses backup address
|
||||
|
||||
ARG USE_BACKUP_ADDRESS
|
||||
|
||||
# (if downloading slowly, consider set it to yes)
|
||||
ENV USE_BACKUP="${USE_BACKUP_ADDRESS}"
|
||||
|
||||
|
||||
# APK repositories mirror address, if u r not in China, consider set USE_BACKUP=yes to boost
|
||||
ENV LINK_APK_REPO='mirrors.ustc.edu.cn'
|
||||
ENV LINK_APK_REPO_BAK='dl-cdn.alpinelinux.org'
|
||||
|
||||
RUN if [ "${USE_BACKUP}" = "" ]; then \
|
||||
export USE_BACKUP="no" ; \
|
||||
fi
|
||||
|
||||
RUN sed -i.backup 's/dl-cdn.alpinelinux.org/'${LINK_APK_REPO}'/g' /etc/apk/repositories ;
|
||||
|
||||
RUN if [ "${USE_BACKUP}" = "no" ]; then cp -f /etc/apk/repositories.backup /etc/apk/repositories; fi
|
||||
RUN cat /etc/apk/repositories
|
||||
# build requirements
|
||||
RUN apk add bash file wget cmake gcc g++ jq autoconf git libstdc++ linux-headers make m4 libgcc binutils ncurses dialog > /dev/null
|
||||
# php zlib dependencies
|
||||
RUN apk add zlib-dev zlib-static > /dev/null
|
||||
# php mbstring dependencies
|
||||
RUN apk add oniguruma-dev > /dev/null
|
||||
# php openssl dependencies
|
||||
RUN apk add openssl-libs-static openssl-dev openssl > /dev/null
|
||||
# php gd dependencies
|
||||
RUN apk add libpng-dev libpng-static > /dev/null
|
||||
# curl c-ares dependencies
|
||||
RUN apk add c-ares-static c-ares-dev > /dev/null
|
||||
# php event dependencies
|
||||
RUN apk add libevent libevent-dev libevent-static > /dev/null
|
||||
# php sqlite3 dependencies
|
||||
RUN apk add sqlite sqlite-dev sqlite-libs sqlite-static > /dev/null
|
||||
# php libzip dependencies
|
||||
RUN apk add bzip2-dev bzip2-static bzip2 > /dev/null
|
||||
# php micro ffi dependencies
|
||||
RUN apk add libffi libffi-dev > /dev/null
|
||||
# php gd event parent dependencies
|
||||
RUN apk add zstd-static > /dev/null
|
||||
# php readline dependencies
|
||||
RUN apk add readline-static ncurses-static readline-dev > /dev/null
|
||||
RUN apk add aria2
|
||||
|
||||
RUN mkdir /app
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
ADD ./ /app/
|
||||
|
||||
# RUN chmod +x /app/*.sh
|
||||
|
||||
# use proxy
|
||||
# ENV http_proxy=http://192.168.3.26:8015
|
||||
# ENV https_proxy=http://192.168.3.26:8015
|
||||
|
||||
# 提前下载好,就可以跳过两步
|
||||
# (容器外提前执行 下面两个命令)
|
||||
RUN sh ./download-library-batch-aria2.sh
|
||||
RUN sh ./download-extension-batch-aria2.sh
|
||||
|
||||
#ENV http_proxy=''
|
||||
#ENV https_proxy=''
|
||||
RUN ls -lh source/libraries
|
||||
RUN ls -lh source/extensions
|
||||
# quick test complie
|
||||
# RUN bash ./compile-deps.sh
|
||||
|
||||
RUN sh ./download.sh swoole ${USE_BACKUP} && \
|
||||
sh ./download.sh inotify ${USE_BACKUP} && \
|
||||
sh ./download.sh mongodb ${USE_BACKUP} && \
|
||||
sh ./download.sh event ${USE_BACKUP} && \
|
||||
sh ./download.sh redis ${USE_BACKUP} && \
|
||||
sh ./download.sh libxml2 ${USE_BACKUP} && \
|
||||
sh ./download.sh xz ${USE_BACKUP} && \
|
||||
sh ./download.sh curl ${USE_BACKUP} && \
|
||||
sh ./download.sh libzip ${USE_BACKUP} && \
|
||||
sh ./download.sh libiconv ${USE_BACKUP} && \
|
||||
sh ./download-git.sh dixyes/phpmicro phpmicro ${USE_BACKUP}
|
||||
|
||||
RUN bash ./compile-deps.sh
|
||||
RUN echo -e "#!/usr/bin/env bash\n/app/compile-php.sh \$@" > /bin/build-php && chmod +x /bin/build-php
|
||||
3
docker/ac_override_1
Executable file
3
docker/ac_override_1
Executable file
@@ -0,0 +1,3 @@
|
||||
AC_DEFUN([PHP_CHECK_LIBRARY], [
|
||||
$3
|
||||
])
|
||||
18
docker/ac_override_2
Executable file
18
docker/ac_override_2
Executable file
@@ -0,0 +1,18 @@
|
||||
AC_DEFUN([PHP_CHECK_LIBRARY], [
|
||||
save_old_LDFLAGS=$LDFLAGS
|
||||
ac_stuff="$5"
|
||||
|
||||
save_ext_shared=$ext_shared
|
||||
ext_shared=yes
|
||||
PHP_EVAL_LIBLINE([$]ac_stuff, LDFLAGS)
|
||||
AC_CHECK_LIB([$1],[$2],[
|
||||
LDFLAGS=$save_old_LDFLAGS
|
||||
ext_shared=$save_ext_shared
|
||||
$3
|
||||
],[
|
||||
LDFLAGS=$save_old_LDFLAGS
|
||||
ext_shared=$save_ext_shared
|
||||
unset ac_cv_lib_$1[]_$2
|
||||
$4
|
||||
])dnl
|
||||
])
|
||||
200
docker/check-extensions.sh
Executable file
200
docker/check-extensions.sh
Executable file
@@ -0,0 +1,200 @@
|
||||
#!/bin/sh
|
||||
|
||||
# Here are 3 steps in configuration of extensions
|
||||
# before_configure
|
||||
# in_configure
|
||||
# after_configure
|
||||
|
||||
self_dir=$(cd "$(dirname "$0")";pwd)
|
||||
php_dir=$(find $self_dir/source -name "php-*" -type d | tail -n1)
|
||||
test -f "$self_dir/extensions_install.txt" && EXT_LIST_FILE="$self_dir/extensions_install.txt" || EXT_LIST_FILE="$self_dir/extensions.txt"
|
||||
|
||||
|
||||
function do_copy_extension() {
|
||||
ext_dir=$(find $self_dir/source -name "*$1-*" -type d | tail -n1)
|
||||
mv $ext_dir $php_dir/ext/$1
|
||||
if [ $? != 0 ]; then
|
||||
echo "Compile error! ext: $1, ext_dir=$ext_dir"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
function check_before_configure() {
|
||||
list=$(cat "$EXT_LIST_FILE" | grep -v "^#" | grep -v "^$" | grep -v "^\^")
|
||||
xml_sign="no"
|
||||
for loop in $list
|
||||
do
|
||||
case $loop in
|
||||
bcmath) ;;
|
||||
calendar) ;;
|
||||
ctype) ;;
|
||||
exif) ;;
|
||||
filter) ;;
|
||||
fileinfo) ;;
|
||||
gd) ;;
|
||||
hash) ;;
|
||||
iconv) ;;
|
||||
json) ;;
|
||||
mbstring) ;;
|
||||
mysqlnd) ;;
|
||||
openssl) ;;
|
||||
pcntl) ;;
|
||||
pdo) ;;
|
||||
pdo_mysql) ;;
|
||||
pdo_sqlite) ;;
|
||||
phar) ;;
|
||||
posix) ;;
|
||||
protobuf)
|
||||
do_copy_extension protobuf
|
||||
echo '#ifndef PHP_PROTOBUF_H' >> $php_dir/ext/protobuf/php_protobuf.h && \
|
||||
echo '# define PHP_PROTOBUF_H' >> $php_dir/ext/protobuf/php_protobuf.h && \
|
||||
echo '#ifdef HAVE_CONFIG_H' >> $php_dir/ext/protobuf/php_protobuf.h && \
|
||||
echo '# include "config.h"' >> $php_dir/ext/protobuf/php_protobuf.h && \
|
||||
echo '#endif' >> $php_dir/ext/protobuf/php_protobuf.h && \
|
||||
echo 'extern zend_module_entry protobuf_module_entry;' >> $php_dir/ext/protobuf/php_protobuf.h && \
|
||||
echo '# define phpext_protobuf_ptr &protobuf_module_entry' >> $php_dir/ext/protobuf/php_protobuf.h && \
|
||||
echo '#endif' >> $php_dir/ext/protobuf/php_protobuf.h
|
||||
;;
|
||||
readline)
|
||||
if [ ! -d "/nom" ]; then
|
||||
mkdir /nom
|
||||
fi
|
||||
mv /usr/lib/libreadline.so* /nom/ && \
|
||||
mv /usr/lib/libncurses*.so* /nom
|
||||
;;
|
||||
shmop) ;;
|
||||
sockets) ;;
|
||||
sqlite3) ;;
|
||||
tokenizer) ;;
|
||||
zlib) ;;
|
||||
zip) ;;
|
||||
curl) cat "$self_dir/ac_override_1" "$php_dir/ext/curl/config.m4" "$self_dir/ac_override_2" > /tmp/aa && mv /tmp/aa "$php_dir/ext/curl/config.m4" ;;
|
||||
dom|xml|libxml|xmlreader|xmlwriter|simplexml|soap) ;;
|
||||
inotify) do_copy_extension inotify ;;
|
||||
redis) do_copy_extension redis ;;
|
||||
swoole) do_copy_extension swoole ;;
|
||||
mongodb) do_copy_extension mongodb ;;
|
||||
event) do_copy_extension event ;;
|
||||
esac
|
||||
done
|
||||
case $1 in
|
||||
8.*)
|
||||
mv $self_dir/source/phpmicro $php_dir/sapi/micro && \
|
||||
sed -ie 's/#include "php.h"/#include "php.h"\n#define PHP_MICRO_FAKE_CLI 1/g' $php_dir/sapi/micro/php_micro.c
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function check_in_configure() {
|
||||
php_configure=""
|
||||
list=$(cat "$EXT_LIST_FILE" | sed 's/#.*//g' | sed 's/\^.*//g' | sed -e 's/[ ]*$//g' | grep -v "^\s*$")
|
||||
for loop in $list
|
||||
do
|
||||
case $loop in
|
||||
bcmath) php_configure="$php_configure --enable-bcmath" ;;
|
||||
calendar) php_configure="$php_configure --enable-calendar" ;;
|
||||
ctype) php_configure="$php_configure --enable-ctype" ;;
|
||||
curl) php_configure="$php_configure --with-curl" ;;
|
||||
dom) php_configure="$php_configure --enable-dom" ;;
|
||||
exif) php_configure="$php_configure --enable-exif" ;;
|
||||
event) php_configure="$php_configure --with-event-libevent-dir=/usr --with-event-core --with-event-extra --with-event-openssl" ;;
|
||||
filter) php_configure="$php_configure --enable-filter" ;;
|
||||
fileinfo) php_configure="$php_configure --enable-fileinfo" ;;
|
||||
gd)
|
||||
case $1 in
|
||||
7.3.*|7.2.*) php_configure="$php_configure --with-gd" ;;
|
||||
7.4.*|8.*) php_configure="$php_configure --enable-gd" ;;
|
||||
esac
|
||||
;;
|
||||
hash)
|
||||
case $1 in
|
||||
7.3.*|7.2.*) php_configure="$php_configure --enable-hash" ;;
|
||||
esac
|
||||
;;
|
||||
iconv) php_configure="$php_configure --with-iconv=/usr" ;;
|
||||
inotify) php_configure="$php_configure --enable-inotify" ;;
|
||||
json)
|
||||
case $1 in
|
||||
7.*) php_configure="$php_configure --enable-json" ;;
|
||||
esac
|
||||
;;
|
||||
libxml)
|
||||
case $1 in
|
||||
7.3.*|7.2.*) php_configure="$php_configure --enable-libxml" ;;
|
||||
7.4.*|8.*) php_configure="$php_configure --with-libxml" ;;
|
||||
esac
|
||||
;;
|
||||
mbstring) php_configure="$php_configure --enable-mbstring" ;;
|
||||
mongodb) php_configure="$php_configure --enable-mongodb" ;;
|
||||
mysqlnd) php_configure="$php_configure --enable-mysqlnd" ;;
|
||||
openssl) php_configure="$php_configure --with-openssl --with-openssl-dir=/usr" ;;
|
||||
pcntl) php_configure="$php_configure --enable-pcntl" ;;
|
||||
pdo) php_configure="$php_configure --enable-pdo" ;;
|
||||
pdo_mysql) php_configure="$php_configure --with-pdo-mysql=mysqlnd" ;;
|
||||
phar) php_configure="$php_configure --enable-phar" ;;
|
||||
posix) php_configure="$php_configure --enable-posix" ;;
|
||||
protobuf) php_configure="$php_configure --enable-protobuf" ;;
|
||||
readline) php_configure="$php_configure --with-readline" ;;
|
||||
redis) php_configure="$php_configure --enable-redis --disable-redis-session" ;;
|
||||
shmop) php_configure="$php_configure --enable-shmop" ;;
|
||||
simplexml) php_configure="$php_configure --enable-simplexml" ;;
|
||||
sockets) php_configure="$php_configure --enable-sockets" ;;
|
||||
soap) php_configure="$php_configure --enable-soap" ;;
|
||||
sqlite3) php_configure="$php_configure --with-sqlite3" ;;
|
||||
pdo_sqlite) php_configure="$php_configure --with-pdo-sqlite" ;;
|
||||
|
||||
swoole)
|
||||
php_configure="$php_configure --enable-swoole"
|
||||
have_openssl=$(echo $list | grep openssl)
|
||||
if [ "$have_openssl" != "" ]; then
|
||||
php_configure="$php_configure --enable-openssl --with-openssl --with-openssl-dir=/usr"
|
||||
fi
|
||||
have_hash=$(echo $list | grep hash)
|
||||
if [ "$have_hash" = "" ]; then
|
||||
case $1 in
|
||||
7.3.*|7.2.*) php_configure="$php_configure --enable-hash" ;;
|
||||
esac
|
||||
fi
|
||||
;;
|
||||
tokenizer) php_configure="$php_configure --enable-tokenizer" ;;
|
||||
xml) php_configure="$php_configure --enable-xml" ;;
|
||||
xmlreader) php_configure="$php_configure --enable-xmlreader" ;;
|
||||
xmlwriter) php_configure="$php_configure --enable-xmlwriter" ;;
|
||||
zlib) php_configure="$php_configure --with-zlib" ;;
|
||||
zip) php_configure="$php_configure --with-zip" ;;
|
||||
*)
|
||||
echo "Unsupported extension '$loop' !" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
case $1 in
|
||||
8.*) php_configure="$php_configure --with-ffi --enable-micro=all-static" ;;
|
||||
esac
|
||||
echo $php_configure
|
||||
}
|
||||
|
||||
function check_after_configure() {
|
||||
list=$(cat "$EXT_LIST_FILE" | grep -v "^#" | grep -v "^$")
|
||||
for loop in $list
|
||||
do
|
||||
case $loop in
|
||||
swoole)
|
||||
sed -ie 's/swoole_clock_gettime(CLOCK_REALTIME/clock_gettime(CLOCK_REALTIME/g' "$php_dir/ext/swoole/include/swoole.h"
|
||||
sed -ie 's/strcmp("cli", sapi_module.name) == 0/strcmp("cli", sapi_module.name) == 0 || strcmp("micro", sapi_module.name) == 0/g' "$php_dir/ext/swoole/ext-src/php_swoole.cc"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
case $1 in
|
||||
8.*) sed -ie 's/$(EXTRA_LIBS:-lresolv=-Wl,-Bstatic,-lresolv,-Bdynamic)/$(EXTRA_LIBS)/g' "$php_dir/Makefile" ;;
|
||||
esac
|
||||
}
|
||||
|
||||
function finish_compile() {
|
||||
if [ -d "/nom" ]; then
|
||||
mv /nom/* /usr/lib/ || echo "Empty directory"
|
||||
rm -rf /nom/
|
||||
fi
|
||||
}
|
||||
|
||||
$1 $2
|
||||
64
docker/compile-deps.sh
Executable file
64
docker/compile-deps.sh
Executable file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
self_dir=$(cd "$(dirname "$0")";pwd)
|
||||
|
||||
function do_xml_compiler() {
|
||||
cd $self_dir/source/xz-* && \
|
||||
./configure --enable-static=yes && \
|
||||
make -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
|
||||
make install && \
|
||||
echo "xz compiled!" && \
|
||||
cd ../libxml2-* && \
|
||||
./configure --prefix=/usr --with-lzma --without-python && \
|
||||
make -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
|
||||
make install && \
|
||||
echo "libxml2 compiled!"
|
||||
}
|
||||
|
||||
function do_libzip_compiler() {
|
||||
cd $self_dir/source/libzip-* && \
|
||||
mkdir build && \
|
||||
cd build && \
|
||||
cmake -DBUILD_SHARED_LIBS=no .. -Wno-dev -DENABLE_BZIP2=no -DENABLE_LZMA=no && \
|
||||
make LDFLAGS="-llzma -lbz2" -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
|
||||
make install && \
|
||||
echo "libzip compiled!"
|
||||
}
|
||||
|
||||
function do_curl_compiler() {
|
||||
cd $self_dir/source/curl-* && \
|
||||
CC=gcc CXX=g++ CFLAGS=-fPIC CPPFLAGS=-fPIC ./configure \
|
||||
--without-nghttp2 \
|
||||
--with-ssl=/usr \
|
||||
--with-pic=pic \
|
||||
--enable-ipv6 \
|
||||
--enable-shared=no \
|
||||
--without-libidn2 \
|
||||
--disable-ldap \
|
||||
--without-libpsl \
|
||||
--without-lber \
|
||||
--enable-ares && \
|
||||
make -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
|
||||
make install && \
|
||||
echo "curl compiled!"
|
||||
}
|
||||
|
||||
function do_iconv_compiler() {
|
||||
cd $self_dir/source/libiconv-* && \
|
||||
./configure --enable-static=yes --prefix=/usr && \
|
||||
make -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
|
||||
make install && \
|
||||
echo "libiconv compiled!"
|
||||
}
|
||||
|
||||
if [ ! -f "$self_dir/source/.deps-compiled" ]; then
|
||||
source ${self_dir}/deps-modules/libmcrypt.sh
|
||||
source ${self_dir}/deps-modules/gmp.sh
|
||||
do_xml_compiler && \
|
||||
do_curl_compiler && \
|
||||
do_libzip_compiler && \
|
||||
do_iconv_compiler && \
|
||||
touch "$self_dir/source/.deps-compiled"
|
||||
else
|
||||
echo "Skip compilation for dependencies"
|
||||
fi
|
||||
125
docker/compile-php.sh
Executable file
125
docker/compile-php.sh
Executable file
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
self_dir=$(cd "$(dirname "$0")";pwd)
|
||||
|
||||
# 通过 extensions.txt 生成一个 dialog 命令
|
||||
function generate_ext_dialog_cmd() {
|
||||
list=$(cat "$self_dir/extensions.txt" | grep -v "^#" | grep -v "^$")
|
||||
echo -n "dialog --backtitle \"static-php-cli Compile Options\" --checklist \"Please select the extension you don't want to compile.\n\nNOTE: Use <space> to select or deselect items\n\n** Default is compiling all **\" 24 60 20 " > $self_dir/.ask_cmd.sh
|
||||
for loop in $list
|
||||
do
|
||||
case $loop in
|
||||
^*)
|
||||
loop=$(echo ${loop:1} | xargs)
|
||||
echo -n "$loop '$loop Extension' off " >> $self_dir/.ask_cmd.sh
|
||||
;;
|
||||
*) echo -n "$loop '$loop Extension' on " >> $self_dir/.ask_cmd.sh ;;
|
||||
esac
|
||||
done
|
||||
echo "2>$self_dir/extensions_install.txt" >> $self_dir/.ask_cmd.sh
|
||||
}
|
||||
|
||||
# PHP 编译参数生成
|
||||
function php_compile_args() {
|
||||
_php_arg="--prefix=$self_dir/php-dist"
|
||||
_php_arg="$_php_arg --disable-all"
|
||||
_php_arg="$_php_arg --enable-shared=no"
|
||||
_php_arg="$_php_arg --enable-static=yes"
|
||||
_php_arg="$_php_arg --enable-inline-optimization"
|
||||
_php_arg="$_php_arg --with-layout=GNU"
|
||||
_php_arg="$_php_arg --with-pear=no"
|
||||
_php_arg="$_php_arg --disable-cgi"
|
||||
_php_arg="$_php_arg --disable-phpdbg"
|
||||
_php_arg="$_php_arg --with-config-file-path=/etc"
|
||||
_php_arg="$_php_arg $($self_dir/check-extensions.sh check_in_configure $1)"
|
||||
echo $_php_arg
|
||||
}
|
||||
|
||||
# 第一个参数用于使用镜像地址还是原地址(mirror为镜像地址,original为原地址)
|
||||
if [ "$1" = "" ]; then
|
||||
dialog --backtitle "static-php-cli Compile Options" --yesno "<Yes>: Use mirror download address, mainland China users recommended.\n\n<No>: Use original address, global users recommended." 10 50
|
||||
test $? == 0 && USE_BACKUP="no" || USE_BACKUP="yes"
|
||||
else
|
||||
test "$1" != "mirror" && USE_BACKUP="yes" || USE_BACKUP="no"
|
||||
fi
|
||||
|
||||
# 第二个参数用于规定编译的 PHP 版本
|
||||
if [ "$2" = "" ]; then
|
||||
dialog --backtitle "static-php-cli Compile Options" --inputbox "Please input your PHP version to compile" 10 50 "8.1.7" 2>$self_dir/.phpver
|
||||
if [ $? != 0 ]; then
|
||||
clear
|
||||
echo "canceled Compiling PHP." && rm -f $self_dir/.phpver
|
||||
exit 1
|
||||
else
|
||||
VER_PHP=$(cat $self_dir/.phpver)
|
||||
rm -f $self_dir/.phpver
|
||||
fi
|
||||
else
|
||||
VER_PHP=$2
|
||||
fi
|
||||
|
||||
# 第三个参数用于是否直接安装,如果留空则询问编译的扩展,如果填入 all,则直接编译所有的扩展
|
||||
if [ "$3" != "all" ]; then
|
||||
generate_ext_dialog_cmd && cat $self_dir/.ask_cmd.sh && chmod +x $self_dir/.ask_cmd.sh && $self_dir/.ask_cmd.sh
|
||||
if [ $? != 0 ]; then
|
||||
clear
|
||||
echo "canceled Compiling PHP while selecting extensions." && rm -rf $self_dir/.ask_cmd.sh
|
||||
exit 1
|
||||
fi
|
||||
rm -f $self_dir/.ask_cmd.sh
|
||||
else
|
||||
cp $self_dir/extensions.txt $self_dir/extensions_install.txt
|
||||
fi
|
||||
|
||||
# 第四个参数用于输出 PHP 和 micro 二进制文件的位置
|
||||
if [ "$4" = "" ]; then
|
||||
dialog --backtitle "static-php-cli Compile Options" --inputbox "Please input compiled output directory" 10 50 "/dist/" 2>$self_dir/.outdir
|
||||
if [ $? != 0 ]; then
|
||||
clear
|
||||
echo "canceled setting output dir, compiling PHP stopped." && rm -f $self_dir/.outdir
|
||||
exit 1
|
||||
else
|
||||
OUT_DIR=$(cat $self_dir/.outdir)
|
||||
rm -f $self_dir/.outdir
|
||||
fi
|
||||
else
|
||||
OUT_DIR=$4
|
||||
fi
|
||||
|
||||
if [ ! -d "$OUT_DIR" ]; then
|
||||
mkdir -p "$OUT_DIR"
|
||||
fi
|
||||
|
||||
# 下载 PHP
|
||||
|
||||
|
||||
echo "All done. Downloading PHP ..."
|
||||
if [ -d "$self_dir/source/php-$VER_PHP" ]; then
|
||||
rm -rf "$self_dir/source/php-$VER_PHP"
|
||||
fi
|
||||
$self_dir/download.sh php ${USE_BACKUP} ${VER_PHP} || { echo "Download PHP failed!" && exit 1 ; }
|
||||
# 选择性编译依赖的库、移动需要安装的扩展到 PHP 目录
|
||||
$self_dir/check-extensions.sh check_before_configure ${VER_PHP} || { echo "Install required library failed!" && exit 1 ; }
|
||||
# 编译 PHP
|
||||
echo "Compiling PHP ..."
|
||||
php_dir=$(find $self_dir/source -name "php-$VER_PHP" -type d | tail -n1)
|
||||
cd $php_dir && \
|
||||
./buildconf --force && \
|
||||
./configure LDFLAGS=-static $(php_compile_args $VER_PHP) && \
|
||||
$self_dir/check-extensions.sh check_after_configure ${VER_PHP} && \
|
||||
sed -ie 's/-export-dynamic//g' "Makefile" && \
|
||||
sed -ie 's/-o $(SAPI_CLI_PATH)/-all-static -o $(SAPI_CLI_PATH)/g' "Makefile" && \
|
||||
#sed -ie 's/$(PHP_GLOBAL_OBJS) $(PHP_BINARY_OBJS) $(PHP_MICRO_OBJS)/$(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_BINARY_OBJS:.lo=.o) $(PHP_MICRO_OBJS:.lo=.o)/g' "Makefile" && \
|
||||
make LDFLAGS="-ldl" -j$(cat /proc/cpuinfo | grep processor | wc -l) && \
|
||||
make install-cli && \
|
||||
$self_dir/check-extensions.sh finish_compile && \
|
||||
strip $self_dir/php-dist/bin/php
|
||||
if [ $? != 0 ]; then
|
||||
exit 1
|
||||
fi
|
||||
# 将 PHP 和 micro 输出到指定目录
|
||||
echo "Copying php binary to $OUT_DIR ..." && \
|
||||
cp $self_dir/php-dist/bin/php $OUT_DIR/ && \
|
||||
test -f $php_dir/sapi/micro/micro.sfx && \
|
||||
echo "Copying micro.sfx binary to $OUT_DIR ..." && \
|
||||
cp $php_dir/sapi/micro/micro.sfx $OUT_DIR/ || { exit 0 ; }
|
||||
61
docker/config.json
Executable file
61
docker/config.json
Executable file
@@ -0,0 +1,61 @@
|
||||
{
|
||||
"php": {
|
||||
"link": "http://mirrors.zhamao.xin/php/php-{version}.tar.gz",
|
||||
"link_2": "https://www.php.net/distributions/php-{version}.tar.gz"
|
||||
},
|
||||
"protobuf": {
|
||||
"version": "3.21.2",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/protobuf-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/protobuf-{version}.tgz"
|
||||
},
|
||||
"swoole": {
|
||||
"version": "4.8.10",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/swoole-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/swoole-{version}.tgz"
|
||||
},
|
||||
"mongodb": {
|
||||
"version": "1.13.0",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/mongodb-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/mongodb-{version}.tgz"
|
||||
},
|
||||
"inotify": {
|
||||
"version": "3.0.0",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/inotify-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/inotify-{version}.tgz"
|
||||
},
|
||||
"event": {
|
||||
"version": "3.0.8",
|
||||
"link": "https://mirrors.zhamao.xin/library/php-event/event-{version}.tar.gz",
|
||||
"link_2": "https://bitbucket.org/osmanov/pecl-event/get/{version}.tar.gz"
|
||||
},
|
||||
"redis": {
|
||||
"version": "5.3.7",
|
||||
"link": "http://mirrors.zhamao.xin/pecl/redis-{version}.tgz",
|
||||
"link_2": "https://pecl.php.net/get/redis-{version}.tgz"
|
||||
},
|
||||
"libxml2": {
|
||||
"version": "2.9.12",
|
||||
"link": "http://mirrors.zhamao.xin/library/libxml2/libxml2-{version}.tar.gz",
|
||||
"link_2": "http://xmlsoft.org/sources/libxml2-{version}.tar.gz"
|
||||
},
|
||||
"curl": {
|
||||
"version": "7.83.1",
|
||||
"link": "https://mirrors.zhamao.xin/library/curl/curl-{version}.tar.gz",
|
||||
"link_2": "https://curl.haxx.se/download/curl-{version}.tar.gz"
|
||||
},
|
||||
"xz": {
|
||||
"version": "5.2.5",
|
||||
"link": "https://mirrors.zhamao.xin/library/xz/xz-{version}.tar.gz",
|
||||
"link_2": "https://tukaani.org/xz/xz-{version}.tar.gz"
|
||||
},
|
||||
"libzip": {
|
||||
"version": "1.9.2",
|
||||
"link": "https://mirrors.zhamao.xin/library/libzip/libzip-{version}.tar.gz",
|
||||
"link_2": "https://libzip.org/download/libzip-{version}.tar.gz"
|
||||
},
|
||||
"libiconv": {
|
||||
"version": "1.17",
|
||||
"link": "https://mirrors.zhamao.xin/library/libiconv/libiconv-{version}.tar.gz",
|
||||
"link_2": "https://ftp.gnu.org/gnu/libiconv/libiconv-{version}.tar.gz"
|
||||
}
|
||||
}
|
||||
32
docker/deps-modules/gmp.sh
Normal file
32
docker/deps-modules/gmp.sh
Normal file
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
if [ -n "$__MODULE_SH__" ]; then
|
||||
return
|
||||
fi
|
||||
__MODULE_SH__='gmp.sh'
|
||||
|
||||
set -exu
|
||||
__DIR__=$(
|
||||
cd "$(dirname "$0")"
|
||||
pwd
|
||||
)
|
||||
cd ${__DIR__}
|
||||
|
||||
# cpu 核数 ,前面为linux 后面为macos
|
||||
cpu_nums=`nproc 2> /dev/null || sysctl -n hw.ncpu`
|
||||
# cpu_nums=`grep "processor" /proc/cpuinfo | sort -u | wc -l`
|
||||
|
||||
function do_gmp_compiler() {
|
||||
pwd
|
||||
mkdir -p /app/source/builder_dir/gmp
|
||||
tar --strip-components=1 -C ${__DIR__}/source/builder_dir/gmp -xf ${__DIR__}/source/libraries/gmp-6.2.1.tar.lz
|
||||
cd ${__DIR__}/source/builder_dir/gmp
|
||||
|
||||
./configure --prefix=/usr/gmp --enable-static --disable-shared
|
||||
make -j $cpu_nums
|
||||
echo "gmp compiled!" && \
|
||||
make install && \
|
||||
echo "gmp compiled!"
|
||||
return $?
|
||||
}
|
||||
|
||||
do_gmp_compiler
|
||||
35
docker/deps-modules/libmcrypt.sh
Normal file
35
docker/deps-modules/libmcrypt.sh
Normal file
@@ -0,0 +1,35 @@
|
||||
#!/bin/bash
|
||||
if [ -n "$__MODULE_SH__" ]; then
|
||||
return
|
||||
fi
|
||||
__MODULE_SH__='libmcrypt.sh'
|
||||
|
||||
set -exu
|
||||
__DIR__=$(
|
||||
cd "$(dirname "$0")"
|
||||
pwd
|
||||
)
|
||||
cd ${__DIR__}
|
||||
|
||||
# cpu 核数 ,前面为linux 后面为macos
|
||||
cpu_nums=`nproc 2> /dev/null || sysctl -n hw.ncpu`
|
||||
# cpu_nums=`grep "processor" /proc/cpuinfo | sort -u | wc -l`
|
||||
|
||||
|
||||
function do_libmcrypt_compiler() {
|
||||
pwd
|
||||
mkdir -p /app/source/builder_dir/libmcrypt
|
||||
tar --strip-components=1 -C ${__DIR__}/source/builder_dir/libmcrypt -xf ${__DIR__}/source/libraries/libmcrypt-2.5.8-3.4.tar.gz
|
||||
cd ${__DIR__}/source/builder_dir/libmcrypt
|
||||
|
||||
chmod a+x ./install-sh
|
||||
sh ./configure --prefix=/usr/libmcrypt \
|
||||
--enable-static=yes \
|
||||
--enable-shared=no
|
||||
make -j $cpu_nums
|
||||
echo "libmcrypt compiled!" && \
|
||||
make install && \
|
||||
echo "libmcrypt compiled!"
|
||||
return $?
|
||||
}
|
||||
do_libmcrypt_compiler
|
||||
34
docker/download-extension-batch-aria2.sh
Executable file
34
docker/download-extension-batch-aria2.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -exu
|
||||
__DIR__=$(
|
||||
cd "$(dirname "$0")"
|
||||
pwd
|
||||
)
|
||||
|
||||
cd ${__DIR__}
|
||||
|
||||
# https://aria2.github.io/manual/en/html/aria2c.html#http-ftp-segmented-downloads
|
||||
# https://aria2.github.io/manual/en/html/aria2c.html
|
||||
# -with-config-file-path=/usr/local/php/etc
|
||||
# -U, --user-agent
|
||||
# aria2c -h
|
||||
# aria2c --conf-path=/etc/aria2/aria2.conf
|
||||
|
||||
:<<EOF
|
||||
-c, --continue [true|false]
|
||||
-s, --split=<N>
|
||||
-x, --max-connection-per-server=<NUM>
|
||||
-k, --min-split-size=<SIZE>
|
||||
-j, --max-concurrent-downloads=<N>
|
||||
-i, --input-file=<FILE>
|
||||
EOF
|
||||
|
||||
user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
|
||||
|
||||
|
||||
test -f download_extension_urls.txt && aria2c -c -j 10 -s 10 -x 8 -k 10M --allow-overwrite=true --max-tries=30 --retry-wait=15 --user-agent=$user_agent \
|
||||
-d extensions --input-file=download_extension_urls.txt
|
||||
|
||||
mkdir -p source/extensions
|
||||
awk 'BEGIN { cmd="cp -ri extensions/* source/extensions/" ; print "n" |cmd; }'
|
||||
20
docker/download-git.sh
Executable file
20
docker/download-git.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
self_dir=$(cd "$(dirname "$0")";pwd)
|
||||
|
||||
test -d "$self_dir/source/cache/" || mkdir -p "$self_dir/source/cache"
|
||||
|
||||
test "$3" != "yes" && GITHUB_ADDR="https://gh.api.99988866.xyz/" || GITHUB_ADDR=""
|
||||
|
||||
if [ -d "$self_dir/source/cache/$2" ]; then
|
||||
echo "Using cache for $2"
|
||||
cp -r "$self_dir/source/cache/$2" "$self_dir/source/"
|
||||
else
|
||||
wget -O $self_dir/source/master.zip "$GITHUB_ADDR""https://github.com/$1/archive/master.zip" && \
|
||||
cd $self_dir/source/ && \
|
||||
unzip master.zip && \
|
||||
mv $2-master/ cache/$2 && \
|
||||
cp -r cache/$2 ./
|
||||
fi
|
||||
|
||||
# git clone https://$GITHUB_ADDR/$1.git --depth=1 $self_dir/source/$2
|
||||
34
docker/download-library-batch-aria2.sh
Executable file
34
docker/download-library-batch-aria2.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -exu
|
||||
__DIR__=$(
|
||||
cd "$(dirname "$0")"
|
||||
pwd
|
||||
)
|
||||
|
||||
cd ${__DIR__}
|
||||
|
||||
# https://aria2.github.io/manual/en/html/aria2c.html#http-ftp-segmented-downloads
|
||||
# https://aria2.github.io/manual/en/html/aria2c.html
|
||||
# -with-config-file-path=/usr/local/php/etc
|
||||
# -U, --user-agent
|
||||
# aria2c -h
|
||||
# aria2c --conf-path=/etc/aria2/aria2.conf
|
||||
|
||||
:<<EOF
|
||||
-c, --continue [true|false]
|
||||
-s, --split=<N>
|
||||
-x, --max-connection-per-server=<NUM>
|
||||
-k, --min-split-size=<SIZE>
|
||||
-j, --max-concurrent-downloads=<N>
|
||||
-i, --input-file=<FILE>
|
||||
EOF
|
||||
|
||||
user_agent='Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36'
|
||||
|
||||
|
||||
test -f download_library_urls.txt && aria2c -c -j 10 -s 10 -x 8 -k 10M --allow-overwrite=true --max-tries=30 --retry-wait=15 --user-agent=$user_agent \
|
||||
-d libraries --input-file=download_library_urls.txt
|
||||
|
||||
mkdir -p source/libraries
|
||||
awk 'BEGIN { cmd="cp -ri libraries/* source/libraries/" ; print "n" |cmd; }'
|
||||
60
docker/download.sh
Executable file
60
docker/download.sh
Executable file
@@ -0,0 +1,60 @@
|
||||
#!/bin/sh
|
||||
|
||||
_use_backup="$2"
|
||||
|
||||
SELF_DIR=$(cd "$(dirname "$0")";pwd)
|
||||
|
||||
if [ ! -d "source" ]; then
|
||||
mkdir source
|
||||
fi
|
||||
|
||||
if [ ! -d "source/cache" ]; then
|
||||
mkdir source/cache
|
||||
fi
|
||||
|
||||
function readconf() {
|
||||
cat $SELF_DIR/config.json | jq $@ | sed 's/\"//g'
|
||||
}
|
||||
|
||||
cd source
|
||||
|
||||
if [ "$_use_backup" = "yes" ]; then
|
||||
_use_backup="_2"
|
||||
else
|
||||
_use_backup=""
|
||||
fi
|
||||
|
||||
archive_find_tar=$(find cache/ -name "$1.*" | grep -E ".tgz" | tail -n1)
|
||||
archive_find_zip=$(find cache/ -name "$1.*" | grep -E ".zip" | tail -n1)
|
||||
|
||||
if [ "$archive_find_tar" != "" ]; then
|
||||
echo "Using cache for $1 ($archive_find_tar)"
|
||||
tar -zxf "$archive_find_tar"
|
||||
elif [ "$archive_find_zip" != "" ]; then
|
||||
echo "Using cache for $1 ($archive_find_zip)"
|
||||
unzip $archive_find_zip -d "$SELF_DIR/source" > /dev/null
|
||||
else
|
||||
if [ "$3" != "" ]; then
|
||||
wget -q "$(readconf ".$1.link$_use_backup" | sed 's/{version}/'$3'/g')"
|
||||
else
|
||||
echo "Downloading $1"
|
||||
wget -q "$(readconf ".$1.link$_use_backup" | sed 's/{version}/'$(readconf ".$1.version")'/g')"
|
||||
fi
|
||||
|
||||
if [ $? == 0 ]; then
|
||||
archive_file_tar=$(find . -name "*.*" -maxdepth 1 | grep -E ".tar|.gz|.tgz" | tail -n1)
|
||||
archive_file_zip=$(find . -name "*.zip" -maxdepth 1 | tail -n1)
|
||||
if [ "$archive_file_tar" != "" ]; then
|
||||
tar -zxf $archive_file_tar && mv $archive_file_tar $SELF_DIR/source/cache/$1.tgz
|
||||
elif [ "$archive_file_zip" != "" ]; then
|
||||
unzip $archive_file_zip && mv $archive_file_zip $SELF_DIR/source/cache/$1.zip > /dev/null
|
||||
else
|
||||
find . -name "*$1*.*"
|
||||
echo "Unable to find downloaded file, only support '.tar.gz', '.tgz', '.zip' file!"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Download $1 failed! (at $?)"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
22
docker/download_extension_urls.bak.txt
Normal file
22
docker/download_extension_urls.bak.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
https://pecl.php.net/get/redis-5.3.7.tgz
|
||||
out=redis-5.3.7.tgz
|
||||
https://pecl.php.net/get/yaml-2.2.2.tgz
|
||||
out=yaml-2.2.2.tgz
|
||||
https://pecl.php.net/get/imagick-3.6.0.tgz
|
||||
out=imagick-3.6.0.tgz
|
||||
https://pecl.php.net/get/mongodb-1.14.2.tgz
|
||||
out=mongodb-1.14.2.tgz
|
||||
https://pecl.php.net/get/apcu-5.1.22.tgz
|
||||
out=apcu-5.1.22.tgz
|
||||
https://pecl.php.net/get/ds-1.4.0.tgz
|
||||
out=ds-1.4.0.tgz
|
||||
https://pecl.php.net/get/inotify-3.0.0.tgz
|
||||
out=inotify-3.0.0.tgz
|
||||
https://pecl.php.net/get/xlswriter-1.5.2.tgz
|
||||
out=xlswriter-1.5.2.tgz
|
||||
https://pecl.php.net/get/zstd-0.12.1.tgz
|
||||
out=zstd-0.12.1.tgz
|
||||
https://pecl.php.net/get/event-3.0.8.tgz
|
||||
out=event-3.0.8.tgz
|
||||
https://pecl.php.net/get/mcrypt-1.0.5.tgz
|
||||
out=mcrypt-1.0.5.tgz
|
||||
4
docker/download_extension_urls.txt
Normal file
4
docker/download_extension_urls.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
https://pecl.php.net/get/mcrypt-1.0.5.tgz
|
||||
out=mcrypt-1.0.5.tgz
|
||||
https://pecl.php.net/get/apcu-5.1.22.tgz
|
||||
out=apcu-5.1.22.tgz
|
||||
72
docker/download_library_urls.bak.txt
Normal file
72
docker/download_library_urls.bak.txt
Normal file
@@ -0,0 +1,72 @@
|
||||
https://www.openssl.org/source/openssl-1.1.1p.tar.gz
|
||||
out=openssl-1.1.1p.tar.gz
|
||||
https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
|
||||
out=libiconv-1.16.tar.gz
|
||||
https://gitlab.gnome.org/GNOME/libxml2/-/archive/v2.9.10/libxml2-v2.9.10.tar.gz
|
||||
out=libxml2-v2.9.10.tar.gz
|
||||
https://gitlab.gnome.org/GNOME/libxslt/-/archive/v1.1.34/libxslt-v1.1.34.tar.gz
|
||||
out=libxslt-v1.1.34.tar.gz
|
||||
https://github.com/google/brotli/archive/refs/tags/v1.0.9.tar.gz
|
||||
out=brotli-1.0.9.tar.gz
|
||||
https://c-ares.org/download/c-ares-1.19.0.tar.gz
|
||||
out=c-ares-1.19.0.tar.gz
|
||||
https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz
|
||||
out=gmp-6.2.1.tar.lz
|
||||
https://mirrors.tuna.tsinghua.edu.cn/gnu/ncurses/ncurses-6.3.tar.gz https://mirrors.ustc.edu.cn/gnu/ncurses/ncurses-6.3.tar.gz https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.3.tar.gz
|
||||
out=ncurses-6.3.tar.gz
|
||||
https://mirrors.tuna.tsinghua.edu.cn/gnu/readline/readline-8.2.tar.gz https://mirrors.ustc.edu.cn/gnu/readline/readline-8.2.tar.gz https://ftp.gnu.org/gnu/readline/readline-8.2.tar.gz
|
||||
out=readline-8.2.tar.gz
|
||||
https://pyyaml.org/download/libyaml/yaml-0.2.5.tar.gz
|
||||
out=yaml-0.2.5.tar.gz
|
||||
https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz
|
||||
out=libsodium-1.0.18.tar.gz
|
||||
https://sourceware.org/pub/bzip2/bzip2-1.0.8.tar.gz
|
||||
out=bzip2-1.0.8.tar.gz
|
||||
https://udomain.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz
|
||||
out=zlib-1.2.11.tar.gz
|
||||
https://github.com/lz4/lz4/archive/refs/tags/v1.9.4.tar.gz
|
||||
out=lz4-v1.9.4.tar.gz
|
||||
https://github.com/tukaani-project/xz/releases/download/v5.4.1/xz-5.4.1.tar.gz
|
||||
out=xz-5.4.1.tar.gz
|
||||
https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz
|
||||
out=zstd-1.5.2.tar.gz
|
||||
https://libzip.org/download/libzip-1.9.2.tar.gz
|
||||
out=libzip-1.9.2.tar.gz
|
||||
https://www.sqlite.org/2021/sqlite-autoconf-3370000.tar.gz
|
||||
out=sqlite-autoconf-3370000.tar.gz
|
||||
https://github.com/unicode-org/icu/releases/download/release-60-3/icu4c-60_3-src.tgz
|
||||
out=icu4c-60_3-src.tgz
|
||||
https://codeload.github.com/kkos/oniguruma/tar.gz/refs/tags/v6.9.7
|
||||
out=oniguruma-6.9.7.tar.gz
|
||||
https://github.com/microsoft/mimalloc/archive/refs/tags/v2.0.7.tar.gz
|
||||
out=mimalloc-2.0.7.tar.gz
|
||||
https://codeload.github.com/libjpeg-turbo/libjpeg-turbo/tar.gz/refs/tags/2.1.2
|
||||
out=libjpeg-turbo-2.1.2.tar.gz
|
||||
https://nchc.dl.sourceforge.net/project/giflib/giflib-5.2.1.tar.gz
|
||||
out=giflib-5.2.1.tar.gz
|
||||
https://nchc.dl.sourceforge.net/project/libpng/libpng16/1.6.37/libpng-1.6.37.tar.gz
|
||||
out=libpng-1.6.37.tar.gz
|
||||
https://codeload.github.com/webmproject/libwebp/tar.gz/refs/tags/v1.2.1
|
||||
out=libwebp-1.2.1.tar.gz
|
||||
https://download.savannah.gnu.org/releases/freetype/freetype-2.10.4.tar.gz
|
||||
out=freetype-2.10.4.tar.gz
|
||||
https://github.com/ImageMagick/ImageMagick/archive/refs/tags/7.1.0-62.tar.gz
|
||||
out=ImageMagick-v7.1.0-62.tar.gz
|
||||
https://ftp.gnu.org/gnu/libidn/libidn2-2.3.4.tar.gz
|
||||
out=libidn2-2.3.4.tar.gz
|
||||
https://curl.se/download/curl-7.88.0.tar.gz
|
||||
out=curl-7.88.0.tar.gz
|
||||
https://ftp.postgresql.org/pub/source/v15.1/postgresql-15.1.tar.gz
|
||||
out=postgresql-15.1.tar.gz
|
||||
https://github.com/libffi/libffi/releases/download/v3.4.4/libffi-3.4.4.tar.gz
|
||||
out=libffi-3.4.4.tar.gz
|
||||
https://github.com/winlibs/libmcrypt/archive/refs/tags/libmcrypt-2.5.8-3.4.tar.gz
|
||||
out=libmcrypt-2.5.8-3.4.tar.gz
|
||||
https://github.com/jmcnamara/libxlsxwriter/archive/refs/tags/RELEASE_1.1.5.tar.gz
|
||||
out=libxlsxwriter-1.1.5.tar.gz
|
||||
https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
|
||||
out=libevent-2.1.12-stable.tar.gz
|
||||
https://github.com/libuv/libuv/archive/refs/tags/v1.44.2.tar.gz
|
||||
out=libuv-v1.44.2.tar.gz
|
||||
https://github.com/php/php-src/archive/refs/tags/php-8.1.12.tar.gz
|
||||
out=php-8.1.12.tar.gz
|
||||
4
docker/download_library_urls.txt
Normal file
4
docker/download_library_urls.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
https://github.com/winlibs/libmcrypt/archive/refs/tags/libmcrypt-2.5.8-3.4.tar.gz
|
||||
out=libmcrypt-2.5.8-3.4.tar.gz
|
||||
https://gmplib.org/download/gmp/gmp-6.2.1.tar.lz
|
||||
out=gmp-6.2.1.tar.lz
|
||||
44
docker/extensions.txt
Executable file
44
docker/extensions.txt
Executable file
@@ -0,0 +1,44 @@
|
||||
# Start with '#' is comments
|
||||
# Start with '^' is deselecting extensions, which is not installed as default
|
||||
# Each line just leave the extension name or ^ character
|
||||
|
||||
bcmath
|
||||
calendar
|
||||
ctype
|
||||
curl
|
||||
dom
|
||||
event
|
||||
exif
|
||||
fileinfo
|
||||
filter
|
||||
gd
|
||||
hash
|
||||
iconv
|
||||
inotify
|
||||
json
|
||||
libxml
|
||||
mbstring
|
||||
mongodb
|
||||
mysqlnd
|
||||
openssl
|
||||
pcntl
|
||||
pdo
|
||||
pdo_mysql
|
||||
pdo_sqlite
|
||||
phar
|
||||
posix
|
||||
^protobuf
|
||||
^readline
|
||||
redis
|
||||
shmop
|
||||
simplexml
|
||||
soap
|
||||
sockets
|
||||
sqlite3
|
||||
swoole
|
||||
tokenizer
|
||||
xml
|
||||
xmlreader
|
||||
xmlwriter
|
||||
zlib
|
||||
zip
|
||||
63
docker/fast-compiler.sh
Executable file
63
docker/fast-compiler.sh
Executable file
@@ -0,0 +1,63 @@
|
||||
#!/bin/sh
|
||||
|
||||
# This script needs alpine linux system.
|
||||
|
||||
self_dir=$(cd "$(dirname "$0")";pwd)
|
||||
|
||||
test "$VER_PHP" = "" && VER_PHP="8.1.7"
|
||||
test "$USE_BACKUP" = "" && USE_BACKUP="no"
|
||||
test "$ALL_EXTENSIONS" = "" && ALL_EXTENSIONS="all"
|
||||
|
||||
LINK_APK_REPO='mirrors.ustc.edu.cn'
|
||||
LINK_APK_REPO_BAK='dl-cdn.alpinelinux.org'
|
||||
|
||||
if [ "${USE_BACKUP}" = "yes" ]; then \
|
||||
echo "Using backup address..." && sleep 1s
|
||||
LINK_APK_REPO=${LINK_APK_REPO_BAK}
|
||||
else
|
||||
echo "Using original address..." && sleep 1s
|
||||
fi
|
||||
|
||||
sed -i 's/dl-cdn.alpinelinux.org/'${LINK_APK_REPO}'/g' /etc/apk/repositories
|
||||
|
||||
# build requirements
|
||||
apk add bash file wget cmake gcc g++ jq autoconf git libstdc++ linux-headers make m4 libgcc binutils ncurses dialog
|
||||
# php zlib dependencies
|
||||
apk add zlib-dev zlib-static
|
||||
# php mbstring dependencies
|
||||
apk add oniguruma-dev
|
||||
# php openssl dependencies
|
||||
apk add openssl-libs-static openssl-dev openssl
|
||||
# php gd dependencies
|
||||
apk add libpng-dev libpng-static
|
||||
# curl c-ares dependencies
|
||||
apk add c-ares-static c-ares-dev
|
||||
# php event dependencies
|
||||
apk add libevent libevent-dev libevent-static
|
||||
# php sqlite3 dependencies
|
||||
apk add sqlite sqlite-dev sqlite-libs sqlite-static
|
||||
# php libzip dependencies
|
||||
apk add bzip2-dev bzip2-static bzip2
|
||||
# php micro ffi dependencies
|
||||
apk add libffi libffi-dev
|
||||
# php gd event parent dependencies
|
||||
apk add zstd-static
|
||||
# php readline dependencies
|
||||
apk add readline-static ncurses-static readline-dev
|
||||
|
||||
test "$USE_BACKUP" = "no" && PROMPT_1="mirror" || PROMPT_1="original"
|
||||
|
||||
$self_dir/download.sh swoole ${USE_BACKUP} && \
|
||||
$self_dir/download.sh inotify ${USE_BACKUP} && \
|
||||
$self_dir/download.sh mongodb ${USE_BACKUP} && \
|
||||
$self_dir/download.sh event ${USE_BACKUP} && \
|
||||
$self_dir/download.sh redis ${USE_BACKUP} && \
|
||||
$self_dir/download.sh libxml2 ${USE_BACKUP} && \
|
||||
$self_dir/download.sh xz ${USE_BACKUP} && \
|
||||
$self_dir/download.sh protobuf ${USE_BACKUP} && \
|
||||
$self_dir/download.sh curl ${USE_BACKUP} && \
|
||||
$self_dir/download.sh libzip ${USE_BACKUP} && \
|
||||
$self_dir/download.sh libiconv ${USE_BACKUP} && \
|
||||
$self_dir/download-git.sh dixyes/phpmicro phpmicro ${USE_BACKUP} && \
|
||||
$self_dir/compile-deps.sh && \
|
||||
$self_dir/compile-php.sh $PROMPT_1 $VER_PHP $ALL_EXTENSIONS /dist/
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,219 +0,0 @@
|
||||
<template>
|
||||
<div class="contributors-container">
|
||||
<div class="contributors-header">
|
||||
<h2>Contributors</h2>
|
||||
<p class="contributors-description">
|
||||
Thanks to all the amazing people who have contributed to this project!
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div v-if="loading" class="loading-state">
|
||||
<div class="spinner"></div>
|
||||
<p>Loading contributors...</p>
|
||||
</div>
|
||||
|
||||
<div v-else-if="error" class="error-state">
|
||||
<p>{{ error }}</p>
|
||||
</div>
|
||||
|
||||
<div v-else class="contributors-grid">
|
||||
<a
|
||||
v-for="contributor in contributors"
|
||||
:key="contributor.id"
|
||||
:href="contributor.html_url"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="contributor-card"
|
||||
:title="contributor.login"
|
||||
>
|
||||
<img
|
||||
:src="contributor.avatar_url"
|
||||
:alt="contributor.login"
|
||||
class="contributor-avatar"
|
||||
loading="lazy"
|
||||
/>
|
||||
<div class="contributor-name">{{ contributor.login }}</div>
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
|
||||
interface Contributor {
|
||||
id: number;
|
||||
login: string;
|
||||
avatar_url: string;
|
||||
html_url: string;
|
||||
contributions: number;
|
||||
}
|
||||
|
||||
const contributors = ref<Contributor[]>([]);
|
||||
const loading = ref(true);
|
||||
const error = ref('');
|
||||
|
||||
const fetchContributors = async () => {
|
||||
try {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
|
||||
const response = await fetch(
|
||||
'https://api.github.com/repos/crazywhalecc/static-php-cli/contributors?per_page=24'
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error('Failed to fetch contributors');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
contributors.value = data;
|
||||
} catch (err) {
|
||||
error.value = 'Failed to load contributors. Please try again later.';
|
||||
console.error('Error fetching contributors:', err);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
fetchContributors();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.contributors-container {
|
||||
margin: 48px auto;
|
||||
padding: 32px 24px;
|
||||
max-width: 1152px;
|
||||
background: linear-gradient(135deg, var(--vp-c-bg-soft) 0%, var(--vp-c-bg) 100%);
|
||||
border-radius: 16px;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
|
||||
}
|
||||
|
||||
.contributors-header {
|
||||
text-align: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.contributors-header h2 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px 0;
|
||||
background: linear-gradient(120deg, var(--vp-c-brand-1), var(--vp-c-brand-2));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.contributors-description {
|
||||
font-size: 0.95rem;
|
||||
color: var(--vp-c-text-2);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
.loading-state,
|
||||
.error-state {
|
||||
text-align: center;
|
||||
padding: 40px 20px;
|
||||
color: var(--vp-c-text-2);
|
||||
}
|
||||
|
||||
.spinner {
|
||||
width: 40px;
|
||||
height: 40px;
|
||||
margin: 0 auto 16px;
|
||||
border: 4px solid var(--vp-c-divider);
|
||||
border-top-color: var(--vp-c-brand-1);
|
||||
border-radius: 50%;
|
||||
animation: spin 1s linear infinite;
|
||||
}
|
||||
|
||||
@keyframes spin {
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
||||
.contributors-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.contributor-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
background: var(--vp-c-bg);
|
||||
border-radius: 12px;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
transition: all 0.3s ease;
|
||||
text-decoration: none;
|
||||
color: var(--vp-c-text-1);
|
||||
}
|
||||
|
||||
.contributor-card:hover {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
|
||||
border-color: var(--vp-c-brand-1);
|
||||
}
|
||||
|
||||
.contributor-avatar {
|
||||
width: 60px;
|
||||
height: 60px;
|
||||
border-radius: 50%;
|
||||
border: 2px solid var(--vp-c-divider);
|
||||
transition: all 0.3s ease;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.contributor-card:hover .contributor-avatar {
|
||||
border-color: var(--vp-c-brand-1);
|
||||
transform: scale(1.05);
|
||||
}
|
||||
|
||||
.contributor-name {
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
word-break: break-word;
|
||||
max-width: 100%;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.contributors-container {
|
||||
margin: 32px 16px;
|
||||
padding: 24px 16px;
|
||||
}
|
||||
|
||||
.contributors-header h2 {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.contributors-description {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
|
||||
.contributors-grid {
|
||||
grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.contributor-card {
|
||||
padding: 8px;
|
||||
}
|
||||
|
||||
.contributor-avatar {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
}
|
||||
|
||||
.contributor-name {
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,193 +0,0 @@
|
||||
export function getMetaList(meta, type, name, list_name) {
|
||||
if (meta.os === 'linux') {
|
||||
return meta[type][name][list_name + '-linux'] ?? meta[type][name][list_name + '-unix'] ?? meta[type][name][list_name] ?? [];
|
||||
}
|
||||
if (meta.os === 'macos') {
|
||||
return meta[type][name][list_name + '-macos'] ?? meta[type][name][list_name + '-unix'] ?? meta[type][name][list_name] ?? [];
|
||||
}
|
||||
if (meta.os === 'windows') {
|
||||
return meta[type][name][list_name + '-windows'] ?? meta[type][name][list_name] ?? [];
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
export function getExtDepends(meta, ext_name) {
|
||||
return getMetaList(meta, 'ext', ext_name, 'ext-depends');
|
||||
}
|
||||
|
||||
export function getExtSuggests(meta, ext_name) {
|
||||
return getMetaList(meta, 'ext', ext_name, 'ext-suggests');
|
||||
}
|
||||
|
||||
export function getExtLibDepends(meta, ext_name) {
|
||||
const ls = getMetaList(meta, 'ext', ext_name, 'lib-depends');
|
||||
return ls;
|
||||
}
|
||||
|
||||
export function getExtLibSuggests(meta, ext_name) {
|
||||
return getMetaList(meta, 'ext', ext_name, 'lib-suggests');
|
||||
}
|
||||
|
||||
export function getLibDepends(meta, lib_name) {
|
||||
return getMetaList(meta, 'lib', lib_name, 'lib-depends');
|
||||
}
|
||||
|
||||
export function getLibSuggests(meta, lib_name) {
|
||||
return getMetaList(meta, 'lib', lib_name, 'lib-suggests');
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the dependent lib list according to the required ext list, and sort according to the dependency
|
||||
* @param meta
|
||||
* @param exts
|
||||
*/
|
||||
export function getExtLibsByDeps(meta, exts) {
|
||||
const sorted = [];
|
||||
const visited = new Set();
|
||||
const notIncludedExts = [];
|
||||
exts.forEach((ext) => {
|
||||
if (!visited.has(ext)) {
|
||||
visitExtDeps(meta, ext, visited, sorted);
|
||||
}
|
||||
});
|
||||
|
||||
const sortedSuggests = [];
|
||||
const visitedSuggests = new Set();
|
||||
const final = [];
|
||||
exts.forEach((ext) => {
|
||||
if (!visited.has(ext)) {
|
||||
visitExtAllDeps(meta, ext, visitedSuggests, sortedSuggests);
|
||||
}
|
||||
});
|
||||
sortedSuggests.forEach((suggest) => {
|
||||
if (sorted.indexOf(suggest) !== -1) {
|
||||
final.push(suggest);
|
||||
}
|
||||
});
|
||||
const libs = [];
|
||||
final.forEach((ext) => {
|
||||
if (exts.indexOf(ext) === -1) {
|
||||
notIncludedExts.push(ext);
|
||||
}
|
||||
getExtLibDepends(meta, ext).forEach((lib) => {
|
||||
if (libs.indexOf(lib) === -1) {
|
||||
libs.push(lib);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
return { exts: final, libs: getLibsByDeps(meta, libs), notIncludedExts: notIncludedExts };
|
||||
}
|
||||
|
||||
export function getAllExtLibsByDeps(meta, exts) {
|
||||
const sorted = [];
|
||||
const visited = new Set();
|
||||
const notIncludedExts = [];
|
||||
exts.forEach((ext) => {
|
||||
if (!visited.has(ext)) {
|
||||
visitExtAllDeps(meta, ext, visited, sorted);
|
||||
}
|
||||
});
|
||||
const libs = [];
|
||||
sorted.forEach((ext) => {
|
||||
if (exts.indexOf(ext) === -1) {
|
||||
notIncludedExts.push(ext);
|
||||
}
|
||||
const allLibs = [...getExtLibDepends(meta, ext), ...getExtLibSuggests(meta, ext)];
|
||||
allLibs.forEach((dep) => {
|
||||
if (libs.indexOf(dep) === -1) {
|
||||
libs.push(dep);
|
||||
}
|
||||
});
|
||||
});
|
||||
return { exts: sorted, libs: getAllLibsByDeps(meta, libs), notIncludedExts: notIncludedExts };
|
||||
}
|
||||
|
||||
export function getAllLibsByDeps(meta, libs) {
|
||||
const sorted = [];
|
||||
const visited = new Set();
|
||||
|
||||
libs.forEach((lib) => {
|
||||
if (!visited.has(lib)) {
|
||||
console.log('before visited');
|
||||
console.log(visited);
|
||||
visitLibAllDeps(meta, lib, visited, sorted);
|
||||
console.log('after visited');
|
||||
console.log(visited);
|
||||
}
|
||||
});
|
||||
return sorted;
|
||||
}
|
||||
|
||||
export function getLibsByDeps(meta, libs) {
|
||||
const sorted = [];
|
||||
const visited = new Set();
|
||||
|
||||
libs.forEach((lib) => {
|
||||
if (!visited.has(lib)) {
|
||||
visitLibDeps(meta, lib, visited, sorted);
|
||||
}
|
||||
});
|
||||
|
||||
const sortedSuggests = [];
|
||||
const visitedSuggests = new Set();
|
||||
const final = [];
|
||||
libs.forEach((lib) => {
|
||||
if (!visitedSuggests.has(lib)) {
|
||||
visitLibAllDeps(meta, lib, visitedSuggests, sortedSuggests);
|
||||
}
|
||||
});
|
||||
sortedSuggests.forEach((suggest) => {
|
||||
if (sorted.indexOf(suggest) !== -1) {
|
||||
final.push(suggest);
|
||||
}
|
||||
});
|
||||
return final;
|
||||
}
|
||||
|
||||
export function visitLibAllDeps(meta, lib_name, visited, sorted) {
|
||||
if (visited.has(lib_name)) {
|
||||
return;
|
||||
}
|
||||
visited.add(lib_name);
|
||||
const allLibs = [...getLibDepends(meta, lib_name), ...getLibSuggests(meta, lib_name)];
|
||||
allLibs.forEach((dep) => {
|
||||
visitLibDeps(meta, dep, visited, sorted);
|
||||
});
|
||||
sorted.push(lib_name);
|
||||
}
|
||||
|
||||
export function visitLibDeps(meta, lib_name, visited, sorted) {
|
||||
if (visited.has(lib_name)) {
|
||||
return;
|
||||
}
|
||||
visited.add(lib_name);
|
||||
getLibDepends(meta, lib_name).forEach((dep) => {
|
||||
visitLibDeps(meta, dep, visited, sorted);
|
||||
});
|
||||
sorted.push(lib_name);
|
||||
}
|
||||
|
||||
export function visitExtDeps(meta, ext_name, visited, sorted) {
|
||||
if (visited.has(visited)) {
|
||||
return;
|
||||
}
|
||||
visited.add(ext_name);
|
||||
getExtDepends(meta, ext_name).forEach((dep) => {
|
||||
visitExtDeps(meta, dep, visited, sorted);
|
||||
});
|
||||
sorted.push(ext_name);
|
||||
}
|
||||
|
||||
export function visitExtAllDeps(meta, ext_name, visited, sorted) {
|
||||
if (visited.has(ext_name)) {
|
||||
return;
|
||||
}
|
||||
visited.add(ext_name);
|
||||
|
||||
const allExts = [...getExtDepends(meta, ext_name), ...getExtSuggests(meta, ext_name)];
|
||||
allExts.forEach((dep) => {
|
||||
visitExtDeps(meta, dep, visited, sorted);
|
||||
});
|
||||
sorted.push(ext_name);
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<template>
|
||||
<div>
|
||||
<header class="DocSearch-SearchBar" style="padding: 0">
|
||||
<form class="DocSearch-Form searchinput">
|
||||
<input class="DocSearch-Input" v-model="filterText" placeholder="Filter name..." @input="doFilter" />
|
||||
</form>
|
||||
</header>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Extension Name</th>
|
||||
<th>Linux</th>
|
||||
<th>macOS</th>
|
||||
<th>FreeBSD</th>
|
||||
<th>Windows</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="item in filterData">
|
||||
<td v-if="!item.notes">{{ item.name }}</td>
|
||||
<td v-else>
|
||||
<a :href="'./extension-notes.html#' + item.name">{{ item.name }}</a>
|
||||
</td>
|
||||
<td>{{ item.linux }}</td>
|
||||
<td>{{ item.macos }}</td>
|
||||
<td>{{ item.freebsd }}</td>
|
||||
<td>{{ item.windows }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<div v-if="filterData.length === 0" style="margin: 0 4px 20px 4px; color: var(--vp-c-text-2); font-size: 14px">
|
||||
No result, please try another keyword.
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "SearchTable"
|
||||
}
|
||||
</script>
|
||||
|
||||
<script setup>
|
||||
import {ref} from "vue";
|
||||
import ext from '../../../config/ext.json';
|
||||
|
||||
// 将 ext 转换为列表,方便后续操作
|
||||
const data = ref([]);
|
||||
for (const [name, item] of Object.entries(ext)) {
|
||||
data.value.push({
|
||||
name,
|
||||
linux: item.support?.Linux === undefined ? 'yes' : (item.support?.Linux === 'wip' ? '' : item.support?.Linux),
|
||||
macos: item.support?.Darwin === undefined ? 'yes' : (item.support?.Darwin === 'wip' ? '' : item.support?.Darwin),
|
||||
freebsd: item.support?.BSD === undefined ? 'yes' : (item.support?.BSD === 'wip' ? '' : item.support?.BSD),
|
||||
windows: item.support?.Windows === undefined ? 'yes' : (item.support?.Windows === 'wip' ? '' : item.support?.Windows),
|
||||
notes: item.notes === true,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
const filterData = ref(data.value);
|
||||
const filterText = ref('');
|
||||
|
||||
const doFilter = () => {
|
||||
if (filterText.value === '') {
|
||||
filterData.value = data.value;
|
||||
return;
|
||||
}
|
||||
filterData.value = data.value.filter(item => {
|
||||
return item.name.toLowerCase().includes(filterText.value.toLowerCase());
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.searchinput {
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
}
|
||||
</style>
|
||||
@@ -1,65 +0,0 @@
|
||||
import sidebarEn from "./sidebar.en";
|
||||
import sidebarZh from "./sidebar.zh";
|
||||
|
||||
|
||||
// https://vitepress.dev/reference/site-config
|
||||
export default {
|
||||
title: "Static PHP",
|
||||
description: "Build single static PHP binary, with PHP project together, with popular extensions included.",
|
||||
locales: {
|
||||
en: {
|
||||
label: 'English',
|
||||
lang: 'en',
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{text: 'Guide', link: '/en/guide/',},
|
||||
{text: 'Advanced', link: '/en/develop/'},
|
||||
{text: 'Contributing', link: '/en/contributing/'},
|
||||
{text: 'FAQ', link: '/en/faq/'},
|
||||
],
|
||||
sidebar: sidebarEn,
|
||||
footer: {
|
||||
message: 'Released under the MIT License.',
|
||||
copyright: 'Copyright © 2023-present crazywhalecc'
|
||||
}
|
||||
},
|
||||
},
|
||||
zh: {
|
||||
label: '简体中文',
|
||||
lang: 'zh', // optional, will be added as `lang` attribute on `html` tag
|
||||
themeConfig: {
|
||||
nav: [
|
||||
{text: '构建指南', link: '/zh/guide/'},
|
||||
{text: '进阶', link: '/zh/develop/'},
|
||||
{text: '贡献', link: '/zh/contributing/'},
|
||||
{text: 'FAQ', link: '/zh/faq/'},
|
||||
],
|
||||
sidebar: sidebarZh,
|
||||
footer: {
|
||||
message: 'Released under the MIT License.',
|
||||
copyright: 'Copyright © 2023-present crazywhalecc'
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
themeConfig: {
|
||||
// https://vitepress.dev/reference/default-theme-config
|
||||
logo: '/images/static-php_nobg.png',
|
||||
nav: [],
|
||||
socialLinks: [
|
||||
{icon: 'github', link: 'https://github.com/crazywhalecc/static-php-cli'}
|
||||
],
|
||||
footer: {
|
||||
message: 'Released under the MIT License.',
|
||||
copyright: 'Copyright © 2023-present crazywhalecc'
|
||||
},
|
||||
search: {
|
||||
provider: 'algolia',
|
||||
options: {
|
||||
appId: 'IHJHUB1SF1',
|
||||
apiKey: '8266d31cc2ffbd0e059f1c6e5bdaf8fc',
|
||||
indexName: 'static-php docs',
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
export default {
|
||||
'/en/guide/': [
|
||||
{
|
||||
text: 'Basic Build Guides',
|
||||
items: [
|
||||
{text: 'Guide', link: '/en/guide/'},
|
||||
{text: 'Build (Local)', link: '/en/guide/manual-build'},
|
||||
{text: 'Build (CI)', link: '/en/guide/action-build'},
|
||||
{text: 'Supported Extensions', link: '/en/guide/extensions'},
|
||||
{text: 'Extension Notes', link: '/en/guide/extension-notes'},
|
||||
{text: 'Build Command Generator', link: '/en/guide/cli-generator'},
|
||||
{text: 'Environment Variables', link: '/en/guide/env-vars', collapsed: true,},
|
||||
{text: 'Dependency Table', link: '/en/guide/deps-map'},
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'Extended Build Guides',
|
||||
items: [
|
||||
{text: 'Troubleshooting', link: '/en/guide/troubleshooting'},
|
||||
{text: 'Build on Windows', link: '/en/guide/build-on-windows'},
|
||||
{text: 'Build with GNU libc', link: '/en/guide/build-with-glibc'},
|
||||
],
|
||||
}
|
||||
],
|
||||
'/en/develop/': [
|
||||
{
|
||||
text: 'Development',
|
||||
items: [
|
||||
{text: 'Get Started', link: '/en/develop/'},
|
||||
{text: 'Project Structure', link: '/en/develop/structure'},
|
||||
{text: 'PHP Source Modification', link: '/en/develop/php-src-changes'},
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Module',
|
||||
items: [
|
||||
{text: 'Doctor ', link: '/en/develop/doctor-module'},
|
||||
{text: 'Source', link: '/en/develop/source-module'},
|
||||
]
|
||||
},
|
||||
{
|
||||
text: 'Extra',
|
||||
items: [
|
||||
{text: 'Compilation Tools', link: '/en/develop/system-build-tools'},
|
||||
{text: 'craft.yml Configuration', link: '/zh/develop/craft-yml'},
|
||||
]
|
||||
}
|
||||
],
|
||||
'/en/contributing/': [
|
||||
{
|
||||
text: 'Contributing',
|
||||
items: [
|
||||
{text: 'Contributing', link: '/en/contributing/'},
|
||||
],
|
||||
}
|
||||
],
|
||||
};
|
||||
@@ -1,57 +0,0 @@
|
||||
export default {
|
||||
'/zh/guide/': [
|
||||
{
|
||||
text: '构建指南',
|
||||
items: [
|
||||
{text: '指南', link: '/zh/guide/'},
|
||||
{text: '本地构建', link: '/zh/guide/manual-build'},
|
||||
{text: 'Actions 构建', link: '/zh/guide/action-build'},
|
||||
{text: '扩展列表', link: '/zh/guide/extensions'},
|
||||
{text: '扩展注意事项', link: '/zh/guide/extension-notes'},
|
||||
{text: '编译命令生成器', link: '/zh/guide/cli-generator'},
|
||||
{text: '环境变量列表', link: '/zh/guide/env-vars'},
|
||||
{text: '依赖关系图表', link: '/zh/guide/deps-map'},
|
||||
]
|
||||
},
|
||||
{
|
||||
text: '扩展构建指南',
|
||||
items: [
|
||||
{text: '故障排除', link: '/zh/guide/troubleshooting'},
|
||||
{text: '在 Windows 上构建', link: '/zh/guide/build-on-windows'},
|
||||
{text: '构建 GNU libc 兼容的二进制', link: '/zh/guide/build-with-glibc'},
|
||||
],
|
||||
}
|
||||
],
|
||||
'/zh/develop/': [
|
||||
{
|
||||
text: '开发指南',
|
||||
items: [
|
||||
{text: '开发简介', link: '/zh/develop/'},
|
||||
{text: '项目结构简介', link: '/zh/develop/structure'},
|
||||
{text: '对 PHP 源码的修改', link: '/zh/develop/php-src-changes'},
|
||||
],
|
||||
},
|
||||
{
|
||||
text: '模块',
|
||||
items: [
|
||||
{text: 'Doctor 环境检查工具', link: '/zh/develop/doctor-module'},
|
||||
{text: '资源模块', link: '/zh/develop/source-module'},
|
||||
]
|
||||
},
|
||||
{
|
||||
text: '其他',
|
||||
items: [
|
||||
{text: '系统编译工具', link: '/zh/develop/system-build-tools'},
|
||||
{text: 'craft.yml 配置详解', link: '/zh/develop/craft-yml'},
|
||||
]
|
||||
}
|
||||
],
|
||||
'/zh/contributing/': [
|
||||
{
|
||||
text: '贡献指南',
|
||||
items: [
|
||||
{text: '贡献指南', link: '/zh/contributing/'},
|
||||
],
|
||||
}
|
||||
],
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
// docs/.vitepress/theme/index.ts
|
||||
import DefaultTheme from 'vitepress/theme'
|
||||
import {inBrowser, useData} from "vitepress";
|
||||
import {watchEffect} from "vue";
|
||||
import './style.css';
|
||||
|
||||
export default {
|
||||
...DefaultTheme,
|
||||
setup() {
|
||||
const { lang } = useData()
|
||||
watchEffect(() => {
|
||||
if (inBrowser) {
|
||||
document.cookie = `nf_lang=${lang.value}; expires=Mon, 1 Jan 2024 00:00:00 UTC; path=/`
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,24 +0,0 @@
|
||||
/** override default styles */
|
||||
.vp-sponsor-grid-image {
|
||||
max-height:36px !important;
|
||||
max-width: 1000px !important;
|
||||
}
|
||||
|
||||
|
||||
.vp-doc .contributors-header h2 {
|
||||
padding-top: 0;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.vp-doc .sponsors-header h2 {
|
||||
padding-top: 0;
|
||||
border-top: none;
|
||||
}
|
||||
|
||||
.dark .VPImage.logo {
|
||||
filter: contrast(0.7);
|
||||
}
|
||||
|
||||
.dark .VPImage.image-src {
|
||||
filter: contrast(0.7);
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
```yaml
|
||||
# PHP version to build (default: 8.4)
|
||||
php-version: 8.4
|
||||
# [REQUIRED] Static PHP extensions to build (list or comma-separated are both accepted)
|
||||
extensions: bcmath,fileinfo,phar,zlib,sodium,posix,pcntl
|
||||
# Extra libraries to build (list or comma-separated are both accepted)
|
||||
libs: [ ]
|
||||
# [REQUIRED] Build SAPIs (list or comma-separated are both accepted)
|
||||
sapi: cli,micro,fpm
|
||||
# Show full console output (default: false)
|
||||
debug: false
|
||||
# Build options (same as `build` command options, all options are optional)
|
||||
build-options:
|
||||
# Before build, remove all old build files and sources (default: false)
|
||||
with-clean: false
|
||||
# Build with all suggested libraries (default: false)
|
||||
with-suggested-libs: false
|
||||
# Build with all suggested extensions (default: false)
|
||||
with-suggested-exts: false
|
||||
# Build extra shared extensions (list or comma-separated are both accepted)
|
||||
build-shared: [ ]
|
||||
# Build without stripping the binary (default: false)
|
||||
no-strip: false
|
||||
# Disable Opcache JIT (default: false)
|
||||
disable-opcache-jit: false
|
||||
# PHP configuration options (same as --with-config-file-path)
|
||||
with-config-file-path: ""
|
||||
# PHP configuration options (same as --with-config-file-scan-dir)
|
||||
with-config-file-scan-dir: ""
|
||||
# Hardcoded INI options for cli and micro SAPI (e.g. "memory_limit=4G", list accepted)
|
||||
with-hardcoded-ini: [ ]
|
||||
# Pretend micro SAPI as cli SAPI to avoid some frameworks to limit the usage of micro SAPI
|
||||
with-micro-fake-cli: false
|
||||
# Additional patch point injection files (e.g. "path/to/patch.php", list accepted)
|
||||
with-added-patch: [ ]
|
||||
# Ignore micro extension tests (if you are using micro SAPI, default: false)
|
||||
without-micro-ext-test: false
|
||||
# UPX pack the binary (default: false)
|
||||
with-upx-pack: false
|
||||
# Set the micro.exe program icon (only for Windows, default: "")
|
||||
with-micro-logo: ""
|
||||
# Set micro SAPI as win32 mode, without this, micro SAPI will be compiled as a console application (only for Windows, default: false)
|
||||
enable-micro-win32: false
|
||||
|
||||
# Build options for shared extensions (list or comma-separated are both accepted)
|
||||
shared-extensions: [ ]
|
||||
|
||||
# Download options
|
||||
download-options:
|
||||
# Use custom url for specified sources, format: "{source-name}:{url}" (e.g. "php-src:https://example.com/php-8.4.0.tar.gz")
|
||||
custom-url: [ ]
|
||||
# Use custom git repo for specified sources, format: "{source-name}:{branch}:{url}" (e.g. "php-src:master:https://github.com/php/php-src.git")
|
||||
custom-git: [ ]
|
||||
# Retries count for downloading sources (default: 5)
|
||||
retry: 5
|
||||
# Use pre-built libraries if available (default: false)
|
||||
prefer-pre-built: true
|
||||
# Do not download from alternative sources (default: false)
|
||||
no-alt: false
|
||||
|
||||
craft-options:
|
||||
doctor: true
|
||||
download: true
|
||||
build: true
|
||||
|
||||
# Extra environment variables
|
||||
extra-env:
|
||||
# e.g. Use github token to avoid rate limit
|
||||
GITHUB_TOKEN: your-github-token
|
||||
```
|
||||
@@ -1,63 +0,0 @@
|
||||
# Contributing
|
||||
|
||||
Thank you for being here, this project welcomes your contributions!
|
||||
|
||||
## Contribution Guide
|
||||
|
||||
If you have code or documentation to contribute, here's what you need to know first.
|
||||
|
||||
1. What type of code are you contributing? (new extensions, bug fixes, security issues, project framework optimizations, documentation)
|
||||
2. If you contribute new files or new snippets, is your code checked by `php-cs-fixer` and `phpstan`?
|
||||
3. Have you fully read the [Developer Guide](../develop/) before contributing code?
|
||||
|
||||
If you can answer the above questions and have made changes to the code,
|
||||
you can initiate a Pull Request in the project GitHub repository in time.
|
||||
After the code review is completed, the code can be modified according to the suggestion, or directly merged into the main branch.
|
||||
|
||||
## Contribution Type
|
||||
|
||||
The main purpose of this project is to compile statically linked PHP binaries,
|
||||
and the command line processing function is written based on `symfony/console`.
|
||||
Before development, if you are not familiar with it,
|
||||
Check out the [symfony/console documentation](https://symfony.com/doc/current/components/console.html) first.
|
||||
|
||||
### Security Update
|
||||
|
||||
Because this project is basically a PHP project running locally, generally speaking, there will be no remote attacks.
|
||||
But if you find such a problem, please **DO NOT submit a PR or Issue in the GitHub repository,
|
||||
You need to contact the project maintainer (crazywhalecc) via [mail](mailto:admin@zhamao.me).
|
||||
|
||||
### Fix Bugs
|
||||
|
||||
Fixing bugs generally does not involve modification of the project structure and framework,
|
||||
so if you can locate the wrong code and fix it directly, please submit a PR directly.
|
||||
|
||||
### New Extensions
|
||||
|
||||
For adding a new extension,
|
||||
you need to understand some basic structure of the project and how to add a new extension according to the existing logic.
|
||||
It will be covered in detail in the next section on this page.
|
||||
In general, you will need:
|
||||
|
||||
1. Evaluate whether the extension can be compiled inline into PHP.
|
||||
2. Evaluate whether the extension's dependent libraries (if any) can be compiled statically.
|
||||
3. Write library compile commands on different platforms.
|
||||
4. Verify that the extension and its dependencies are compatible with existing extensions and dependencies.
|
||||
5. Verify that the extension works normally in `cli`, `micro`, `fpm`, `embed` SAPIs.
|
||||
6. Write documentation and add your extension.
|
||||
|
||||
### Project Framework Optimization
|
||||
|
||||
If you are already familiar with the working principle of `symfony/console`,
|
||||
and at the same time want to make some modifications or optimizations to the framework of the project,
|
||||
please understand the following things first:
|
||||
|
||||
1. Adding extensions does not belong to project framework optimization,
|
||||
but if you find that you have to optimize the framework when adding new extensions,
|
||||
you need to modify the framework itself before adding extensions.
|
||||
2. For some large-scale logical modifications (such as those involving LibraryBase, Extension objects, etc.),
|
||||
it is recommended to submit an Issue or Draft PR for discussion first.
|
||||
3. In the early stage of the project, it was a pure private development project, and there were some Chinese comments in the code.
|
||||
After internationalizing your project you can submit a PR to translate these comments into English.
|
||||
4. Please do not submit more useless code fragments in the code,
|
||||
such as a large number of unused variables, methods, classes, and code that has been rewritten many times.
|
||||
@@ -1,7 +0,0 @@
|
||||
---
|
||||
aside: false
|
||||
---
|
||||
|
||||
# craft.yml Configuration
|
||||
|
||||
<!--@include: ../../deps-craft-yml.md-->
|
||||
@@ -1,70 +0,0 @@
|
||||
# Doctor module
|
||||
|
||||
The Doctor module is a relatively independent module used to check the system environment, which can be entered with the command `bin/spc doctor`, and the entry command class is in `DoctorCommand.php`.
|
||||
|
||||
The Doctor module is a checklist with a series of check items and automatic repair items.
|
||||
These items are stored in the `src/SPC/doctor/item/` directory,
|
||||
And two Attributes are used as check item tags and auto-fix item tags: `#[AsCheckItem]` and `#[AsFixItem]`.
|
||||
|
||||
Take the existing check item `if necessary tools are installed`,
|
||||
which is used to check whether the packages necessary for compilation are installed in the macOS system.
|
||||
The following is its source code:
|
||||
|
||||
```php
|
||||
use SPC\doctor\AsCheckItem;
|
||||
use SPC\doctor\AsFixItem;
|
||||
use SPC\doctor\CheckResult;
|
||||
|
||||
#[AsCheckItem('if necessary tools are installed', limit_os: 'Darwin', level: 997)]
|
||||
public function checkCliTools(): ?CheckResult
|
||||
{
|
||||
$missing = [];
|
||||
foreach (self::REQUIRED_COMMANDS as $cmd) {
|
||||
if ($this->findCommand($cmd) === null) {
|
||||
$missing[] = $cmd;
|
||||
}
|
||||
}
|
||||
if (!empty($missing)) {
|
||||
return CheckResult::fail('missing system commands: ' . implode(', ', $missing), 'build-tools', [$missing]);
|
||||
}
|
||||
return CheckResult::ok();
|
||||
}
|
||||
```
|
||||
|
||||
The first parameter of the attribute is the name of the check item,
|
||||
and the following `limit_os` parameter restricts the check item to be triggered only under the specified system,
|
||||
and `level` is the priority of executing the check item, the larger the number, the higher the priority higher.
|
||||
|
||||
The `$this->findCommand()` method used in it is the method of `SPC\builder\traits\UnixSystemUtilTrait`,
|
||||
the purpose is to find the location of the system command, and return NULL if it cannot be found.
|
||||
|
||||
Each check item method should return a `SPC\doctor\CheckResult`:
|
||||
|
||||
- When returning `CheckResult::fail()`, the first parameter is used to output the error prompt of the terminal,
|
||||
and the second parameter is the name of the repair item when this check item can be automatically repaired.
|
||||
- When `CheckResult::ok()` is returned, the check passed. You can also pass a parameter to return the check result, for example: `CheckResult::ok('OS supported')`.
|
||||
- When returning `CheckResult::fail()`, if the third parameter is included, the array of the third parameter will be used as the parameter of `AsFixItem`.
|
||||
|
||||
The following is the method for automatically repairing items corresponding to this check item:
|
||||
|
||||
```php
|
||||
#[AsFixItem('build-tools')]
|
||||
public function fixBuildTools(array $missing): bool
|
||||
{
|
||||
foreach ($missing as $cmd) {
|
||||
try {
|
||||
shell(true)->exec('brew install ' . escapeshellarg($cmd));
|
||||
} catch (RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
`#[AsFixItem()]` first parameter is the name of the fix item, and this method must return True or False.
|
||||
When False is returned, the automatic repair failed and manual handling is required.
|
||||
|
||||
In the code here, `shell()->exec()` is the method of executing commands of the project,
|
||||
which is used to replace `exec()` and `system()`, and also provides debugging, obtaining execution status,
|
||||
entering directories, etc. characteristic.
|
||||
@@ -1,35 +0,0 @@
|
||||
# Start Developing
|
||||
|
||||
Developing this project requires the installation and deployment of a PHP environment,
|
||||
as well as some extensions and Composer commonly used in PHP projects.
|
||||
|
||||
The development environment and running environment of the project are almost exactly the same.
|
||||
You can refer to the **Manual Build** section to install system PHP or use the pre-built static PHP of this project as the environment.
|
||||
I will not go into details here.
|
||||
|
||||
Regardless of its purpose, this project itself is actually a `php-cli` program. You can edit and develop it as a normal PHP project.
|
||||
At the same time, you need to understand the Shell languages of different systems.
|
||||
|
||||
The current purpose of this project is to compile statically compiled independent PHP,
|
||||
but the main part also includes compiling static versions of many dependent libraries,
|
||||
so you can reuse this set of compilation logic to build independent binary versions of other programs, such as Nginx, etc.
|
||||
|
||||
## Environment preparation
|
||||
|
||||
A PHP environment is required to develop this project. You can use the PHP that comes with the system,
|
||||
or you can use the static PHP built by this project.
|
||||
|
||||
Regardless of which PHP you use, in your development environment you need to install these extensions:
|
||||
|
||||
```
|
||||
curl,dom,filter,mbstring,openssl,pcntl,phar,posix,sodium,tokenizer,xml,xmlwriter
|
||||
```
|
||||
|
||||
The static-php-cli project itself does not require so many extensions, but during the development process,
|
||||
you will use tools such as Composer and PHPUnit, which require these extensions.
|
||||
|
||||
> For micro self-executing binaries built by static-php-cli itself, only `pcntl,posix,mbstring,tokenizer,phar` is required.
|
||||
|
||||
## Start development
|
||||
|
||||
Continuing down to see the project structure documentation, you can learn how `static-php-cli` works.
|
||||
@@ -1,59 +0,0 @@
|
||||
# Modifications to PHP source code
|
||||
|
||||
During the static compilation process, static-php-cli made some modifications to the PHP source code
|
||||
in order to achieve good compatibility, performance, and security.
|
||||
The following is a description of the current modifications to the PHP source code.
|
||||
|
||||
## Micro related patches
|
||||
|
||||
Based on the patches provided by the phpmicro project,
|
||||
static-php-cli has made some modifications to the PHP source code to meet the needs of static compilation.
|
||||
The patches currently used by static-php-cli during compilation in the [patch list](https://github.com/easysoft/phpmicro/tree/master/patches) are:
|
||||
|
||||
- static_opcache
|
||||
- static_extensions_win32
|
||||
- cli_checks
|
||||
- disable_huge_page
|
||||
- vcruntime140
|
||||
- win32
|
||||
- zend_stream
|
||||
- cli_static
|
||||
- macos_iconv
|
||||
- phar
|
||||
|
||||
## PHP <= 8.1 libxml patch
|
||||
|
||||
Because PHP only provides security updates for 8.1 and stops updating older versions,
|
||||
static-php-cli applies the libxml compilation patch that has been applied in newer versions of PHP to PHP 8.1 and below.
|
||||
|
||||
## gd extension Windows patch
|
||||
|
||||
Compiling the gd extension under Windows requires major changes to the `config.w32` file.
|
||||
static-php-cli has made some changes to the gd extension to make it easier to compile under Windows.
|
||||
|
||||
## YAML extension Windows patch
|
||||
|
||||
YAML extension needs to modify the `config.w32` file to compile under Windows.
|
||||
static-php-cli has made some modifications to the YAML extension to make it easier to compile under Windows.
|
||||
|
||||
## static-php-cli version information insertion
|
||||
|
||||
When compiling, static-php-cli will insert the static-php-cli version information into the PHP version information for easy identification.
|
||||
|
||||
## Add option to hardcode INI
|
||||
|
||||
When using the `-I` parameter to hardcode INI into static PHP functionality,
|
||||
static-php-cli will modify the PHP source code to insert the hardcoded content.
|
||||
|
||||
## Linux system repair patch
|
||||
|
||||
Some compilation environments may lack some system header files or libraries.
|
||||
static-php-cli will automatically fix these problems during compilation, such as:
|
||||
|
||||
- HAVE_STRLCAT missing problem
|
||||
- HAVE_STRLCPY missing problem
|
||||
|
||||
## Fiber issue fix patch for Windows
|
||||
|
||||
When compiling PHP on Windows, there will be some issues with the Fiber extension.
|
||||
static-php-cli will automatically fix these issues during compilation (modify `config.w32` in php-src).
|
||||
@@ -1,372 +0,0 @@
|
||||
# Source module
|
||||
|
||||
The download source module of static-php-cli is a major module.
|
||||
It includes dependent libraries, external extensions, PHP source code download methods and file decompression methods.
|
||||
The download configuration file mainly involves the `source.json` and `pkg.json` file, which records the download method of all downloadable sources.
|
||||
|
||||
The main commands involved in the download function are `bin/spc download` and `bin/spc extract`.
|
||||
The `download` command is a downloader that downloads sources according to the configuration file,
|
||||
and the `extract` command is an extractor that extract sources from downloaded files.
|
||||
|
||||
Generally speaking, downloading sources may be slow because these sources come from various official websites, GitHub,
|
||||
and other different locations.
|
||||
At the same time, they also occupy a large space, so you can download the sources once and reuse them.
|
||||
|
||||
The configuration file of the downloader is `source.json`, which contains the download methods of all sources.
|
||||
You can add the source download methods you need, or modify the existing source download methods.
|
||||
|
||||
The download configuration structure of each source is as follows.
|
||||
The following is the source download configuration corresponding to the `libevent` extension:
|
||||
|
||||
```json
|
||||
{
|
||||
"libevent": {
|
||||
"type": "ghrel",
|
||||
"repo": "libevent/libevent",
|
||||
"match": "libevent.+\\.tar\\.gz",
|
||||
"provide-pre-built": true,
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The most important field here is `type`. Currently, the types it supports are:
|
||||
|
||||
- `url`: Directly use URL to download, for example: `https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz`.
|
||||
- `pie`: Download PHP extensions from Packagist using the PIE (PHP Installer for Extensions) standard.
|
||||
- `ghrel`: Use the GitHub Release API to download, download the artifacts uploaded from the latest version released by maintainers.
|
||||
- `ghtar`: Use the GitHub Release API to download.
|
||||
Different from `ghrel`, `ghtar` is downloaded from the `source code (tar.gz)` in the latest Release of the project.
|
||||
- `ghtagtar`: Use GitHub Release API to download.
|
||||
Compared with `ghtar`, `ghtagtar` can find the latest one from the `tags` list and download the source code in `tar.gz` format
|
||||
(because some projects only use `tag` release version).
|
||||
- `bitbuckettag`: Download using BitBucket API, basically the same as `ghtagtar`, except this one applies to BitBucket.
|
||||
- `git`: Clone the project directly from a Git address to download sources, applicable to any public Git repository.
|
||||
- `filelist`: Use a crawler to crawl the Web download site that provides file index,
|
||||
and get the latest version of the file name and download it.
|
||||
- `custom`: If none of the above download methods are satisfactory, you can write `custom`,
|
||||
create a new class under `src/SPC/store/source/`, extends `CustomSourceBase`, and write the download script yourself.
|
||||
|
||||
## source.json Common parameters
|
||||
|
||||
Each source file in source.json has the following params:
|
||||
|
||||
- `license`: the open source license of the source code, see **Open Source License** section below
|
||||
- `type`: must be one of the types mentioned above
|
||||
- `path` (optional): release the source code to the specified directory instead of `source/{name}`
|
||||
- `provide-pre-built` (optional): whether to provide precompiled binary files.
|
||||
If `true`, it will automatically try to download precompiled binary files when running `bin/spc download`
|
||||
|
||||
::: tip
|
||||
The `path` parameter in `source.json` can specify a relative or absolute path. When specified as a relative path, the path is based on `source/`.
|
||||
:::
|
||||
|
||||
## Download type - url
|
||||
|
||||
URL type sources refer to downloading files directly from the URL.
|
||||
|
||||
The parameters included are:
|
||||
|
||||
- `url`: The download address of the file, such as `https://example.com/file.tgz`
|
||||
- `filename` (optional): The file name saved to the local area. If not specified, the file name of the url will be used.
|
||||
|
||||
Example (download the imagick extension and extract it to the extension storage path of the php source code):
|
||||
|
||||
```json
|
||||
{
|
||||
"ext-imagick": {
|
||||
"type": "url",
|
||||
"url": "https://pecl.php.net/get/imagick",
|
||||
"path": "php-src/ext/imagick",
|
||||
"filename": "imagick.tgz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Download type - pie
|
||||
|
||||
PIE (PHP Installer for Extensions) type sources refer to downloading PHP extensions from Packagist that follow the PIE standard.
|
||||
This method automatically fetches extension information from the Packagist repository and downloads the appropriate distribution file.
|
||||
|
||||
The parameters included are:
|
||||
|
||||
- `repo`: The Packagist vendor/package name, such as `vendor/package-name`
|
||||
|
||||
Example (download a PHP extension from Packagist using PIE):
|
||||
|
||||
```json
|
||||
{
|
||||
"ext-example": {
|
||||
"type": "pie",
|
||||
"repo": "vendor/example-extension",
|
||||
"path": "php-src/ext/example",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
::: tip
|
||||
The PIE download type will automatically detect the extension information from Packagist metadata,
|
||||
including the download URL, version, and distribution type.
|
||||
The extension must be marked as `type: php-ext` or contain `php-ext` metadata in its Packagist package definition.
|
||||
:::
|
||||
|
||||
## Download type - ghrel
|
||||
|
||||
ghrel will download files from Assets uploaded in GitHub Release.
|
||||
First use the GitHub Release API to get the latest version, and then download the corresponding files according to the regular matching method.
|
||||
|
||||
The parameters included are:
|
||||
|
||||
- `repo`: GitHub repository name
|
||||
- `match`: regular expression matching Assets files
|
||||
- `prefer-stable`: Whether to download stable versions first (default is `false`)
|
||||
|
||||
Example (download the libsodium library, matching the libsodium-x.y.tar.gz file in Release):
|
||||
|
||||
```json
|
||||
{
|
||||
"libsodium": {
|
||||
"type": "ghrel",
|
||||
"repo": "jedisct1/libsodium",
|
||||
"match": "libsodium-\\d+(\\.\\d+)*\\.tar\\.gz",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Download type - ghtar
|
||||
|
||||
ghtar will download the file from the GitHub Release Tag.
|
||||
Unlike `ghrel`, `ghtar` will download the `source code (tar.gz)` from the latest Release of the project.
|
||||
|
||||
The parameters included are:
|
||||
|
||||
- `repo`: GitHub repository name
|
||||
- `prefer-stable`: Whether to download stable versions first (default is `false`)
|
||||
|
||||
Example (brotli library):
|
||||
|
||||
```json
|
||||
{
|
||||
"brotli": {
|
||||
"type": "ghtar",
|
||||
"repo": "google/brotli",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Download type - ghtagtar
|
||||
|
||||
Use the GitHub Release API to download.
|
||||
Compared with `ghtar`, `ghtagtar` can find the latest one from the `tags` list and download the source code in `tar.gz` format
|
||||
(because some projects only use the `tag` version).
|
||||
|
||||
The parameters included are:
|
||||
|
||||
- `repo`: GitHub repository name
|
||||
- `prefer-stable`: Whether to download stable versions first (default is `false`)
|
||||
|
||||
Example (gmp library):
|
||||
|
||||
```json
|
||||
{
|
||||
"gmp": {
|
||||
"type": "ghtagtar",
|
||||
"repo": "alisw/GMP",
|
||||
"license": {
|
||||
"type": "text",
|
||||
"text": "EXAMPLE LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Download Type - bitbuckettag
|
||||
|
||||
Download using BitBucket API, basically the same as `ghtagtar`, except this one works with BitBucket.
|
||||
|
||||
The parameters included are:
|
||||
|
||||
- `repo`: BitBucket repository name
|
||||
|
||||
## Download type - git
|
||||
|
||||
Clone the project directly from a Git address to download sources, applicable to any public Git repository.
|
||||
|
||||
The parameters included are:
|
||||
|
||||
- `url`: Git link (HTTPS only)
|
||||
- `rev`: branch name
|
||||
|
||||
```json
|
||||
{
|
||||
"imap": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/static-php/imap.git",
|
||||
"rev": "master",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Download type - filelist
|
||||
|
||||
Use a crawler to crawl a web download site that provides a file index and get the latest version of the file name and download it.
|
||||
|
||||
Note that this method is only applicable to static sites with page index functions such as mirror sites and GNU official websites.
|
||||
|
||||
The parameters included are:
|
||||
|
||||
- `url`: The URL of the page to crawl the latest version of the file
|
||||
- `regex`: regular expression matching file names and download links
|
||||
|
||||
Example (download the libiconv library from the GNU official website):
|
||||
|
||||
```json
|
||||
{
|
||||
"libiconv": {
|
||||
"type": "filelist",
|
||||
"url": "https://ftp.gnu.org/gnu/libiconv/",
|
||||
"regex": "/href=\"(?<file>libiconv-(?<version>[^\"]+)\\.tar\\.gz)\"/",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "COPYING"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Download type - custom
|
||||
|
||||
If the above downloading methods are not satisfactory, you can write `custom`,
|
||||
create a new class under `src/SPC/store/source/`, extends `CustomSourceBase`, and write the download script yourself.
|
||||
|
||||
I won’t go into details here, you can look at `src/SPC/store/source/PhpSource.php` or `src/SPC/store/source/PostgreSQLSource.php` as examples.
|
||||
|
||||
## pkg.json General parameters
|
||||
|
||||
pkg.json stores non-source-code files, such as precompiled tools musl-toolchain and UPX. It includes:
|
||||
|
||||
- `type`: The same type as `source.json` and different kinds of parameters.
|
||||
- `extract` (optional): The path to decompress after downloading, the default is `pkgroot/{pkg_name}`.
|
||||
- `extract-files` (optional): Extract only the specified files to the specified location after downloading.
|
||||
|
||||
It should be noted that `pkg.json` does not involve compilation, modification and distribution of source code,
|
||||
so there is no `license` open source license field.
|
||||
And you cannot use the `extract` and `extract-files` parameters at the same time.
|
||||
|
||||
Example (download nasm locally and extract only program files to PHP SDK):
|
||||
|
||||
```json
|
||||
{
|
||||
"nasm-x86_64-win": {
|
||||
"type": "url",
|
||||
"url": "https://www.nasm.us/pub/nasm/releasebuilds/2.16.01/win64/nasm-2.16.01-win64.zip",
|
||||
"extract-files": {
|
||||
"nasm-2.16.01/nasm.exe": "{php_sdk_path}/bin/nasm.exe",
|
||||
"nasm-2.16.01/ndisasm.exe": "{php_sdk_path}/bin/ndisasm.exe"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
The key name in `extract-files` is the file in the source folder, and the key value is the storage path. The storage path can use the following variables:
|
||||
|
||||
- `{php_sdk_path}`: (Windows only) PHP SDK path
|
||||
- `{pkg_root_path}`: `pkgroot/`
|
||||
- `{working_dir}`: current working directory
|
||||
- `{download_path}`: download directory
|
||||
- `{source_path}`: source code decompression directory
|
||||
|
||||
When `extract-files` does not use variables and is a relative path, the directory of the relative path is `{working_dir}`.
|
||||
|
||||
## Open source license
|
||||
|
||||
For `source.json`, each source file should contain an open source license.
|
||||
The `license` field stores the open source license information.
|
||||
|
||||
Each `license` contains the following parameters:
|
||||
|
||||
- `type`: `file` or `text`
|
||||
- `path`: the license file in the source code directory (required when `type` is `file`)
|
||||
- `text`: License text (required when `type` is `text`)
|
||||
|
||||
Example (yaml extension source code with LICENSE file):
|
||||
|
||||
```json
|
||||
{
|
||||
"yaml": {
|
||||
"type": "git",
|
||||
"path": "php-src/ext/yaml",
|
||||
"rev": "php7",
|
||||
"url": "https://github.com/php/pecl-file_formats-yaml",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When an open source project has multiple licenses, multiple files can be specified:
|
||||
|
||||
```json
|
||||
{
|
||||
"libuv": {
|
||||
"type": "ghtar",
|
||||
"repo": "libuv/libuv",
|
||||
"license": [
|
||||
{
|
||||
"type": "file",
|
||||
"path": "LICENSE"
|
||||
},
|
||||
{
|
||||
"type": "file",
|
||||
"path": "LICENSE-extra"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When the license of an open source project uses different files between versions,
|
||||
`path` can be used as an array to list the possible license files:
|
||||
|
||||
```json
|
||||
{
|
||||
"redis": {
|
||||
"type": "git",
|
||||
"path": "php-src/ext/redis",
|
||||
"rev": "release/6.0.2",
|
||||
"url": "https://github.com/phpredis/phpredis",
|
||||
"license": {
|
||||
"type": "file",
|
||||
"path": [
|
||||
"LICENSE",
|
||||
"COPYING"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1,180 +0,0 @@
|
||||
# Introduction to project structure
|
||||
|
||||
static-php-cli mainly contains three logical components: sources, dependent libraries, and extensions.
|
||||
These components contains 4 configuration files: `source.json`, `pkg.json`, `lib.json`, and `ext.json`.
|
||||
|
||||
A complete process for building standalone static PHP is:
|
||||
|
||||
1. Use the source download module `Downloader` to download specified or all source codes.
|
||||
These sources include PHP source code, dependent library source code, and extension source code.
|
||||
2. Use the source decompression module `SourceExtractor` to decompress the downloaded sources to the compilation directory.
|
||||
3. Use the dependency tool to calculate the dependent extensions and dependent libraries of the currently added extension,
|
||||
and then compile each library that needs to be compiled in the order of dependencies.
|
||||
4. After building each dependent library using `Builder` under the corresponding operating system, install it to the `buildroot` directory.
|
||||
5. If external extensions are included (the source code does not contain extensions within PHP),
|
||||
copy the external extensions to the `source/php-src/ext/` directory.
|
||||
6. Use `Builder` to build the PHP source code and build target to the `buildroot` directory.
|
||||
|
||||
The project is mainly divided into several folders:
|
||||
|
||||
- `bin/`: used to store program entry files, including `bin/spc`, `bin/spc-alpine-docker`, `bin/setup-runtime`.
|
||||
- `config/`: Contains all the extensions and dependent libraries supported by the project,
|
||||
as well as the download link and download methods of these sources. It is divided into files: `lib.json`, `ext.json`, `source.json`, `pkg.json`, `pre-built.json` .
|
||||
- `src/`: The core code of the project, including the entire framework and commands for compiling various extensions and libraries.
|
||||
- `vendor/`: The directory that Composer depends on, you do not need to make any modifications to it.
|
||||
|
||||
The operating principle is to start a `ConsoleApplication` of `symfony/console`, and then parse the commands entered by the user in the terminal.
|
||||
|
||||
## Basic command line structure
|
||||
|
||||
`bin/spc` is an entry file, including the Unix common `#!/usr/bin/env php`,
|
||||
which is used to allow the system to automatically execute with the PHP interpreter installed on the system.
|
||||
After the project executes `new ConsoleApplication()`, the framework will automatically register them as commands.
|
||||
|
||||
The project does not directly use the Command registration method and command execution method recommended by Symfony. Here are small changes:
|
||||
|
||||
1. Each command uses the `#[AsCommand()]` Attribute to register the name and description.
|
||||
2. Abstract `execute()` so that all commands are based on `BaseCommand` (which is based on `Symfony\Component\Console\Command\Command`),
|
||||
and the execution code of each command itself is written in the `handle()` method .
|
||||
3. Added variable `$no_motd` to `BaseCommand`, which is used to display the Figlet greeting when the command is executed.
|
||||
4. `BaseCommand` saves `InputInterface` and `OutputInterface` as member variables. You can use `$this->input` and `$this->output` within the command class.
|
||||
|
||||
## Basic source code structure
|
||||
|
||||
The source code of the project is located in the `src/SPC` directory,
|
||||
supports automatic loading of the PSR-4 standard, and contains the following subdirectories and classes:
|
||||
|
||||
- `src/SPC/builder/`: The core compilation command code used to build libraries,
|
||||
PHP and related extensions under different operating systems, and also includes some compilation system tool methods.
|
||||
- `src/SPC/command/`: All commands of the project are here.
|
||||
- `src/SPC/doctor/`: Doctor module, which is a relatively independent module used to check the system environment.
|
||||
It can be entered using the command `bin/spc doctor`.
|
||||
- `src/SPC/exception/`: exception class.
|
||||
- `src/SPC/store/`: Classes related to storage, files and sources are all here.
|
||||
- `src/SPC/util/`: Some reusable tool methods are here.
|
||||
- `src/SPC/ConsoleApplication.php`: command line program entry file.
|
||||
|
||||
If you have read the source code, you may find that there is also a `src/globals/` directory,
|
||||
which is used to store some global variables, global methods,
|
||||
and non-PSR-4 standard PHP source code that is relied upon during the build process, such as extension sanity check code etc.
|
||||
|
||||
## Phar application directory issue
|
||||
|
||||
Like other php-cli projects, spc itself has additional considerations for paths.
|
||||
Because spc can run in multiple modes such as `php-cli directly`, `micro SAPI`, `php-cli with Phar`, `vendor with Phar`, etc.,
|
||||
there are ambiguities in various root directories. A complete explanation is given here.
|
||||
This problem is generally common in the base class path selection problem of accessing files in PHP projects, especially when used with `micro.sfx`.
|
||||
|
||||
Note that this may only be useful for you when developing Phar projects or PHP frameworks.
|
||||
|
||||
> Next, we will treat `static-php-cli` (that is, spc) as a normal `php` command line program. You can understand spc as any of your own php-cli applications for reference.
|
||||
|
||||
There are three basic constant theoretical values below. We recommend that you introduce these three constants when writing PHP projects:
|
||||
|
||||
- `WORKING_DIR`: the working directory when executing PHP scripts
|
||||
|
||||
- `SOURCE_ROOT_DIR` or `ROOT_DIR`: the root directory of the project folder, generally the directory where `composer.json` is located
|
||||
|
||||
- `FRAMEWORK_ROOT_DIR`: the root directory of the framework used, which may be used by self-developed frameworks. Generally, the framework directory is read-only
|
||||
|
||||
You can define these constants in your framework entry or cli applications to facilitate the use of paths in your project.
|
||||
|
||||
The following are PHP built-in constant values, which have been defined inside the PHP interpreter:
|
||||
|
||||
- `__DIR__`: the directory where the file of the currently executed script is located
|
||||
|
||||
- `__FILE__`: the file path of the currently executed script
|
||||
|
||||
### Git project mode (source)
|
||||
|
||||
Git project mode refers to a framework or program itself stored in plain text in the current folder, and running through `php path/to/entry.php`.
|
||||
|
||||
Assume that your project is stored in the `/home/example/static-php-cli/` directory, or your project is the framework itself,
|
||||
which contains project files such as `composer.json`:
|
||||
|
||||
```
|
||||
composer.json
|
||||
src/App/MyCommand.app
|
||||
vendor/*
|
||||
bin/entry.php
|
||||
```
|
||||
|
||||
We assume that the above constants are obtained from `src/App/MyCommand.php`:
|
||||
|
||||
| Constant | Value |
|
||||
|----------------------|------------------------------------------------------|
|
||||
| `WORKING_DIR` | `/home/example/static-php-cli` |
|
||||
| `SOURCE_ROOT_DIR` | `/home/example/static-php-cli` |
|
||||
| `FRAMEWORK_ROOT_DIR` | `/home/example/static-php-cli` |
|
||||
| `__DIR__` | `/home/example/static-php-cli/src/App` |
|
||||
| `__FILE__` | `/home/example/static-php-cli/src/App/MyCommand.php` |
|
||||
|
||||
In this case, the values of `WORKING_DIR`, `SOURCE_ROOT_DIR`, and `FRAMEWORK_ROOT_DIR` are exactly the same: `/home/example/static-php-cli`.
|
||||
|
||||
The source code of the framework and the source code of the application are both in the current path.
|
||||
|
||||
### Vendor library mode (vendor)
|
||||
|
||||
The vendor library mode generally means that your project is a framework or is installed into the project as a composer dependency by other applications,
|
||||
and the storage location is in the `vendor/author/XXX` directory.
|
||||
|
||||
Suppose your project is `crazywhalecc/static-php-cli`, and you or others install this project in another project using `composer require`.
|
||||
|
||||
We assume that static-php-cli contains all files except the `vendor` directory with the same `Git mode`, and get the constant value from `src/App/MyCommand`,
|
||||
Directory constant should be:
|
||||
|
||||
| Constant | Value |
|
||||
|----------------------|--------------------------------------------------------------------------------------|
|
||||
| `WORKING_DIR` | `/home/example/another-app` |
|
||||
| `SOURCE_ROOT_DIR` | `/home/example/another-app` |
|
||||
| `FRAMEWORK_ROOT_DIR` | `/home/example/another-app/vendor/crazywhalecc/static-php-cli` |
|
||||
| `__DIR__` | `/home/example/another-app/vendor/crazywhalecc/static-php-cli/src/App` |
|
||||
| `__FILE__` | `/home/example/another-app/vendor/crazywhalecc/static-php-cli/src/App/MyCommand.php` |
|
||||
|
||||
Here `SOURCE_ROOT_DIR` refers to the root directory of the project using `static-php-cli`.
|
||||
|
||||
### Git project Phar mode (source-phar)
|
||||
|
||||
Git project Phar mode refers to the mode of packaging the project directory of the Git project mode into a `phar` file. We assume that `/home/example/static-php-cli` will be packaged into a Phar file, and the directory has the following files:
|
||||
|
||||
```
|
||||
composer.json
|
||||
src/App/MyCommand.app
|
||||
vendor/*
|
||||
bin/entry.php
|
||||
```
|
||||
|
||||
When packaged into `app.phar` and stored in the `/home/example/static-php-cli` directory, `app.phar` is executed at this time. Assuming that the `src/App/MyCommand` code is executed, the constant is obtained in the file:
|
||||
|
||||
| Constant | Value |
|
||||
|----------------------|----------------------------------------------------------------------|
|
||||
| `WORKING_DIR` | `/home/example/static-php-cli` |
|
||||
| `SOURCE_ROOT_DIR` | `phar:///home/example/static-php-cli/app.phar/` |
|
||||
| `FRAMEWORK_ROOT_DIR` | `phar:///home/example/static-php-cli/app.phar/` |
|
||||
| `__DIR__` | `phar:///home/example/static-php-cli/app.phar/src/App` |
|
||||
| `__FILE__` | `phar:///home/example/static-php-cli/app.phar/src/App/MyCommand.php` |
|
||||
|
||||
Because the `phar://` protocol is required to read files in the phar itself, the project root directory and the framework directory will be different from `WORKING_DIR`.
|
||||
|
||||
### Vendor Library Phar Mode (vendor-phar)
|
||||
|
||||
Vendor Library Phar Mode means that your project is installed as a framework in other projects and stored in the `vendor` directory.
|
||||
|
||||
We assume that your project directory structure is as follows:
|
||||
|
||||
```
|
||||
composer.json # Composer configuration file of the current project
|
||||
box.json # Configuration file for packaging Phar
|
||||
another-app.php # Entry file of another project
|
||||
vendor/crazywhalecc/static-php-cli/* # Your project is used as a dependent library
|
||||
```
|
||||
|
||||
When packaging these files under the directory `/home/example/another-app/` into `app.phar`, the value of the following constant for your project should be:
|
||||
|
||||
| Constant | Value |
|
||||
|----------------------|------------------------------------------------------------------------------------------------------|
|
||||
| `WORKING_DIR` | `/home/example/another-app` |
|
||||
| `SOURCE_ROOT_DIR` | `phar:///home/example/another-app/app.phar/` |
|
||||
| `FRAMEWORK_ROOT_DIR` | `phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli` |
|
||||
| `__DIR__` | `phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli/src/App` |
|
||||
| `__FILE__` | `phar:///home/example/another-app/app.phar/vendor/crazywhalecc/static-php-cli/src/App/MyCommand.php` |
|
||||
@@ -1,242 +0,0 @@
|
||||
# Compilation Tools
|
||||
|
||||
static-php-cli uses many system compilation tools when building static PHP. These tools mainly include:
|
||||
|
||||
- `autoconf`: used to generate `configure` scripts.
|
||||
- `make`: used to execute `Makefile`.
|
||||
- `cmake`: used to execute `CMakeLists.txt`.
|
||||
- `pkg-config`: Used to find the installation path of dependent libraries.
|
||||
- `gcc`: used to compile C/C++ projects under Linux.
|
||||
- `clang`: used to compile C/C++ projects under macOS.
|
||||
|
||||
For Linux and macOS operating systems,
|
||||
these tools can usually be installed through the package manager, which is written in the doctor module.
|
||||
Theoretically we can also compile and download these tools manually,
|
||||
but this will increase the complexity of compilation, so we do not recommend this.
|
||||
|
||||
## Linux Compilation Tools
|
||||
|
||||
For Linux systems, different distributions have different installation methods for compilation tools.
|
||||
And for static compilation, the package management of some distributions cannot install libraries and tools for pure static compilation.
|
||||
Therefore, for the Linux platform and its different distributions,
|
||||
we currently provide a variety of compilation environment preparations.
|
||||
|
||||
### Glibc Environment
|
||||
|
||||
The glibc environment refers to the underlying `libc` library of the system
|
||||
(that is, the C standard library that all programs written in C language are dynamically linked to) uses `glibc`,
|
||||
which is the default environment for most distributions.
|
||||
For example: Ubuntu, Debian, CentOS, RHEL, openSUSE, Arch Linux, etc.
|
||||
|
||||
In the glibc environment, the package management and compiler we use point to glibc by default,
|
||||
and glibc cannot be statically linked well.
|
||||
One of the reasons it cannot be statically linked is that its network library `nss` cannot be compiled statically.
|
||||
|
||||
For the glibc environment, in static-php-cli and spc in 2.0-RC8 and later, you can choose two ways to build static PHP:
|
||||
|
||||
1. Use Docker to build, you can use `bin/spc-alpine-docker` to build, it will build an Alpine Linux docker image.
|
||||
2. Use `bin/spc doctor --auto-fix` to install the `musl-wrapper` and `musl-cross-make` packages, and then build directly.
|
||||
([Related source code](https://github.com/crazywhalecc/static-php-cli/blob/main/src/SPC/doctor/item/LinuxMuslCheck.php))
|
||||
|
||||
Generally speaking, the build results in these two environments are consistent, and you can choose according to actual needs.
|
||||
|
||||
In the doctor module, static-php-cli will first detect the current Linux distribution.
|
||||
If the current distribution is a glibc environment, you will be prompted to install the musl-wrapper and musl-cross-make packages.
|
||||
|
||||
The process of installing `musl-wrapper` in the glibc environment is as follows:
|
||||
|
||||
1. Download the specific version of [musl-wrapper source code](https://musl.libc.org/releases/) from the musl official website.
|
||||
2. Use `gcc` installed from the package management to compile the musl-wrapper source code and generate `musl-libc` and other libraries: `./configure --disable-gcc-wrapper && make -j && sudo make install`.
|
||||
3. The musl-wrapper related libraries will be installed in the `/usr/local/musl` directory.
|
||||
|
||||
The process of installing `musl-cross-make` in the glibc environment is as follows:
|
||||
|
||||
1. Download the precompiled [musl-cross-make](https://dl.static-php.dev/static-php-cli/deps/musl-toolchain/) compressed package from dl.static-php.dev .
|
||||
2. Unzip to the `/usr/local/musl` directory.
|
||||
|
||||
::: tip
|
||||
In the glibc environment, static compilation can be achieved by directly installing musl-wrapper,
|
||||
but musl-wrapper only contains `musl-gcc` and not `musl-g++`, which means that C++ code cannot be compiled.
|
||||
So we need musl-cross-make to provide `musl-g++`.
|
||||
|
||||
The reason why the musl-cross-make package cannot be compiled directly locally is that
|
||||
its compilation environment requirements are relatively high (requires more than 36GB of memory, compiled under Alpine Linux),
|
||||
so we provide precompiled binary packages that can be used for all Linux distributions.
|
||||
|
||||
At the same time, the package management of some distributions provides musl-wrapper,
|
||||
but musl-cross-make needs to match the corresponding musl-wrapper version,
|
||||
so we do not use package management to install musl-wrapper.
|
||||
|
||||
Compiling musl-cross-make will be introduced in the **musl-cross-make Toolchain Compilation** section of this chapter.
|
||||
:::
|
||||
|
||||
### Musl Environment
|
||||
|
||||
The musl environment refers to the system's underlying `libc` library that uses `musl`,
|
||||
which is a lightweight C standard library that can be well statically linked.
|
||||
|
||||
For the currently popular Linux distributions, Alpine Linux uses the musl environment,
|
||||
so static-php-cli can directly build static PHP under Alpine Linux.
|
||||
You only need to install basic compilation tools (such as `gcc`, `cmake`, etc.) directly from the package management.
|
||||
|
||||
For other distributions, if your distribution uses the musl environment,
|
||||
you can also use static-php-cli to build static PHP directly after installing the necessary compilation tools.
|
||||
|
||||
::: tip
|
||||
In the musl environment, static-php-cli will automatically skip the installation of musl-wrapper and musl-cross-make.
|
||||
:::
|
||||
|
||||
### Docker Environment
|
||||
|
||||
The Docker environment refers to using Docker containers to build static PHP. You can use `bin/spc-alpine-docker` to build.
|
||||
Before executing this command, you need to install Docker first, and then execute `bin/spc-alpine-docker` in the project root directory.
|
||||
|
||||
After executing `bin/spc-alpine-docker`, static-php-cli will automatically download the Alpine Linux image and then build a `cwcc-spc-x86_64` or `cwcc-spc-aarch64` image.
|
||||
Then all build process is performed within this image, which is equivalent to compiling in Alpine Linux.
|
||||
|
||||
## musl-cross-make Toolchain Compilation
|
||||
|
||||
In Linux, although you do not need to manually compile the musl-cross-make tool,
|
||||
if you want to understand its compilation process, you can refer here.
|
||||
Another important reason is that this may not be compiled using automated tools such as CI and Actions,
|
||||
because the existing CI service compilation environment does not meet the compilation requirements of musl-cross-make,
|
||||
and the configuration that meets the requirements is too expensive.
|
||||
|
||||
The compilation process of musl-cross-make is as follows:
|
||||
|
||||
Prepare an Alpine Linux environment (either directly installed or using Docker).
|
||||
The compilation process requires more than **36GB** of memory,
|
||||
so you need to compile on a machine with larger memory.
|
||||
Without this much memory, compilation may fail.
|
||||
|
||||
Then write the following content into the `config.mak` file:
|
||||
|
||||
```makefile
|
||||
STAT = -static --static
|
||||
FLAG = -g0 -Os -Wno-error
|
||||
|
||||
ifneq ($(NATIVE),)
|
||||
COMMON_CONFIG += CC="$(HOST)-gcc ${STAT}" CXX="$(HOST)-g++ ${STAT}"
|
||||
else
|
||||
COMMON_CONFIG += CC="gcc ${STAT}" CXX="g++ ${STAT}"
|
||||
endif
|
||||
|
||||
COMMON_CONFIG += CFLAGS="${FLAG}" CXXFLAGS="${FLAG}" LDFLAGS="${STAT}"
|
||||
|
||||
BINUTILS_CONFIG += --enable-gold=yes --enable-gprofng=no
|
||||
GCC_CONFIG += --enable-static-pie --disable-cet --enable-default-pie
|
||||
#--enable-default-pie
|
||||
|
||||
CONFIG_SUB_REV = 888c8e3d5f7b
|
||||
GCC_VER = 13.2.0
|
||||
BINUTILS_VER = 2.40
|
||||
MUSL_VER = 1.2.4
|
||||
GMP_VER = 6.2.1
|
||||
MPC_VER = 1.2.1
|
||||
MPFR_VER = 4.2.0
|
||||
LINUX_VER = 6.1.36
|
||||
```
|
||||
|
||||
And also you need to add `gcc-13.2.0.tar.xz.sha1` file, contents here:
|
||||
|
||||
```
|
||||
5f95b6d042fb37d45c6cbebfc91decfbc4fb493c gcc-13.2.0.tar.xz
|
||||
```
|
||||
|
||||
If you are using Docker to build, create a new `Dockerfile` file and write the following content:
|
||||
|
||||
```dockerfile
|
||||
FROM alpine:edge
|
||||
|
||||
RUN apk add --no-cache \
|
||||
gcc g++ git make curl perl \
|
||||
rsync patch wget libtool \
|
||||
texinfo autoconf automake \
|
||||
bison tar xz bzip2 zlib \
|
||||
file binutils flex \
|
||||
linux-headers libintl \
|
||||
gettext gettext-dev icu-libs pkgconf \
|
||||
pkgconfig icu-dev bash \
|
||||
ccache libarchive-tools zip
|
||||
|
||||
WORKDIR /opt
|
||||
|
||||
RUN git clone https://git.zv.io/toolchains/musl-cross-make.git
|
||||
WORKDIR /opt/musl-cross-make
|
||||
COPY config.mak /opt/musl-cross-make
|
||||
COPY gcc-13.2.0.tar.xz.sha1 /opt/musl-cross-make/hashes
|
||||
|
||||
RUN make TARGET=x86_64-linux-musl -j || :
|
||||
RUN sed -i 's/poison calloc/poison/g' ./gcc-13.2.0/gcc/system.h
|
||||
RUN make TARGET=x86_64-linux-musl -j
|
||||
RUN make TARGET=x86_64-linux-musl install -j
|
||||
RUN tar cvzf x86_64-musl-toolchain.tgz output/*
|
||||
```
|
||||
|
||||
If you are using Alpine Linux in a non-Docker environment, you can directly execute the commands in the Dockerfile, for example:
|
||||
|
||||
```bash
|
||||
apk add --no-cache \
|
||||
gcc g++ git make curl perl \
|
||||
rsync patch wget libtool \
|
||||
texinfo autoconf automake \
|
||||
bison tar xz bzip2 zlib \
|
||||
file binutils flex \
|
||||
linux-headers libintl \
|
||||
gettext gettext-dev icu-libs pkgconf \
|
||||
pkgconfig icu-dev bash \
|
||||
ccache libarchive-tools zip
|
||||
|
||||
git clone https://git.zv.io/toolchains/musl-cross-make.git
|
||||
# Copy config.mak to the working directory of musl-cross-make.
|
||||
# You need to replace /path/to/config.mak with your config.mak file path.
|
||||
cp /path/to/config.mak musl-cross-make/
|
||||
cp /path/to/gcc-13.2.0.tar.xz.sha1 musl-cross-make/hashes
|
||||
|
||||
make TARGET=x86_64-linux-musl -j || :
|
||||
sed -i 's/poison calloc/poison/g' ./gcc-13.2.0/gcc/system.h
|
||||
make TARGET=x86_64-linux-musl -j
|
||||
make TARGET=x86_64-linux-musl install -j
|
||||
tar cvzf x86_64-musl-toolchain.tgz output/*
|
||||
```
|
||||
|
||||
::: tip
|
||||
All the above scripts are suitable for x86_64 architecture Linux.
|
||||
If you need to build musl-cross-make for the ARM environment, just replace all `x86_64` above with `aarch64`.
|
||||
:::
|
||||
|
||||
This compilation process may fail due to insufficient memory, network problems, etc.
|
||||
You can try a few more times, or use a machine with larger memory to compile.
|
||||
If you encounter problems or you have better improvement solutions, go to [Discussion](https://github.com/crazywhalecc/static-php-cli-hosted/issues/1).
|
||||
|
||||
## macOS Environment
|
||||
|
||||
For macOS systems, the main compilation tool we use is `clang`,
|
||||
which is the default compiler for macOS systems and is also the compiler of Xcode.
|
||||
|
||||
Compiling under macOS mainly relies on Xcode or Xcode Command Line Tools.
|
||||
You can download Xcode from the App Store,
|
||||
or execute `xcode-select --install` in the terminal to install Xcode Command Line Tools.
|
||||
|
||||
In addition, in the `doctor` environment check module, static-php-cli will check whether Homebrew,
|
||||
compilation tools, etc. are installed on the macOS system.
|
||||
If not, you will be prompted to install them. I will not go into details here.
|
||||
|
||||
## FreeBSD Environment
|
||||
|
||||
FreeBSD is also a Unix system, and its compilation tools are similar to macOS.
|
||||
You can directly use the package management `pkg` to install `clang` and other compilation tools through the `doctor` command.
|
||||
|
||||
## pkg-config Compilation (*nix only)
|
||||
|
||||
If you observe the compilation log when using static-php-cli to build static PHP, you will find that no matter what is compiled,
|
||||
`pkg-config` will be compiled first. This is because `pkg-config` is a library used to find dependencies.
|
||||
In earlier versions of static-php-cli, we directly used the `pkg-config` tool installed by package management,
|
||||
but this would cause some problems, such as:
|
||||
|
||||
- Even if `PKG_CONFIG_PATH` is specified, `pkg-config` will try to find dependent packages from the system path.
|
||||
- Since `pkg-config` will look for dependent packages from the system path,
|
||||
if a dependent package with the same name exists in the system, compilation may fail.
|
||||
|
||||
In order to avoid the above problems, we compile `pkg-config` into `buildroot/bin` in user mode and use it.
|
||||
We use parameters such as `--without-sysroot` to avoid looking for dependent packages from the system path.
|
||||
@@ -1,108 +0,0 @@
|
||||
# FAQ
|
||||
|
||||
Here will be some questions that you may encounter easily. There are currently many, but I need to take time to organize them.
|
||||
|
||||
## What is the path of php.ini ?
|
||||
|
||||
On Linux, macOS and FreeBSD, the path of `php.ini` is `/usr/local/etc/php/php.ini`.
|
||||
On Windows, the path is `C:\windows\php.ini` or the current directory of `php.exe`.
|
||||
The directory where to look for `php.ini` can be changed on *nix using the manual build option `--with-config-file-path`.
|
||||
|
||||
In addition, on Linux, macOS and FreeBSD, `.ini` files present in the `/usr/local/etc/php/conf.d` directory will also be loaded.
|
||||
On Windows, this path is empty by default.
|
||||
The directory can be changed using the manual build option `--with-config-file-scan-dir`.
|
||||
|
||||
`php.ini` will also be searched for in [the other standard locations](https://www.php.net/manual/configuration.file.php).
|
||||
|
||||
## Can statically-compiled PHP install extensions?
|
||||
|
||||
Because the principle of installing PHP extensions under the normal mode is to use `.so` type dynamic link library to install new extensions,
|
||||
and we use the static link PHP compiled by this project. However, static linking has different definitions in different operating systems.
|
||||
|
||||
First of all, for Linux systems, statically linked binaries will not link the system's dynamic link library.
|
||||
Purely statically linked binaries (`build with -all-static`) cannot load dynamic libraries, so new extensions cannot be added.
|
||||
At the same time, in pure static mode, you cannot use extensions such as `ffi` to load external `.so` modules.
|
||||
|
||||
You can use the command `ldd buildroot/bin/php` to check whether the binary you built under Linux is purely statically linked.
|
||||
|
||||
If you [build GNU libc based PHP](../guide/build-with-glibc), you can use the `ffi` extension to load external `.so` modules and load `.so` extensions with the same ABI.
|
||||
|
||||
For example, you can use the following command to build a static PHP binary dynamically linked with glibc,
|
||||
supporting FFI extensions and loading the `xdebug.so` extension of the same PHP version and the same TS type:
|
||||
|
||||
```bash
|
||||
bin/spc-gnu-docker download --for-extensions=ffi,xml --with-php=8.4
|
||||
bin/spc-gnu-docker build ffi,xml --build-cli --debug
|
||||
|
||||
buildroot/bin/php -d "zend_extension=/path/to/php{PHP_VER}-{ts/nts}/xdebug.so" --ri xdebug
|
||||
```
|
||||
|
||||
For macOS platform, almost all binaries under macOS cannot be truly purely statically linked, and almost all binaries will link macOS system libraries: `/usr/lib/libresolv.9.dylib` and `/usr/lib/libSystem.B.dylib`.
|
||||
So on macOS, you can **directly** use SPC to build statically compiled PHP binaries with dynamically linked extensions:
|
||||
|
||||
1. Build shared extension `xxx.so` using: `--build-shared=XXX` option. e.g. `bin/spc build bcmath,zlib --build-shared=xdebug --build-cli`
|
||||
2. You will get `buildroot/modules/xdebug.so` and `buildroot/bin/php`.
|
||||
3. The `xdebug.so` file could be used for php that version and thread-safe are the same.
|
||||
|
||||
For the Windows platform, since officially built extensions (such as `php_yaml.dll`) force the use of the `php8.dll` dynamic library as a link, and statically built PHP does not include any dynamic libraries other than system libraries,
|
||||
php.exe built by static-php cannot load officially built dynamic extensions. Since static-php-cli does not yet support building dynamic extensions, there is currently no way to load dynamic extensions with static-php.
|
||||
|
||||
However, Windows can normally use the `FFI` extension to load other dll files and call them.
|
||||
|
||||
## Can it support Oracle database extension?
|
||||
|
||||
Some extensions that rely on closed source libraries, such as `oci8`, `sourceguardian`, etc.,
|
||||
they do not provide purely statically compiled dependent library files (`.a`), only dynamic dependent library files (`.so`).
|
||||
These extensions cannot be compiled into static-php-cli using source code, so this project may never support these extensions.
|
||||
However, in theory you can access and use such extensions under macOS and Linux according to the above questions.
|
||||
|
||||
If you have a need for such extensions, or most people have needs for these closed-source extensions,
|
||||
see the discussion on [standalone-php-cli](https://github.com/crazywhalecc/static-php-cli/discussions/58). Welcome to leave a message.
|
||||
|
||||
## Does it support Windows?
|
||||
|
||||
The project currently supports Windows, but the number of supported extensions is small. Windows support is not perfect. There are mainly the following problems:
|
||||
|
||||
1. The compilation process of Windows is different from that of *nix, and the toolchain used is also different. The compilation tools used to compile the dependent libraries of each extension are almost completely different.
|
||||
2. The demand for the Windows version will also be advanced based on the needs of all people who use this project. If many people need it, I will support related extensions as soon as possible.
|
||||
|
||||
## Can I protect my source code with micro?
|
||||
|
||||
You can't. micro.sfx is essentially combining php and php code into one file,
|
||||
there is no process of compiling or encrypting the PHP code.
|
||||
|
||||
First of all, php-src is the official interpreter of PHP code, and there is no PHP compiler compatible with mainstream branches on the market.
|
||||
I saw on the Internet that there is a project called BPC (Binary PHP Compiler?) that can compile PHP into binary,
|
||||
but there are many restrictions.
|
||||
|
||||
The direction of encrypting and protecting the code is not the same as compiling.
|
||||
After compiling, the code can also be obtained through reverse engineering and other methods.
|
||||
The real protection is still carried out by means of packing and encrypting the code.
|
||||
|
||||
Therefore, this project (static-php-cli) and related projects (lwmbs, swoole-cli) all provide a convenient compilation tool for php-src source code.
|
||||
The phpmicro referenced by this project and related projects is only a package of PHP's sapi interface, not a compilation tool for PHP code.
|
||||
The compiler for PHP code is a completely different project, so the extra cases are not taken into account.
|
||||
If you are interested in encryption, you can consider using existing encryption technologies,
|
||||
such as Swoole Compiler, Source Guardian, etc.
|
||||
|
||||
## Unable to use ssl
|
||||
|
||||
**Update: This issue has been fixed in the latest version of static-php-cli, which now reads the system's certificate file by default. If you still have problems, try the solution below.**
|
||||
|
||||
When using curl, pgsql, etc. to request an HTTPS website or establish an SSL connection, there may be an `error:80000002:system library::No such file or directory` error.
|
||||
This error is caused by statically compiled PHP without specifying `openssl.cafile` via `php.ini`.
|
||||
|
||||
You can solve this problem by specifying `php.ini` before using PHP and adding `openssl.cafile=/path/to/your-cert.pem` in the INI.
|
||||
|
||||
For Linux systems, you can download the [cacert.pem](https://curl.se/docs/caextract.html) file from the curl official website, or you can use the certificate file that comes with the system.
|
||||
For the certificate locations of different distros, please refer to [Golang docs](https://go.dev/src/crypto/x509/root_linux.go).
|
||||
|
||||
> INI configuration `openssl.cafile` cannot be set dynamically using the `ini_set()` function, because `openssl.cafile` is a `PHP_INI_SYSTEM` type configuration and can only be set in the `php.ini` file.
|
||||
|
||||
## Why don't we support older versions of PHP?
|
||||
|
||||
Because older versions of PHP have many problems, such as security issues, performance issues, and functional issues.
|
||||
In addition, many older versions of PHP are not compatible with the latest dependency libraries,
|
||||
which is one of the reasons why older versions of PHP are not supported.
|
||||
|
||||
You can use older versions compiled earlier by static-php-cli, such as PHP 8.0, but earlier versions will not be explicitly supported.
|
||||
@@ -1,31 +0,0 @@
|
||||
# GitHub Action Build
|
||||
|
||||
Action Build refers to compiling directly using GitHub Action.
|
||||
|
||||
If you don't want to compile it yourself, you can download the artifact from the existing Action in this project,
|
||||
or you can download it from a self-hosted server:[Enter](https://dl.static-php.dev/static-php-cli/common/).
|
||||
|
||||
> Self-hosted binaries are also built from Actions: [repo](https://github.com/static-php/static-php-cli-hosted).
|
||||
> The extensions included are: bcmath,bz2,calendar,ctype,curl,dom,exif,fileinfo,filter,ftp,gd,gmp,iconv,xml,mbstring,mbregex,mysqlnd,openssl,
|
||||
> pcntl,pdo,pdo_mysql,pdo_sqlite,phar,posix,redis,session,simplexml,soap,sockets,sqlite3,tokenizer,xmlwriter,xmlreader,zlib,zip
|
||||
|
||||
## Build Guide
|
||||
|
||||
Using GitHub Action makes it easy to build a statically compiled PHP and phpmicro,
|
||||
while also defining the extensions to compile.
|
||||
|
||||
1. Fork project.
|
||||
2. Go to the Actions of the project and select `CI`.
|
||||
3. Select `Run workflow`, fill in the PHP version you want to compile, the target type, and the list of static extensions. (comma separated, e.g. `bcmath,curl,mbstring`)
|
||||
4. If you need shared extensions (for example `xdebug`), set `shared-extensions` (comma separated, e.g. `xdebug`).
|
||||
5. If you need FrankenPHP, enable `build-frankenphp` and also enable `enable-zts`.
|
||||
6. After waiting for about a period of time, enter the corresponding task and get `Artifacts`.
|
||||
|
||||
If you enable `debug`, all logs will be output at build time, including compiled logs, for troubleshooting.
|
||||
|
||||
> If you need to build in other environments, you can use [manual build](./manual-build).
|
||||
|
||||
## Extensions
|
||||
|
||||
You can go to [extensions](./extensions) check here to see if all the extensions you need currently support.
|
||||
and then go to [command generator](./cli-generator) select the extension you need to compile, copy the extensions string to `extensions` option.
|
||||
@@ -1,228 +0,0 @@
|
||||
# Build on Windows
|
||||
|
||||
Because the Windows system is an NT kernel, the compilation tools and operating system interfaces
|
||||
used by Unix-like operating systems are almost completely different,
|
||||
so the build process on Windows will be slightly different from that of Unix systems.
|
||||
|
||||
## GitHub Actions Build
|
||||
|
||||
Building the Windows version of static-php from Actions is now supported.
|
||||
Like Linux and macOS, you need to Fork the static-php-cli repository to your GitHub account first,
|
||||
then you can enter [Extension List](./extensions) to select the extension to be compiled,
|
||||
and then go to your own `CI on Windows` select the PHP version, fill in the extension list (comma separated), and click Run.
|
||||
|
||||
If you're going to develop or build locally, please read on.
|
||||
|
||||
## Requirements
|
||||
|
||||
The tools required to build static PHP on Windows are the same as PHP's official Windows build tools.
|
||||
You can read [Official Documentation](https://wiki.php.net/internals/windows/stepbystepbuild_sdk_2).
|
||||
|
||||
To sum up, you need the following environment and tools:
|
||||
|
||||
- Windows 10/11 (requires build 17063 or later)
|
||||
- Visual Studio 2019/2022 (recommended 2022)
|
||||
- C++ desktop development for Visual Studio
|
||||
- Git for Windows
|
||||
- [php-sdk-binary-tools](https://github.com/php/php-sdk-binary-tools) (can be installed automatically using doctor)
|
||||
- strawberry-perl (can be installed automatically using doctor)
|
||||
- nasm (can be installed automatically using doctor)
|
||||
|
||||
::: tip
|
||||
The construction of static-php-cli on Windows refers to using MSVC to build PHP and is not based on MinGW, Cygwin, WSL and other environments.
|
||||
|
||||
If you prefer to use WSL, please refer to the chapter on Building on Linux.
|
||||
:::
|
||||
|
||||
After installing Visual Studio and selecting the C++ desktop development workload,
|
||||
you may download about 8GB of compilation tools, and the download speed depends on your network conditions.
|
||||
|
||||
### Install Git
|
||||
|
||||
Git for Windows can be downloaded and installed from [here](https://git-scm.com/download/win) `Standalone Installer 64-bit` version,
|
||||
installed in the default location (`C:\Program Files\Git\`).
|
||||
If you don't want to download and install manually,
|
||||
you can also use Visual Studio Installer and check Git in the **Individual component** tab.
|
||||
|
||||
### Prepare static-php-cli
|
||||
|
||||
Downloading the static-php-cli project is very simple, just use git clone.
|
||||
It is recommended to place the project in `C:\spc-build\` or a similar directory.
|
||||
It is best **not to have spaces in the path**.
|
||||
|
||||
```shell
|
||||
mkdir "C:\spc-build"
|
||||
cd C:\spc-build
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git
|
||||
cd static-php-cli
|
||||
```
|
||||
|
||||
It is a bit strange that static-php-cli itself requires a PHP environment,
|
||||
but now you can quickly install the PHP environment through a script.
|
||||
Generally, your computer will not have the Windows version of PHP installed,
|
||||
so we recommend that you use `bin/setup-runtime` directly after downloading static-php-cli to install PHP and Composer in the current directory.
|
||||
|
||||
```shell
|
||||
# Install PHP and Composer to the ./runtime/ directory
|
||||
bin/setup-runtime
|
||||
|
||||
# After installation, if you need to use PHP and Composer in global commands,
|
||||
# use the following command to add the runtime/ directory to PATH
|
||||
bin/setup-runtime -action add-path
|
||||
|
||||
# Delete the runtime/ directory in PATH
|
||||
bin/setup-runtime -action remove-path
|
||||
```
|
||||
|
||||
Finally, now that you have PHP and Composer installed, you need to install static-php-cli's Composer dependencies:
|
||||
|
||||
```shell
|
||||
composer install
|
||||
```
|
||||
|
||||
### Install other Tools (automatic)
|
||||
|
||||
For `php-sdk-binary-tools`, `strawberry-perl`, and `nasm`,
|
||||
we recommend that you directly use the command `bin/spc doctor` to check and install them.
|
||||
|
||||
If doctor successfully installs automatically, please **skip** the steps below to manually install the above tools.
|
||||
|
||||
But if the automatic installation fails, please refer to the manual installation method below.
|
||||
|
||||
### Install php-sdk-binary-tools (manual)
|
||||
|
||||
```shell
|
||||
cd C:\spc-build\static-php-cli
|
||||
git clone https://github.com/php/php-sdk-binary-tools.git
|
||||
```
|
||||
|
||||
> You can also set the global variable `PHP_SDK_PATH` in Windows settings and
|
||||
> clone the project to the path corresponding to the variable.
|
||||
> Under normal circumstances, you don't need to change it.
|
||||
|
||||
### Install strawberry-perl (manual)
|
||||
|
||||
> If you don't need to compile the openssl extension, you don't need to install perl.
|
||||
|
||||
1. Download the latest version of strawberry-perl from [GitHub](https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/).
|
||||
2. Install to the `C:\spc-build\static-php-cli\pkgroot\perl\` directory.
|
||||
|
||||
> You can download the `-portable` version and extract it directly to the above directory.
|
||||
> The last `perl.exe` should be located at `C:\spc-build\static-php-cli\pkgroot\perl\perl\bin\perl.exe`.
|
||||
|
||||
### Install nasm (manual)
|
||||
|
||||
> If you don't need to compile openssl extension, you don't need to install nasm.
|
||||
|
||||
1. Download the nasm tool (x64) from [official website](https://www.nasm.us/pub/nasm/releasebuilds/).
|
||||
2. Place `nasm.exe` and `ndisasm.exe` in the `C:\spc-build\static-php-cli\php-sdk-binary-tools\bin\` directory.
|
||||
|
||||
## Download required sources
|
||||
|
||||
Same as [Manual build - Download](./manual-build.html#command-download)
|
||||
|
||||
## Build PHP
|
||||
|
||||
Use the build command to start building the static php binary.
|
||||
Before executing the `bin/spc build` command, be sure to use the `download` command to download sources.
|
||||
It is recommended to use `doctor` to check the environment.
|
||||
|
||||
### Build SAPI
|
||||
|
||||
You need to go to [Extension List](./extensions) or [Command Generator](./cli-generator) to select the extension you want to add,
|
||||
and then use the command `bin/spc build` to compile.
|
||||
You need to specify targets, choose from the following parameters (at least one):
|
||||
|
||||
- `--build-cli`: Build a cli sapi (command line interface, which can execute PHP code on the command line)
|
||||
- `--build-micro`: Build a micro sapi (used to build a standalone executable binary containing PHP code)
|
||||
|
||||
```shell
|
||||
# Compile PHP with bcmath,openssl,zlib extensions, the compilation target is cli
|
||||
bin/spc build "bcmath,openssl,zlib" --build-cli
|
||||
|
||||
# Compile PHP with phar,curl,posix,pcntl,tokenizer extensions, compile target is micro and cli
|
||||
bin/spc build "bcmath,openssl,zlib" --build-micro --build-cli
|
||||
```
|
||||
|
||||
::: warning
|
||||
In Windows, it is best to use double quotes to wrap parameters containing commas, such as `"bcmath,openssl,mbstring"`.
|
||||
:::
|
||||
|
||||
### Debug
|
||||
|
||||
If you encounter problems during the compilation process, or want to view each executing shell command,
|
||||
you can use `--debug` to enable debug mode and view all terminal logs:
|
||||
|
||||
```shell
|
||||
bin/spc build "openssl" --build-cli --debug
|
||||
```
|
||||
|
||||
### Build Options
|
||||
|
||||
During the compilation process, in some special cases,
|
||||
the compiler and the content of the compilation directory need to be intervened.
|
||||
You can try to use the following commands:
|
||||
|
||||
- `--with-clean`: clean up old make files before compiling PHP
|
||||
- `--enable-zts`: Make compiled PHP thread-safe version (default is NTS version)
|
||||
- `--with-libs=XXX,YYY`: Compile the specified dependent library before compiling PHP, and activate some extension optional functions
|
||||
- `--with-config-file-scan-dir=XXX`: Set the directory to scan for `.ini` files after reading `php.ini` (Check [here](../faq/index.html#what-is-the-path-of-php-ini) for default paths)
|
||||
- `-I xxx=yyy`: Hard compile INI options into PHP before compiling (support multiple options, alias is `--with-hardcoded-ini`)
|
||||
- `--with-micro-fake-cli`: When compiling micro, let micro's `PHP_SAPI` pretend to be `cli` (for compatibility with some programs that check `PHP_SAPI`)
|
||||
- `--disable-opcache-jit`: Disable opcache jit (enabled by default)
|
||||
- `--without-micro-ext-test`: After building micro.sfx, do not test the running results of different extensions in micro.sfx
|
||||
- `--with-suggested-exts`: Add `ext-suggests` as dependencies when compiling
|
||||
- `--with-suggested-libs`: Add `lib-suggests` as dependencies when compiling
|
||||
- `--with-upx-pack`: Use UPX to reduce the size of the binary file after compilation (you need to use `bin/spc install-pkg upx` to install upx first)
|
||||
- `--with-micro-logo=XXX.ico`: Customize the icon of the `exe` executable file after customizing the micro build (in the format of `.ico`)
|
||||
|
||||
Here is a simple example where we preset a larger `memory_limit` and disable the `system` function:
|
||||
|
||||
```shell
|
||||
bin/spc build "bcmath,openssl" --build-cli -I "memory_limit=4G" -I "disable_functions=system"
|
||||
```
|
||||
|
||||
Another example: Customize our hello-world.exe program logo:
|
||||
|
||||
```shell
|
||||
bin/spc build "ffi,bcmath" --build-micro --with-micro-logo=mylogo.ico --debug
|
||||
bin/spc micro:combine hello.php
|
||||
# Then we got `my-app.exe` with custom logo!
|
||||
my-app.exe
|
||||
```
|
||||
|
||||
## Use php.exe
|
||||
|
||||
After php.exe is compiled, it is located in the `buildroot\bin\` directory. You can copy it to any location for use.
|
||||
|
||||
```shell
|
||||
.\php -v
|
||||
```
|
||||
|
||||
## Use micro.sfx
|
||||
|
||||
> phpmicro is a SelF-extracted eXecutable SAPI module,
|
||||
> provided by [phpmicro](https://github.com/dixyes/phpmicro) project.
|
||||
> But this project is using a [fork](https://github.com/static-php/phpmicro) of phpmicro, because we need to add some features to it.
|
||||
> It can put php runtime and your source code together.
|
||||
|
||||
The final compilation result will output a file named `./micro.sfx`,
|
||||
which needs to be used with your PHP source code like `code.php`.
|
||||
This file will be located in the path `buildroot/bin/micro.sfx`.
|
||||
|
||||
Prepare your project source code, which can be a single PHP file or a Phar file, for use.
|
||||
|
||||
> If you want to combine phar files, you must add `phar` extension when compiling!
|
||||
|
||||
```shell
|
||||
# code.php "<?php echo 'Hello world' . PHP_EOL;"
|
||||
bin/spc micro:combine code.php -O my-app.exe
|
||||
# Run it!!! Copy it to another computer!!!
|
||||
./my-app.exe
|
||||
```
|
||||
|
||||
If you package a PHAR file, just replace `code.php` with the phar file path.
|
||||
You can use [box-project/box](https://github.com/box-project/box) to package your CLI project as Phar,
|
||||
It is then combined with phpmicro to produce a standalone executable binary.
|
||||
|
||||
For more details on the `micro:combine` command, refer to [command](./manual-build) on Unix systems.
|
||||
@@ -1,64 +0,0 @@
|
||||
# Build glibc Compatible Linux Binary
|
||||
|
||||
## Why Build glibc Compatible Binary
|
||||
|
||||
Currently, the binaries built by static-php-cli on Linux by default are based on musl-libc (statically linked).
|
||||
musl-libc is a lightweight libc implementation
|
||||
that aims to be compatible with glibc and provides good support for pure static linking.
|
||||
This means that the compiled static PHP executable can be used on almost any Linux distribution without worrying about the versions of libc, libstdc++, etc.
|
||||
|
||||
However, there are some issues with pure static linking of musl-libc binaries on Linux:
|
||||
|
||||
- The `dl()` function in PHP cannot be used to load dynamic libraries and external PHP extensions.
|
||||
- The FFI extension in PHP cannot be used.
|
||||
- In some extreme cases, performance issues may occur. See [musl-libc performance issues](https://github.com/php/php-src/issues/13648).
|
||||
|
||||
Different Linux distributions use different default libc.
|
||||
For example, Alpine Linux uses musl libc, while most Linux distributions use glibc.
|
||||
However, even so, we cannot directly use any distribution using glibc to build portable static binaries because glibc has some issues:
|
||||
|
||||
- Binaries built with gcc and other tools on newer versions of distributions cannot run on older versions of distributions.
|
||||
- glibc is not recommended to be statically linked because some of its features require the support of dynamic libraries.
|
||||
|
||||
However, we can use Docker to solve this problem.
|
||||
The final output is a binary **dynamically linked with glibc** and some necessary libraries,
|
||||
but **statically linked with all other dependencies**.
|
||||
|
||||
1. Use an older version of a Linux distribution (such as CentOS 7.x), which has an older version of glibc but can run on most modern Linux distributions.
|
||||
2. Build the static binary of PHP in this container so that it can run on most modern Linux distributions.
|
||||
|
||||
> Using glibc static binaries can run on most modern Linux distributions but cannot run on musl libc distributions, such as CentOS 6, Alpine Linux, etc.
|
||||
|
||||
## Build glibc Compatible Linux Binary
|
||||
|
||||
The latest version of static-php-cli includes the `bin/spc-gnu-docker` script,
|
||||
which can create a CentOS 7.x (glibc-2.17) Docker container with one click and build a glibc compatible PHP static binary in the container.
|
||||
|
||||
Then, run the following command once.
|
||||
The first run will take a long time because it needs to download the CentOS 7.x image and some build tools.
|
||||
|
||||
```bash
|
||||
bin/spc-gnu-docker
|
||||
```
|
||||
|
||||
After the image is built, you will see the same command help menu as `bin/spc`, which means the container is ready.
|
||||
|
||||
After the container is ready, you can refer to the [local build](./manual-build) section to build your PHP static binary.
|
||||
Just replace `bin/spc` or `./spc` with `bin/spc-gnu-docker`.
|
||||
|
||||
```bash
|
||||
bin/spc-gnu-docker build bcmath,ctype,openssl,pdo,phar,posix,session,tokenizer,xml,zip --build-cli --debug
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
In rare cases, glibc-based static PHP may encounter segment faults and other errors, but there are currently few examples.
|
||||
If you encounter any issues, please submit an issue.
|
||||
|
||||
glibc build is an extended feature and is not part of the default static-php support.
|
||||
If you have related issues or requirements, please indicate that you are building based on glibc when submitting an issue.
|
||||
|
||||
If you need to build glibc-based binaries without using Docker,
|
||||
please refer to the `bin/spc-gnu-docker` script to manually create a similar environment.
|
||||
|
||||
Please keep in mind that we only support glibc build with `bin/spc-gnu-docker`. Compilation on RHEL 9 & 10 has been tested and is stable, but if you run into issues, we may choose not to fix them.
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
aside: false
|
||||
---
|
||||
|
||||
<script setup lang="ts">
|
||||
import CliGenerator from "../../.vitepress/components/CliGenerator.vue";
|
||||
</script>
|
||||
|
||||
# CLI Build Command Generator
|
||||
|
||||
::: tip
|
||||
The extensions selected below may contain extensions that are not supported by the selected operating system,
|
||||
which may cause compilation to fail. Please check [Supported Extensions](./extensions) first.
|
||||
:::
|
||||
|
||||
<cli-generator lang="en" />
|
||||
@@ -1,26 +0,0 @@
|
||||
---
|
||||
outline: 'deep'
|
||||
---
|
||||
|
||||
# Dependency Table
|
||||
|
||||
When compiling PHP, each extension and library has dependencies, which may be required or optional.
|
||||
You can choose whether to include these optional dependencies.
|
||||
|
||||
For example, when compiling the `gd` extension under Linux,
|
||||
the `zlib,libpng` libraries and the `zlib` extension are forced to be compiled,
|
||||
while the `libavif,libwebp,libjpeg,freetype` libraries are optional libraries and will not be compiled by default
|
||||
unless specified by the `--with-libs=avif,webp,jpeg,freetype` option.
|
||||
|
||||
- For optional extensions (optional features of extensions), you need to specify them manually at compile time, for example, to enable igbinary support for Redis: `bin/spc build redis,igbinary`.
|
||||
- For optional libraries, you need to compile and specify them through the `--with-libs=XXX` option.
|
||||
- If you want to enable all optional extensions, you can use `bin/spc build redis --with-suggested-exts`.
|
||||
- If you want to enable all optional libraries, you can use `--with-suggested-libs`.
|
||||
|
||||
## Extension Dependency Table
|
||||
|
||||
<!--@include: ../../deps-map-ext.md-->
|
||||
|
||||
## Library Dependency Table
|
||||
|
||||
<!--@include: ../../deps-map-lib.md-->
|
||||
@@ -1,121 +0,0 @@
|
||||
# Environment variables
|
||||
|
||||
All environment variables mentioned in the list on this page have default values unless otherwise noted.
|
||||
You can override the default values by setting these environment variables.
|
||||
|
||||
## Environment variables list
|
||||
|
||||
Starting from version 2.3.5, we have centralized the environment variables in the `config/env.ini` file.
|
||||
You can set environment variables by modifying this file.
|
||||
|
||||
We divide the environment variables supported by static-php-cli into three types:
|
||||
|
||||
- Global internal environment variables: declared after static-php-cli starts, you can use `getenv()` to get them internally in static-php-cli, and you can override them before starting static-php-cli.
|
||||
- Fixed environment variables: declared after static-php-cli starts, you can only use `getenv()` to get them, but you cannot override them through shell scripts.
|
||||
- Config file environment variables: declared before static-php-cli build, you can set these environment variables by modifying the `config/env.ini` file or through shell scripts.
|
||||
|
||||
You can read the comments for each parameter in [config/env.ini](https://github.com/crazywhalecc/static-php-cli/blob/main/config/env.ini) to understand its purpose.
|
||||
|
||||
## Custom environment variables
|
||||
|
||||
Generally, you don't need to modify any of the following environment variables as they are already set to optimal values.
|
||||
However, if you have special needs, you can set these environment variables to meet your needs
|
||||
(for example, you need to debug PHP performance under different compilation parameters).
|
||||
|
||||
If you want to use custom environment variables, you can use the `export` command in the terminal or set the environment variables directly before the command, for example:
|
||||
|
||||
```shell
|
||||
# export first
|
||||
export SPC_CONCURRENCY=4
|
||||
bin/spc build mbstring,pcntl --build-cli
|
||||
|
||||
# or direct use
|
||||
SPC_CONCURRENCY=4 bin/spc build mbstring,pcntl --build-cli
|
||||
```
|
||||
|
||||
Or, if you need to modify an environment variable for a long time, you can modify the `config/env.ini` file.
|
||||
|
||||
`config/env.ini` is divided into three sections, `[global]` is globally effective, `[windows]`, `[macos]`, `[linux]` are only effective for the corresponding operating system.
|
||||
|
||||
For example, if you need to modify the `./configure` command for compiling PHP, you can find the `SPC_CMD_PREFIX_PHP_CONFIGURE` environment variable in the `config/env.ini` file, and then modify its value.
|
||||
|
||||
If your build conditions are more complex and require multiple `env.ini` files to switch,
|
||||
we recommend that you use the `config/env.custom.ini` file.
|
||||
In this way, you can specify your environment variables by writing additional override items
|
||||
without modifying the default `config/env.ini` file.
|
||||
|
||||
```ini
|
||||
; This is an example of `config/env.custom.ini` file,
|
||||
; we modify the `SPC_CONCURRENCY` and linux default CFLAGS passing to libs and PHP
|
||||
[global]
|
||||
SPC_CONCURRENCY=4
|
||||
|
||||
[linux]
|
||||
SPC_DEFAULT_C_FLAGS="-O3"
|
||||
```
|
||||
|
||||
## Library environment variables (Unix only)
|
||||
|
||||
Starting from 2.2.0, static-php-cli supports custom environment variables for all compilation dependent library commands of macOS, Linux, FreeBSD and other Unix systems.
|
||||
|
||||
In this way, you can adjust the behavior of compiling dependent libraries through environment variables at any time.
|
||||
For example, you can set the optimization parameters for compiling the xxx library through `xxx_CFLAGS=-O0`.
|
||||
|
||||
Of course, not every library supports the injection of environment variables.
|
||||
We currently provide three wildcard environment variables with the suffixes:
|
||||
|
||||
- `_CFLAGS`: CFLAGS for the compiler
|
||||
- `_LDFLAGS`: LDFLAGS for the linker
|
||||
- `_LIBS`: LIBS for the linker
|
||||
|
||||
The prefix is the name of the dependent library, and the specific name of the library is subject to `lib.json`.
|
||||
Among them, the library name with `-` needs to replace `-` with `_`.
|
||||
|
||||
Here is an example of an optimization option that replaces the openssl library compilation:
|
||||
|
||||
```shell
|
||||
openssl_CFLAGS="-O0"
|
||||
```
|
||||
|
||||
The library name uses the same name listed in `lib.json` and is case-sensitive.
|
||||
|
||||
::: tip
|
||||
When no relevant environment variables are specified, except for the following variables, the remaining values are empty by default:
|
||||
|
||||
| var name | var default value |
|
||||
|-----------------------|-------------------------------------------------------------------------------------------------|
|
||||
| `pkg_config_CFLAGS` | macOS: `$SPC_DEFAULT_C_FLAGS -Wimplicit-function-declaration -Wno-int-conversion`, Other: empty |
|
||||
| `pkg_config_LDFLAGS` | Linux: `--static`, Other: empty |
|
||||
| `imagemagick_LDFLAGS` | Linux: `-static`, Other: empty |
|
||||
| `imagemagick_LIBS` | macOS: `-liconv`, Other: empty |
|
||||
| `ldap_LDFLAGS` | `-L$BUILD_LIB_PATH` |
|
||||
| `openssl_CFLAGS` | Linux: `$SPC_DEFAULT_C_FLAGS`, Other: empty |
|
||||
| others... | empty |
|
||||
:::
|
||||
|
||||
The following table is a list of library names that support customizing the above three variables:
|
||||
|
||||
| lib name |
|
||||
|-------------|
|
||||
| brotli |
|
||||
| bzip |
|
||||
| curl |
|
||||
| freetype |
|
||||
| gettext |
|
||||
| gmp |
|
||||
| imagemagick |
|
||||
| ldap |
|
||||
| libargon2 |
|
||||
| libavif |
|
||||
| libcares |
|
||||
| libevent |
|
||||
| openssl |
|
||||
|
||||
::: tip
|
||||
Because adapting custom environment variables to each library is a particularly tedious task,
|
||||
and in most cases you do not need custom environment variables for these libraries,
|
||||
so we currently only support custom environment variables for some libraries.
|
||||
|
||||
If the library you need to customize environment variables is not listed above,
|
||||
you can submit your request through [GitHub Issue](https://github.com/crazywhalecc/static-php-cli/issues).
|
||||
:::
|
||||
@@ -1,168 +0,0 @@
|
||||
# Extension Notes
|
||||
|
||||
Because it is a static compilation, extensions will not compile 100% perfectly,
|
||||
and different extensions have different requirements for PHP and the environment,
|
||||
which will be listed one by one here.
|
||||
|
||||
## curl
|
||||
|
||||
HTTP3 support is not enabled by default, compile with `--with-libs="nghttp2,nghttp3,ngtcp2"` to enable HTTP3 support for PHP >= 8.4.
|
||||
|
||||
When using curl to request HTTPS, there may be an `error:80000002:system library::No such file or directory` error.
|
||||
For details on the solution, see [FAQ - Unable to use ssl](../faq/#unable-to-use-ssl).
|
||||
|
||||
## phpmicro
|
||||
|
||||
1. Only PHP >= 8.0 is supported.
|
||||
|
||||
## swoole
|
||||
|
||||
1. swoole >= 5.0 Only PHP >= 8.0 is supported.
|
||||
2. swoole Currently, curl hooks are not supported for PHP 8.0.x (which may be fixed in the future).
|
||||
3. When compiling, if only `swoole` extension is included, the supported Swoole database coroutine hook will not be fully enabled.
|
||||
If you need to use it, please add the corresponding `swoole-hook-xxx` extension.
|
||||
4. The `zend_mm_heap corrupted` problem may occur in swoole under some extension combinations. The cause has not yet been found.
|
||||
|
||||
## swoole-hook-pgsql
|
||||
|
||||
swoole-hook-pgsql is not an extension, it's a Hook feature of Swoole.
|
||||
If you use `swoole,swoole-hook-pgsql`, you will enable Swoole's PostgreSQL client and the coroutine mode of the `pdo_pgsql` extension.
|
||||
|
||||
swoole-hook-pgsql conflicts with the `pdo_pgsql` extension. If you want to use Swoole and `pdo_pgsql`, please delete the pdo_pgsql extension and enable `swoole` and `swoole-hook-pgsql`.
|
||||
This extension contains an implementation of the coroutine environment for `pdo_pgsql`.
|
||||
|
||||
On macOS systems, `pdo_pgsql` may not be able to connect to the postgresql server normally, please use it with caution.
|
||||
|
||||
## swoole-hook-mysql
|
||||
|
||||
swoole-hook-mysql is not an extension, it's a Hook feature of Swoole.
|
||||
If you use `swoole,swoole-hook-mysql`, you will enable the coroutine mode of Swoole's `mysqlnd` and `pdo_mysql`.
|
||||
|
||||
## swoole-hook-sqlite
|
||||
|
||||
swoole-hook-sqlite is not an extension, it's a Hook feature of Swoole.
|
||||
If you use `swoole,swoole-hook-sqlite`, you will enable the coroutine mode of Swoole's `pdo_sqlite` (Swoole must be 5.1 or above).
|
||||
|
||||
swoole-hook-sqlite conflicts with the `pdo_sqlite` extension. If you want to use Swoole and `pdo_sqlite`, please delete the pdo_sqlite extension and enable `swoole` and `swoole-hook-sqlite`.
|
||||
This extension contains an implementation of the coroutine environment for `pdo_sqlite`.
|
||||
|
||||
## swoole-hook-odbc
|
||||
|
||||
swoole-hook-odbc is not an extension, it's a Hook feature of Swoole.
|
||||
If you use `swoole,swoole-hook-odbc`, you will enable the coroutine mode of Swoole's `odbc` extension.
|
||||
|
||||
swoole-hook-odbc conflicts with the `pdo_odbc` extension. If you want to use Swoole and `pdo_odbc`, please delete the `pdo_odbc` extension and enable `swoole` and `swoole-hook-odbc`.
|
||||
This extension contains an implementation of the coroutine environment for `pdo_odbc`.
|
||||
|
||||
## swow
|
||||
|
||||
1. Only PHP 8.0+ is supported.
|
||||
|
||||
## imagick
|
||||
|
||||
1. OpenMP support is disabled, this is recommended by the maintainers and also the case system packages.
|
||||
|
||||
## imap
|
||||
|
||||
1. Kerberos is not supported
|
||||
2. ext-imap is not thread safe due to the underlying c-client. It's not possible to use it in `--enable-zts` builds.
|
||||
3. The extension was dropped from php 8.4, we recommend you look for an alternative implementation, such as [Webklex/php-imap](https://github.com/Webklex/php-imap)
|
||||
|
||||
## gd
|
||||
|
||||
1. gd Extension relies on more additional Graphics library. By default,
|
||||
using `bin/spc build gd` directly will not support some Graphics library, such as `libjpeg`, `libavif`, etc.
|
||||
Currently, it supports four libraries: `freetype,libjpeg,libavif,libwebp`.
|
||||
Therefore, the following command can be used to introduce them into the gd library:
|
||||
|
||||
```bash
|
||||
bin/spc build gd --with-libs=freetype,libjpeg,libavif,libwebp --build-cli
|
||||
```
|
||||
|
||||
## mcrypt
|
||||
|
||||
1. Currently not supported, and this extension will not be supported in the future. [#32](https://github.com/crazywhalecc/static-php-cli/issues/32)
|
||||
|
||||
## oci8
|
||||
|
||||
1. oci8 is an extension of the Oracle database, because the library on which the extension provided by Oracle does not provide a statically compiled version (`.a`) or source code,
|
||||
and this extension cannot be compiled into php by static linking, so it cannot be supported.
|
||||
|
||||
## xdebug
|
||||
|
||||
1. Xdebug is only buildable as a shared extension. On Linux, you'll need to use a SPC_TARGET like `native-native -dynamic` or `native-native-gnu`.
|
||||
2. When using Linux/glibc or macOS, you can compile Xdebug as a shared extension using --build-shared="xdebug".
|
||||
The compiled `./php` binary can be configured and run by specifying the INI, eg `./php -d 'zend_extension=/path/to/xdebug.so' your-code.php`.
|
||||
|
||||
## xml
|
||||
|
||||
1. xml includes xml, xmlreader, xmlwriter, xsl, dom, simplexml, etc.
|
||||
When adding xml extensions, it is best to enable these extensions at the same time.
|
||||
2. libxml is included in xml extension. Enabling xml is equivalent to enabling libxml.
|
||||
|
||||
## glfw
|
||||
|
||||
1. glfw depends on OpenGL, and linux environment also needs X11, which cannot be linked statically.
|
||||
2. macOS platform, we can compile and link system builtin OpenGL and related libraries dynamically.
|
||||
|
||||
## rar
|
||||
|
||||
1. The rar extension currently has a problem when compiling phpmicro with the `common` extension collection in the macOS x86_64 environment.
|
||||
|
||||
## pgsql
|
||||
|
||||
~~pgsql ssl connection is not compatible with openssl 3.2.0. See:~~
|
||||
|
||||
- ~~<https://github.com/Homebrew/homebrew-core/issues/155651>~~
|
||||
- ~~<https://github.com/Homebrew/homebrew-core/pull/155699>~~
|
||||
- ~~<https://github.com/postgres/postgres/commit/c82207a548db47623a2bfa2447babdaa630302b9>~~
|
||||
|
||||
pgsql 16.2 has fixed this bug, now it's working.
|
||||
|
||||
When pgsql uses SSL connection, there may be `error:80000002:system library::No such file or directory` error,
|
||||
For details on the solution, see [FAQ - Unable to use ssl](../faq/#unable-to-use-ssl).
|
||||
|
||||
## openssl
|
||||
|
||||
When using openssl-based extensions (such as curl, pgsql and other network libraries),
|
||||
there may be an `error:80000002:system library::No such file or directory` error.
|
||||
For details on the solution, see [FAQ - Unable to use ssl](../faq/#unable-to-use-ssl).
|
||||
|
||||
## password-argon2
|
||||
|
||||
1. password-argon2 is not a standard extension. The algorithm `PASSWORD_ARGON2ID` for the `password_hash` function needs libsodium or libargon2 to work.
|
||||
2. using password-argon2 enables multithread support for this.
|
||||
|
||||
## ffi
|
||||
|
||||
1. Due to the limitation of musl libc's static linkage, you cannot use ffi because dynamic libraries cannot be loaded.
|
||||
If you need to use the ffi extension, see [Compile PHP with GNU libc](./build-with-glibc).
|
||||
2. macOS supports the ffi extension, but errors will occur when some kernels do not contain debugging symbols.
|
||||
3. Windows x64 supports the ffi extension.
|
||||
|
||||
## xhprof
|
||||
|
||||
The xhprof extension consists of three parts: `xhprof_extension`, `xhprof_html`, `xhprof_libs`.
|
||||
Only `xhprof_extension` is included in the compiled binary.
|
||||
If you need to use xhprof,
|
||||
please download the source code from [pecl.php.net/package/xhprof](http://pecl.php.net/package/xhprof) and specify the `xhprof_libs` and `xhprof_html` paths for use.
|
||||
|
||||
## event
|
||||
|
||||
If you enable event extension on macOS, the `openpty` will be disabled due to issue:
|
||||
|
||||
- [static-php-cli#335](https://github.com/crazywhalecc/static-php-cli/issues/335)
|
||||
|
||||
## parallel
|
||||
|
||||
Parallel is only supported on PHP 8.0 ZTS and above.
|
||||
|
||||
## spx
|
||||
|
||||
1. SPX does not support Windows, and the official repository does not support static compilation. static-php-cli uses a [modified version](https://github.com/static-php/php-spx).
|
||||
|
||||
## mimalloc
|
||||
|
||||
1. This is not technically an extension, but a library.
|
||||
2. Building with `--with-libs="mimalloc"` on Linux or macOS will override the default allocator.
|
||||
3. This is experimental for now, but is recommended in threaded environments.
|
||||
@@ -1,23 +0,0 @@
|
||||
<script setup>
|
||||
import SearchTable from "../../.vitepress/components/SearchTable.vue";
|
||||
</script>
|
||||
|
||||
# Extensions
|
||||
|
||||
> - `yes`: supported
|
||||
> - _blank_: not supported yet, or WIP
|
||||
> - `no` with issue link: confirmed to be unavailable due to issue
|
||||
> - `partial` with issue link: supported but not perfect due to issue
|
||||
|
||||
<search-table />
|
||||
|
||||
::: tip
|
||||
If an extension you need is missing, you can create a [Feature Request](https://github.com/crazywhalecc/static-php-cli/issues).
|
||||
|
||||
Some extensions or libraries that the extension depends on will have some optional features.
|
||||
For example, the gd library optionally supports libwebp, freetype, etc.
|
||||
If you only use `bin/spc build gd --build-cli` they will not be included (static-php-cli defaults to the minimum dependency principle).
|
||||
|
||||
For more information about optional libraries, see [Extensions, Library Dependency Map](./deps-map).
|
||||
For optional libraries, you can also select an extension from the [Command Generator](./cli-generator) and then select optional libraries.
|
||||
:::
|
||||
@@ -1,50 +0,0 @@
|
||||
# Guide
|
||||
|
||||
Static php cli is a tool used to build statically compiled PHP binaries,
|
||||
currently supporting Linux and macOS systems.
|
||||
|
||||
In the guide section, you will learn how to use static php cli to build standalone PHP programs.
|
||||
|
||||
- [Build (local)](./manual-build)
|
||||
- [Build (GitHub Actions)](./action-build)
|
||||
- [Supported Extensions](./extensions)
|
||||
|
||||
## Compilation Environment
|
||||
|
||||
The following is the architecture support situation, where :gear: represents support for GitHub Action build,
|
||||
:computer: represents support for local manual build, and empty represents temporarily not supported.
|
||||
|
||||
| | x86_64 | aarch64 |
|
||||
|---------|-------------------|-------------------|
|
||||
| macOS | :gear: :computer: | :gear: :computer: |
|
||||
| Linux | :gear: :computer: | :gear: :computer: |
|
||||
| Windows | :gear: :computer: | |
|
||||
| FreeBSD | :computer: | :computer: |
|
||||
|
||||
Current supported PHP versions for compilation:
|
||||
|
||||
> :warning: Partial support, there may be issues with new beta versions and old versions.
|
||||
>
|
||||
> :heavy_check_mark: Supported
|
||||
>
|
||||
> :x: Not supported
|
||||
|
||||
| PHP Version | Status | Comment |
|
||||
|-------------|--------------------|-------------------------------------------------------------------------------------------------------------------------|
|
||||
| 7.2 | :x: | |
|
||||
| 7.3 | :x: | phpmicro and many extensions do not support 7.3, 7.4 versions |
|
||||
| 7.4 | :x: | phpmicro and many extensions do not support 7.3, 7.4 versions |
|
||||
| 8.0 | :warning: | PHP official has stopped maintaining 8.0, we no longer handle 8.0 related backport support |
|
||||
| 8.1 | :warning: | PHP official only provides security updates for 8.1, we no longer handle 8.1 related backport support after 8.5 release |
|
||||
| 8.2 | :heavy_check_mark: | |
|
||||
| 8.3 | :heavy_check_mark: | |
|
||||
| 8.4 | :heavy_check_mark: | |
|
||||
| 8.5 (beta) | :warning: | PHP 8.5 is currently in beta stage |
|
||||
|
||||
> This table shows the support status of static-php-cli for building corresponding versions, not the PHP official support status for that version.
|
||||
|
||||
## PHP Support Versions
|
||||
|
||||
Currently, static-php-cli supports PHP versions 8.2 ~ 8.5, and theoretically supports PHP 8.1 and earlier versions, just select the earlier version when downloading.
|
||||
However, due to some extensions and special components that have stopped supporting earlier versions of PHP, static-php-cli will not explicitly support earlier versions.
|
||||
We recommend that you compile the latest PHP version possible for a better experience.
|
||||
@@ -1,705 +0,0 @@
|
||||
---
|
||||
outline: 'deep'
|
||||
---
|
||||
|
||||
# Build (Linux, macOS, FreeBSD)
|
||||
|
||||
This section covers the build process for Linux, macOS, and FreeBSD. If you want to build on Windows,
|
||||
also need to read [Build on Windows](./build-on-windows).
|
||||
|
||||
### Build locally (using SPC binary) (recommended)
|
||||
|
||||
This project provides a binary file of static-php-cli.
|
||||
You can directly download the binary file of the corresponding platform and then use it to build static PHP.
|
||||
Currently, the platforms supported by `spc` binary are Linux and macOS.
|
||||
|
||||
Here's how to download from self-hosted server:
|
||||
|
||||
```bash
|
||||
# Download from self-hosted nightly builds (sync with main branch)
|
||||
# For Linux x86_64
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64
|
||||
# For Linux aarch64
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-aarch64
|
||||
# macOS x86_64 (Intel)
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-x86_64
|
||||
# macOS aarch64 (Apple)
|
||||
curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-aarch64
|
||||
# Windows (x86_64, win10 build 17063 or later)
|
||||
curl.exe -fsSL -o spc.exe https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-windows-x64.exe
|
||||
|
||||
# Add execute perm (Linux and macOS only)
|
||||
chmod +x ./spc
|
||||
|
||||
# Run (Linux and macOS)
|
||||
./spc --version
|
||||
# Run (Windows powershell)
|
||||
.\spc.exe --version
|
||||
```
|
||||
|
||||
> If you are using the packaged `spc` binary, you will need to replace the leading `bin/spc` with `./spc` in all the commands below.
|
||||
|
||||
### Build locally (using source code)
|
||||
|
||||
If you have problems using the spc binary, or if you need to modify the static-php-cli source code, download static-php-cli from the source code.
|
||||
|
||||
Currently, it supports building on macOS and Linux.
|
||||
macOS supports the latest version of the operating system and two architectures,
|
||||
while Linux supports Debian and derivative distributions, as well as Alpine Linux.
|
||||
|
||||
Because this project itself is developed using PHP,
|
||||
it is also necessary to install PHP on the system during compilation.
|
||||
This project also provides static binary PHP suitable for this project,
|
||||
which can be selected and used according to actual situations.
|
||||
|
||||
```bash
|
||||
# clone repo
|
||||
git clone https://github.com/crazywhalecc/static-php-cli.git --depth=1
|
||||
cd static-php-cli
|
||||
|
||||
# You need to install the PHP environment first before running Composer and this project. The installation method can be referred to below.
|
||||
composer update
|
||||
```
|
||||
|
||||
### Use Precompiled Static PHP Binaries
|
||||
|
||||
If you don't want to use Docker and install PHP in the system,
|
||||
you can directly download the php binary cli program compiled by this project itself. The usage process is as follows:
|
||||
|
||||
Deploy the environment using the command, the command will download a static php-cli binary from [self-hosted server](https://dl.static-php.dev/static-php-cli/).
|
||||
Next, it will automatically download Composer from [getcomposer](https://getcomposer.org/download/latest-stable/composer.phar) or [Aliyun mirror](https://mirrors.aliyun.com/composer/composer.phar).
|
||||
|
||||
::: tip
|
||||
Using precompiled static PHP binaries is currently only supported on Linux and macOS.
|
||||
The FreeBSD environment is currently not supported due to the lack of an automated build environment.
|
||||
:::
|
||||
|
||||
```bash
|
||||
bin/setup-runtime
|
||||
|
||||
# For users with special network environments such as mainland China, you can use mirror sites (aliyun) to speed up the download speed
|
||||
bin/setup-runtime --mirror china
|
||||
```
|
||||
|
||||
This script will download two files in total: `bin/php` and `bin/composer`. After the download is complete, there are two ways to use it:
|
||||
|
||||
1. Add the `bin/` directory to the PATH: `export PATH="/path/to/your/static-php-cli/bin:$PATH"`, after adding the path,
|
||||
it is equivalent to installing PHP in the system, you can directly Use commands such as `composer`, `php -v`, or directly use `bin/spc`.
|
||||
2. Direct call, such as executing static-php-cli command: `bin/php bin/spc --help`, executing Composer: `bin/php bin/composer update`.
|
||||
|
||||
### Use Docker
|
||||
|
||||
If you don't want to install PHP and Composer runtime environment on your system, you can use the built-in Docker environment build script.
|
||||
|
||||
```bash
|
||||
# To use directly, replace `bin/spc` with `bin/spc-alpine-docker` in all used commands
|
||||
bin/spc-alpine-docker
|
||||
```
|
||||
|
||||
The first time the command is executed, `docker build` will be used to build a Docker image.
|
||||
The default built Docker image is the `x86_64` architecture, and the image name is `cwcc-spc-x86_64`.
|
||||
|
||||
If you want to build `aarch64` static-php-cli in `x86_64` environment,
|
||||
you can use qemu to emulate the arm image to run Docker, but the speed will be very slow.
|
||||
Use command: `SPC_USE_ARCH=aarch64 bin/spc-alpine-docker`.
|
||||
|
||||
If it prompts that sudo is required to run after running,
|
||||
execute the following command once to grant static-php-cli permission to execute sudo:
|
||||
|
||||
```bash
|
||||
export SPC_USE_SUDO=yes
|
||||
```
|
||||
|
||||
### Use System PHP
|
||||
|
||||
Below are some example commands for installing PHP and Composer in the system.
|
||||
It is recommended to search for the specific installation method yourself or ask the AI search engine to obtain the answer,
|
||||
which will not be elaborated here.
|
||||
|
||||
```bash
|
||||
# [macOS], need install Homebrew first. See https://brew.sh/
|
||||
# Remember change your composer executable path. For M1/M2 Chip mac, "/opt/homebrew/bin/", for Intel mac, "/usr/local/bin/". Or add it to your own path.
|
||||
brew install php wget
|
||||
wget https://getcomposer.org/download/latest-stable/composer.phar -O /path/to/your/bin/composer && chmod +x /path/to/your/bin/composer
|
||||
|
||||
# [Debian], you need to make sure your php version >= 8.1 and composer >= 2.0
|
||||
sudo apt install php-cli composer php-tokenizer
|
||||
|
||||
# [Alpine]
|
||||
apk add bash file wget xz php81 php81-common php81-pcntl php81-tokenizer php81-phar php81-posix php81-xml composer
|
||||
```
|
||||
|
||||
::: tip
|
||||
Currently, some versions of Ubuntu install older PHP versions,
|
||||
so no installation commands are provided. If necessary, it is recommended to add software sources such as ppa first,
|
||||
and then install the latest version of PHP and tokenizer, XML, and phar extensions.
|
||||
|
||||
Older versions of Debian may have an older (<= 7.4) version of PHP installed by default, it is recommended to upgrade Debian first.
|
||||
:::
|
||||
|
||||
## Build with craft (recommended)
|
||||
|
||||
Using `bin/spc craft`, you can use a configuration file and a command to automatically check the environment, download source code, build dependency libraries, build PHP and extensions, etc.
|
||||
|
||||
You need to write a `craft.yml` file and save it in the current working directory. `craft.yml` can be generated by [command generator](./cli-generator) or written manually.
|
||||
|
||||
For manual writing, please refer to the comments in [craft.yml configuration](../develop/craft-yml.md) to write it.
|
||||
Let's assume that you compile an extension combination and choose PHP 8.4, outputting `cli` and `fpm`:
|
||||
|
||||
```yaml
|
||||
# path/to/craft.yml
|
||||
php-version: 8.4
|
||||
extensions: bcmath,posix,phar,zlib,openssl,curl,fileinfo,tokenizer
|
||||
sapi:
|
||||
- cli
|
||||
- fpm
|
||||
```
|
||||
|
||||
Then use the `bin/spc craft` command to compile:
|
||||
|
||||
```bash
|
||||
bin/spc craft --debug
|
||||
```
|
||||
|
||||
If the build is successful, you will see the `buildroot/bin` directory in the current directory, which contains the compiled PHP binary file, or the corresponding SAPI.
|
||||
|
||||
- cli: The build result is `buildroot/bin/php.exe` on Windows and `buildroot/bin/php` on other platforms.
|
||||
- fpm: The build result is `buildroot/bin/php-fpm`.
|
||||
- micro: The build result is `buildroot/bin/micro.sfx`. If you need to further package it with PHP code, please refer to [Packaging micro binary](./manual-build#command-micro-combine).
|
||||
- embed: See [Using embed](./manual-build#embed-usage).
|
||||
- frankenphp: The build result is `buildroot/bin/frankenphp`.
|
||||
|
||||
If the build fails, you can use the `--debug` parameter to view detailed error information,
|
||||
or use the `--with-clean` to clear the old compilation results and recompile.
|
||||
|
||||
If the build still fails to use the above method, please submit an issue and attach your `craft.yml` and `./log` archive.
|
||||
|
||||
## Step-by-step build command
|
||||
|
||||
If you have customized requirements, or the need to download and compile PHP and dependent libraries separately, you can use the `bin/spc` command to execute step by step.
|
||||
|
||||
### Command download - Download dependency packages
|
||||
|
||||
Use the command `bin/spc download` to download the source code required for compilation,
|
||||
including php-src and the source code of various dependent libraries.
|
||||
|
||||
```bash
|
||||
# Download all dependencies, defaults to php 8.4
|
||||
bin/spc download --all
|
||||
|
||||
# Download all dependent packages, and specify the main version of PHP to download, optional: 8.1, 8.2, 8.3, 8.4
|
||||
# Also supports specific version of php release: 8.3.10, 8.2.22, etc.
|
||||
bin/spc download --all --with-php=8.3
|
||||
|
||||
# Show download progress bar while downloading (curl)
|
||||
bin/spc download --all --debug
|
||||
|
||||
# Delete old download data
|
||||
bin/spc download --clean
|
||||
|
||||
# Download specified dependencies
|
||||
bin/spc download php-src,micro,zstd,ext-zstd
|
||||
|
||||
# Download only extensions and libraries to be compiled (use extensions, including suggested libraries)
|
||||
bin/spc download --for-extensions=openssl,swoole,zip,pcntl,zstd
|
||||
|
||||
# Download resources, prefer to download dependencies with pre-built packages (reduce the time to compile dependencies)
|
||||
bin/spc download --for-extensions="curl,pcntl,xml,mbstring" --prefer-pre-built
|
||||
|
||||
# Download only the extensions and dependent libraries to be compiled (use extensions, excluding suggested libraries)
|
||||
bin/spc download --for-extensions=openssl,swoole,zip,pcntl --without-suggestions
|
||||
|
||||
# Download only libraries to be compiled (use libraries, including suggested libraries and required libraries, can use --for-extensions together)
|
||||
bin/spc download --for-libs=liblz4,libevent --for-extensions=pcntl,rar,xml
|
||||
|
||||
# Download only libraries to be compiled (use libraries, excluding suggested libraries)
|
||||
bin/spc download --for-libs=liblz4,libevent --without-suggestions
|
||||
|
||||
# When downloading sources, ignore some source caches (always force download, e.g. switching PHP version)
|
||||
bin/spc download --for-extensions=curl,pcntl,xml --ignore-cache-sources=php-src --with-php=8.3.10
|
||||
|
||||
# Set retry times (default is 0)
|
||||
bin/spc download --all --retry=2
|
||||
```
|
||||
|
||||
If the network in your area is not good, or the speed of downloading the dependency package is too slow,
|
||||
you can download `download.zip` which is packaged regularly every week from GitHub Action,
|
||||
and use the command to directly use the zip archive as a dependency.
|
||||
|
||||
Dependent packages can be downloaded locally from [Action](https://github.com/static-php/static-php-cli-hosted/actions/workflows/download-cache.yml).
|
||||
Enter Action and select the latest Workflow that has been successfully run, and download `download-files-x.y`.
|
||||
|
||||
```bash
|
||||
bin/spc download --from-zip=/path/to/your/download.zip
|
||||
```
|
||||
|
||||
If a source cannot be downloaded all the time, or you need to download some specific version of the package,
|
||||
such as downloading the beta version of PHP, the old version of the library, etc.,
|
||||
you can use the parameter `-U` or `--custom-url` to rewrite the download link,
|
||||
Make the downloader force the link you specify to download packages from this source.
|
||||
The method of use is `{source-name}:{url}`, which can rewrite the download URLs of multiple libraries at the same time.
|
||||
Also, it is available when downloading with the `--for-extensions` option.
|
||||
|
||||
|
||||
```bash
|
||||
# Specifying to download a alpha version of PHP 8.5
|
||||
bin/spc download --all -U "php-src:https://downloads.php.net/~edorian/php-8.5.0alpha2.tar.xz"
|
||||
|
||||
# Specifying to download an older version of the curl library
|
||||
bin/spc download --all -U "curl:https://curl.se/download/curl-7.88.1.tar.gz"
|
||||
```
|
||||
|
||||
If the source you download is not a link, but a git repository, you can use `-G` or `--custom-git` to rewrite the download link,
|
||||
so that the downloader can force the use of the specified git repository to download packages from this source.
|
||||
The usage method is `{source-name}:{branch}:{url}`, which can rewrite the download link of multiple libraries at the same time.
|
||||
It is also available when downloading with the `--for-extensions` option.
|
||||
|
||||
```bash
|
||||
# Specifying to download the source code of the PHP extension from the specified branch of the git repository
|
||||
bin/spc download --for-extensions=redis -G "php-src:master:https://github.com/php/php-src.git"
|
||||
|
||||
# Download the latest code from the master branch of the swoole-src repository instead of PECL release version
|
||||
bin/spc download --for-extensions=swoole -G "swoole:master:https://github.com/swoole/swoole-src.git"
|
||||
```
|
||||
|
||||
### Command - doctor
|
||||
|
||||
If you can run `bin/spc` normally but cannot compile static PHP or dependent libraries normally,
|
||||
you can run `bin/spc doctor` first to check whether the system itself lacks dependencies.
|
||||
|
||||
```bash
|
||||
# Quick check
|
||||
bin/spc doctor
|
||||
|
||||
# Quickly check and fix when it can be automatically repaired (use package management to install dependent packages, only support the above-mentioned operating systems and distributions)
|
||||
bin/spc doctor --auto-fix
|
||||
```
|
||||
|
||||
### Command - build
|
||||
|
||||
Use the build command to start building the static php binary.
|
||||
Before executing the `bin/spc build` command, be sure to use the `download` command to download sources.
|
||||
It is recommended to use `doctor` to check the environment.
|
||||
|
||||
#### Basic build
|
||||
|
||||
You need to go to [Extension List](./extensions) or [Command Generator](./cli-generator) to select the extension you want to add,
|
||||
and then use the command `bin/spc build` to compile.
|
||||
You need to specify a compilation target, choose from the following parameters:
|
||||
|
||||
- `--build-cli`: Build a cli sapi (command line interface, which can execute PHP code on the command line)
|
||||
- `--build-fpm`: Build a fpm sapi (php-fpm, used in conjunction with other traditional fpm architecture software such as nginx)
|
||||
- `--build-cgi`: Build a cgi sapi (cgi, rarely used)
|
||||
- `--build-micro`: Build a micro sapi (used to build a standalone executable binary containing PHP code)
|
||||
- `--build-embed`: Build an embed sapi (used to embed into other C language programs)
|
||||
- `--build-frankenphp`: Build a [FrankenPHP](https://github.com/php/frankenphp) executable
|
||||
- `--build-all`: build all above sapi
|
||||
|
||||
```bash
|
||||
# Compile PHP with bcmath,curl,openssl,ftp,posix,pcntl extensions, the compilation target is cli
|
||||
bin/spc build bcmath,curl,openssl,ftp,posix,pcntl --build-cli
|
||||
|
||||
# Compile PHP with phar,curl,posix,pcntl,tokenizer extensions, compile target is micro
|
||||
bin/spc build phar,curl,posix,pcntl,tokenizer --build-micro
|
||||
```
|
||||
|
||||
::: tip
|
||||
If you need to repeatedly build and debug, you can delete the `buildroot/` and `source/` directories so that you can re-extract and build all you need from the downloaded source code package:
|
||||
|
||||
```shell
|
||||
# remove
|
||||
rm -rf buildroot source
|
||||
# build again
|
||||
bin/spc build bcmath,curl,openssl,ftp,posix,pcntl --build-cli
|
||||
```
|
||||
:::
|
||||
|
||||
::: tip
|
||||
If you want to build multiple versions of PHP and don't want to build other dependent libraries repeatedly each time,
|
||||
you can use `switch-php-version` to quickly switch to another version and compile after compiling one version:
|
||||
|
||||
```shell
|
||||
# switch to 8.4
|
||||
bin/spc switch-php-version 8.4
|
||||
# build
|
||||
bin/spc build bcmath,curl,openssl,ftp,posix,pcntl --build-cli
|
||||
# switch to 8.1
|
||||
bin/spc switch-php-version 8.1
|
||||
# build
|
||||
bin/spc build bcmath,curl,openssl,ftp,posix,pcntl --build-cli
|
||||
```
|
||||
:::
|
||||
|
||||
#### Build Options
|
||||
|
||||
During the compilation process, in some special cases,
|
||||
the compiler and the content of the compilation directory need to be intervened.
|
||||
You can try to use the following commands:
|
||||
|
||||
- `--cc=XXX`: Specifies the execution command of the C language compiler (Linux default `musl-gcc` or `gcc`, macOS default `clang`)
|
||||
- `--cxx=XXX`: Specifies the execution command of the C++ language compiler (Linux defaults to `g++`, macOS defaults to `clang++`)
|
||||
- `--with-clean`: clean up old make files before compiling PHP
|
||||
- `--enable-zts`: Make compiled PHP thread-safe version (default is NTS version)
|
||||
- `--no-strip`: Do not run `strip` after compiling the PHP library to trim the binary file to reduce its size
|
||||
- `--with-libs=XXX,YYY`: Compile the specified dependent library before compiling PHP, and activate some extended optional functions (such as libavif of the gd library, etc.)
|
||||
- `--with-config-file-path=XXX`: Set the path in which to look for `php.ini` (Check [here](../faq/index.html#what-is-the-path-of-php-ini) for default paths)
|
||||
- `--with-config-file-scan-dir=XXX`: Set the directory to scan for `.ini` files after reading `php.ini` (Check [here](../faq/index.html#what-is-the-path-of-php-ini) for default paths)
|
||||
- `-I xxx=yyy`: Hard compile INI options into PHP before compiling (support multiple options, alias is `--with-hardcoded-ini`)
|
||||
- `--with-micro-fake-cli`: When compiling micro, let micro's `PHP_SAPI` pretend to be `cli` (for compatibility with some programs that check `PHP_SAPI`)
|
||||
- `--disable-opcache-jit`: Disable opcache jit (enabled by default)
|
||||
- `-P xxx.php`: Inject external scripts during static-php-cli compilation (see **Inject external scripts** below for details)
|
||||
- `--without-micro-ext-test`: After building micro.sfx, do not test the running results of different extensions in micro.sfx
|
||||
- `--with-suggested-exts`: Add `ext-suggests` as dependencies when compiling
|
||||
- `--with-suggested-libs`: Add `lib-suggests` as dependencies when compiling
|
||||
- `--with-upx-pack`: Use UPX to reduce the size of the binary file after compilation (you need to use `bin/spc install-pkg upx` to install upx first)
|
||||
- `--build-shared=XXX,YYY`: compile the specified extension into a shared library (the default is to compile into a static library)
|
||||
|
||||
For hardcoding INI options, it works for cli, micro, embed sapi. Here is a simple example where we preset a larger `memory_limit` and disable the `system` function:
|
||||
|
||||
```bash
|
||||
bin/spc build bcmath,pcntl,posix --build-all -I "memory_limit=4G" -I "disable_functions=system"
|
||||
```
|
||||
|
||||
## Debug
|
||||
|
||||
If you encounter problems during the compilation process, or want to view each executing shell command,
|
||||
you can use `--debug` to enable debug mode and view all terminal logs:
|
||||
|
||||
```bash
|
||||
bin/spc build mysqlnd,pdo_mysql --build-all --debug
|
||||
```
|
||||
|
||||
## Command - micro:combine
|
||||
|
||||
Use the `micro:combine` command to build the compiled `micro.sfx` and your code (`.php` or `.phar` file) into an executable binary.
|
||||
You can also use this command to directly build a micro binary injected with ini configuration.
|
||||
|
||||
::: tip
|
||||
Injecting ini configuration refers to adding a special structure after micro.sfx to save ini configuration items before combining micro.sfx with PHP source code.
|
||||
|
||||
micro.sfx can identify the INI file header through a special byte, and the micro can be started with INI through the INI file header.
|
||||
|
||||
The original wiki of this feature is in [phpmicro - Wiki](https://github.com/easysoft/phpmicro/wiki/INI-settings), and this feature may change in the future.
|
||||
:::
|
||||
|
||||
The following is the general usage, directly packaging the php source code into a file:
|
||||
|
||||
```bash
|
||||
# Before doing the packaging process, you should use `build --build-micro` to compile micro.sfx
|
||||
echo "<?php echo 'hello';" > a.php
|
||||
bin/spc micro:combine a.php
|
||||
|
||||
# Just use it
|
||||
./my-app
|
||||
```
|
||||
|
||||
You can use the following options to specify the file name to be output, and you can also specify micro.sfx in other paths for packaging.
|
||||
|
||||
```bash
|
||||
# specify the output filename
|
||||
bin/spc micro:combine a.php --output=custom-bin
|
||||
# Use absolute path
|
||||
bin/spc micro:combine a.php -O /tmp/my-custom-app
|
||||
|
||||
# Specify micro.sfx in other locations for packaging
|
||||
bin/spc micro:combine a.app --with-micro=/path/to/your/micro.sfx
|
||||
```
|
||||
|
||||
If you want to inject ini configuration items, you can use the following parameters to add ini to the executable file from a file or command line option.
|
||||
|
||||
```bash
|
||||
# Specified using command-line options (-I is shorthand for --with-ini-set)
|
||||
bin/spc micro:combine a.php -I "a=b" -I "foo=bar"
|
||||
|
||||
# Use ini file specification (-N is shorthand for --with-ini-file)
|
||||
bin/spc micro:combine a.php -N /path/to/your/custom.ini
|
||||
```
|
||||
|
||||
::: warning
|
||||
Note, please do not directly use the PHP source code or the `php.ini` file in the system-installed PHP,
|
||||
it is best to manually write an ini configuration file that you need, for example:
|
||||
|
||||
```ini
|
||||
; custom.ini
|
||||
curl.cainfo=/path/to/your/cafile.pem
|
||||
memory_limit=1G
|
||||
```
|
||||
|
||||
The ini injection of this command is achieved by appending a special structure after micro.sfx,
|
||||
which is different from the function of inserting hard-coded INI during compilation.
|
||||
:::
|
||||
|
||||
If you want to package phar, just replace `a.php` with the packaged phar file.
|
||||
But please note that micro.sfx under phar needs extra attention to the path problem, see [Developing - Phar directory issue](../develop/structure#phar-application-directory-issue).
|
||||
|
||||
## Command - extract
|
||||
|
||||
Use the command `bin/spc extract` to unpack and copy the source code required for compilation,
|
||||
including php-src and the source code of various dependent libraries (you need to specify the name of the library to be unpacked).
|
||||
|
||||
For example, after we have downloaded sources, we want to distribute and execute the build process,
|
||||
manually unpack and copy the package to a specified location, and we can use commands.
|
||||
|
||||
```bash
|
||||
# Unzip the downloaded compressed package of php-src and libxml2, and store the decompressed source code in the source directory
|
||||
bin/spc extract php-src,libxml2
|
||||
```
|
||||
|
||||
## Command - dump-extensions
|
||||
|
||||
Use the command `bin/spc dump-extensions` to export required extensions of the current project.
|
||||
|
||||
```bash
|
||||
# Print the extension list of the project, pass in the root directory of the project containing composer.json
|
||||
bin/spc dump-extensions /path/to/your/project/
|
||||
|
||||
# Print the extension list of the project, excluding development dependencies
|
||||
bin/spc dump-extensions /path-to/tour/project/ --no-dev
|
||||
|
||||
# Output in the extension list format acceptable to the spc command (comma separated)
|
||||
bin/spc dump-extensions /path-to/tour/project/ --format=text
|
||||
|
||||
# Output as a JSON list
|
||||
bin/spc dump-extensions /path-to/tour/project/ --format=json
|
||||
|
||||
# When the project does not have any extensions, output the specified extension combination instead of returning failure
|
||||
bin/spc dump-extensions /path-to/your/project/ --no-ext-output=mbstring,posix,pcntl,phar
|
||||
|
||||
# Do not exclude extensions not supported by spc when outputting
|
||||
bin/spc dump-extensions /path/to/your/project/ --no-spc-filter
|
||||
```
|
||||
It should be noted that the project directory must contain the `vendor/installed.json` and `composer.lock` files, otherwise they cannot be found normally.
|
||||
|
||||
## Dev Command - dev
|
||||
|
||||
Debug commands refer to a collection of commands that can assist in outputting some information
|
||||
when you use static-php-cli to build PHP or modify and enhance the static-php-cli project itself.
|
||||
|
||||
- `dev:extensions`: output all currently supported extension names, or output the specified extension information
|
||||
- `dev:php-version`: output the currently compiled PHP version (by reading `php_version.h`)
|
||||
- `dev:sort-config`: Sort the list of configuration files in the `config/` directory in alphabetical order
|
||||
- `dev:lib-ver <lib-name>`: Read the version from the source code of the dependency library (only available for specific dependency libraries)
|
||||
- `dev:ext-ver <ext-name>`: Read the corresponding version from the source code of the extension (only available for specific extensions)
|
||||
- `dev:pack-lib <lib-name>`: Package the specified library into a tar.gz file (maintainer only)
|
||||
- `dev:gen-ext-docs`: Generate extension documentation (maintainer only)
|
||||
|
||||
```bash
|
||||
# output all extensions information
|
||||
bin/spc dev:extensions
|
||||
|
||||
# Output the meta information of the specified extension
|
||||
bin/spc dev:extensions mongodb,curl,openssl
|
||||
|
||||
# Output the specified columns
|
||||
# Available column name: lib-depends, lib-suggests, ext-depends, ext-suggests, unix-only, type
|
||||
bin/spc dev:extensions --columns=lib-depends,type,ext-depends
|
||||
|
||||
# Output the currently compiled PHP version
|
||||
# You need to decompress the downloaded PHP source code to the source directory first
|
||||
# You can use `bin/spc extract php-src` to decompress the source code separately
|
||||
bin/spc dev:php-version
|
||||
|
||||
# Sort the configuration files in the config/ directory in alphabetical order (e.g. ext.json)
|
||||
bin/spc dev:sort-config ext
|
||||
```
|
||||
|
||||
## Command - install-pkg
|
||||
|
||||
Use the command `bin/spc install-pkg` to download some precompiled or closed source tools and install them into the `pkgroot` directory.
|
||||
|
||||
When `bin/spc doctor` automatically repairs the Windows environment, tools such as nasm and perl will be downloaded, and the installation process of `install-pkg` will also be used.
|
||||
|
||||
Here is an example of installing the tool:
|
||||
|
||||
- Download and install UPX (Linux and Windows only): `bin/spc install-pkg upx`
|
||||
- Download and install nasm (Windows only): `bin/spc install-pkg nasm`
|
||||
- Download and install go-xcaddy: `bin/spc install-pkg go-xcaddy`
|
||||
|
||||
## Command - del-download
|
||||
|
||||
In some cases, you need to delete single or multiple specified download source files and re-download them, such as switching PHP versions.
|
||||
The `bin/spc del-download` command is provided after the `2.1.0-beta.4` version. Specified source files can be deleted.
|
||||
|
||||
Deletes downloaded source files containing precompiled packages and source code named as keys in `source.json` or `pkg.json`. Here are some examples:
|
||||
|
||||
- Delete the old PHP source code and switch to download the 8.3 version: `bin/spc del-download php-src && bin/spc download php-src --with-php=8.3`
|
||||
- Delete the download file of redis extension: `bin/spc del-download redis`
|
||||
- Delete the downloaded musl-toolchain x86_64: `bin/spc del-download musl-toolchain-x86_64-linux`
|
||||
|
||||
## Inject External Script
|
||||
|
||||
Injecting external scripts refers to inserting one or more scripts during the static-php-cli compilation process
|
||||
to more flexibly support parameter modifications and source code patches in different environments.
|
||||
|
||||
Under normal circumstances, this function mainly solves the problem that the patch cannot be modified
|
||||
by modifying the static-php-cli code when compiling with `spc` binary.
|
||||
|
||||
There is another situation: your project directly depends on the `crazywhalecc/static-php-cli` repository and is synchronized with main branch,
|
||||
but some proprietary modifications are required, and these feature are not suitable for merging into the main branch.
|
||||
|
||||
In view of the above situation, in the official version 2.0.0, static-php-cli has added multiple event trigger points.
|
||||
You can write an external `xx.php` script and pass it in through the command line parameter `-P` and execute.
|
||||
|
||||
When writing to inject external scripts, the methods you will use are `builder()` and `patch_point()`.
|
||||
Among them, `patch_point()` obtains the name of the current event, and `builder()` obtains the BuilderBase object.
|
||||
|
||||
Because the incoming patch point does not distinguish between events,
|
||||
you must write the code you want to execute in `if(patch_point() === 'your_event_name')`,
|
||||
otherwise it will be executed repeatedly in other events.
|
||||
|
||||
The following are the supported `patch_point` event names and corresponding locations:
|
||||
|
||||
| Event name | Event description |
|
||||
|---------------------------------|----------------------------------------------------------------------------------------------------|
|
||||
| before-libs-extract | Triggered before the dependent libraries extracted |
|
||||
| after-libs-extract | Triggered after the compiled dependent libraries extracted |
|
||||
| before-php-extract | Triggered before PHP source code extracted |
|
||||
| after-php-extract | Triggered after PHP source code extracted |
|
||||
| before-micro-extract | Triggered before phpmicro extract |
|
||||
| after-micro-extract | Triggered after phpmicro extracted |
|
||||
| before-exts-extract | Triggered before the extension (to be compiled) extracted to the PHP source directory |
|
||||
| after-exts-extract | Triggered after the extension extracted to the PHP source directory |
|
||||
| before-library[*name*]-build | Triggered before the library named `name` is compiled (such as `before-library[postgresql]-build`) |
|
||||
| after-library[*name*]-build | Triggered after the library named `name` is compiled |
|
||||
| after-shared-ext[*name*]-build | Triggered after the shared extension named `name` is compiled |
|
||||
| before-shared-ext[*name*]-build | Triggered before the shared extension named `name` is compiled |
|
||||
| before-php-buildconf | Triggered before compiling PHP command `./buildconf` |
|
||||
| before-php-configure | Triggered before compiling PHP command `./configure` |
|
||||
| before-php-make | Triggered before compiling PHP command `make` |
|
||||
| before-sanity-check | Triggered after compiling PHP but before running extended checks |
|
||||
|
||||
The following is a simple example of temporarily modifying the PHP source code.
|
||||
Enable the CLI function to search for the `php.ini` configuration in the current working directory:
|
||||
|
||||
```php
|
||||
// a.php
|
||||
<?php
|
||||
// patch it before `./buildconf` executed
|
||||
if (patch_point() === 'before-php-buildconf') {
|
||||
\SPC\store\FileSystem::replaceFileStr(
|
||||
SOURCE_PATH . '/php-src/sapi/cli/php_cli.c',
|
||||
'sapi_module->php_ini_ignore_cwd = 1;',
|
||||
'sapi_module->php_ini_ignore_cwd = 0;'
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
bin/spc build mbstring --build-cli -P a.php
|
||||
# Write in ./
|
||||
echo 'memory_limit=8G' > ./php.ini
|
||||
```
|
||||
|
||||
```
|
||||
$ buildroot/bin/php -i | grep Loaded
|
||||
Loaded Configuration File => /Users/jerry/project/git-project/static-php-cli/php.ini
|
||||
|
||||
$ buildroot/bin/php -i | grep memory
|
||||
memory_limit => 8G => 8G
|
||||
```
|
||||
|
||||
For the objects, methods and interfaces supported by static-php-cli, you can read the source code. Most methods and objects have corresponding comments.
|
||||
|
||||
Commonly used objects and functions using the `-P` function are:
|
||||
|
||||
- `SPC\store\FileSystem`: file management class
|
||||
- `::replaceFileStr(string $filename, string $search, $replace)`: Replace file string content
|
||||
- `::replaceFileStr(string $filename, string $pattern, $replace)`: Regularly replace file content
|
||||
- `::replaceFileUser(string $filename, $callback)`: User-defined function replaces file content
|
||||
- `::copyDir(string $from, string $to)`: Recursively copy a directory to another location
|
||||
- `::convertPath(string $path)`: Convert the path delimiter to the current system delimiter
|
||||
- `::scanDirFiles(string $dir, bool $recursive = true, bool|string $relative = false, bool $include_dir = false)`: Traverse directory files
|
||||
- `SPC\builder\BuilderBase`: Build object
|
||||
- `->getPatchPoint()`: Get the current injection point name
|
||||
- `->getOption(string $key, $default = null)`: Get command line and compile-time options
|
||||
- `->getPHPVersionID()`: Get the currently compiled PHP version ID
|
||||
- `->getPHPVersion()`: Get the currently compiled PHP version number
|
||||
- `->setOption(string $key, $value)`: Set options
|
||||
- `->setOptionIfNotExists(string $key, $value)`: Set option if option does not exist
|
||||
|
||||
::: tip
|
||||
static-php-cli has many open methods, which cannot be listed in the docs,
|
||||
but as long as it is a `public function` and is not marked as `@internal`, it theoretically can be called.
|
||||
:::
|
||||
|
||||
## Multiple builds
|
||||
|
||||
If you need to build multiple times locally, the following method can save you time downloading resources and compiling.
|
||||
|
||||
- If you only switch the PHP version without changing the dependent libraries, you can use `bin/spc switch-php-version` to quickly switch the PHP version, and then re-run the same `build` command.
|
||||
- If you want to rebuild once, but do not re-download the source code, you can first `rm -rf buildroot source` to delete the compilation directory and source code directory, and then rebuild.
|
||||
- If you want to update a version of a dependency, you can use `bin/spc del-download <source-name>` to delete the specified source code, and then use `download <source-name>` to download it again.
|
||||
- If you want to update all dependent versions, you can use `bin/spc download --clean` to delete all downloaded sources, and then download them again.
|
||||
|
||||
## embed usage
|
||||
|
||||
If you want to embed static-php into other C language programs, you can use `--build-embed` to build an embed version of PHP.
|
||||
|
||||
```bash
|
||||
bin/spc build {your extensions} --build-embed --debug
|
||||
```
|
||||
|
||||
Under normal circumstances, PHP embed will generate `php-config` after compilation.
|
||||
For static-php, we provide `spc-config` to obtain the parameters during compilation.
|
||||
In addition, when using embed SAPI (libphp.a), you need to use the same compiler as libphp, otherwise there will be a link error.
|
||||
|
||||
Here is the basic usage of spc-config:
|
||||
|
||||
```bash
|
||||
# output all flags and options
|
||||
bin/spc spc-config curl,zlib,phar,openssl
|
||||
|
||||
# output libs
|
||||
bin/spc spc-config curl,zlib,phar,openssl --libs
|
||||
|
||||
# output includes
|
||||
bin/spc spc-config curl,zlib,phar,openssl --includes
|
||||
```
|
||||
|
||||
By default, static-php uses the following compilers on different systems:
|
||||
|
||||
- macOS: `clang`
|
||||
- Linux (Alpine Linux): `gcc`
|
||||
- Linux (glibc based distros, x86_64): `/usr/local/musl/bin/x86_64-linux-musl-gcc`
|
||||
- Linux (glibc based distros, aarch64): `/usr/local/musl/bin/aarch64-linux-musl-gcc`
|
||||
- FreeBSD: `clang`
|
||||
|
||||
Here is an example of using embed SAPI:
|
||||
|
||||
```c
|
||||
// embed.c
|
||||
#include <sapi/embed/php_embed.h>
|
||||
|
||||
int main(int argc,char **argv){
|
||||
|
||||
PHP_EMBED_START_BLOCK(argc,argv)
|
||||
|
||||
zend_file_handle file_handle;
|
||||
|
||||
zend_stream_init_filename(&file_handle,"embed.php");
|
||||
|
||||
if(php_execute_script(&file_handle) == FAILURE){
|
||||
php_printf("Failed to execute PHP script.\n");
|
||||
}
|
||||
|
||||
PHP_EMBED_END_BLOCK()
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
```php
|
||||
<?php
|
||||
// embed.php
|
||||
echo "Hello world!\n";
|
||||
```
|
||||
|
||||
```bash
|
||||
# compile in debian/ubuntu x86_64
|
||||
/usr/local/musl/bin/x86_64-linux-musl-gcc embed.c $(bin/spc spc-config bcmath,zlib) -static -o embed
|
||||
# compile in macOS/FreeBSD
|
||||
clang embed.c $(bin/spc spc-config bcmath,zlib) -o embed
|
||||
|
||||
./embed
|
||||
# out: Hello world!
|
||||
```
|
||||
@@ -1,42 +0,0 @@
|
||||
# Troubleshooting
|
||||
|
||||
Various failures may be encountered in the process of using static-php-cli,
|
||||
here will describe how to check the errors by yourself and report Issue.
|
||||
|
||||
## Download Failure
|
||||
|
||||
Problems with downloading resources are one of the most common problems with spc.
|
||||
The main reason is that the addresses used for SPC download resources are generally the official website of the corresponding project or GitHub, etc.,
|
||||
and these websites may occasionally go down and block IP addresses.
|
||||
After encountering a download failure,
|
||||
you can try to call the download command multiple times.
|
||||
|
||||
When downloading extensions, you may eventually see errors like `curl: (56) The requested URL returned error: 403` which are often caused by github rate limiting.
|
||||
You can verify this by adding `--debug` to the command and will see something like `[DEBU] Running command (no output) : curl -sfSL "https://api.github.com/repos/openssl/openssl/releases"`.
|
||||
|
||||
To fix this, [create](https://github.com/settings/tokens) a personal access token on GitHub and set it as an environment variable `GITHUB_TOKEN=<XXX>`.
|
||||
|
||||
If you confirm that the address is indeed inaccessible,
|
||||
you can submit an Issue or PR to update the url or download type.
|
||||
|
||||
## Doctor Can't Fix Something
|
||||
|
||||
In most cases, the doctor module can automatically repair and install missing system environments,
|
||||
but there are also special circumstances where the automatic repair function cannot be used normally.
|
||||
|
||||
Due to system limitations (for example, software such as Visual Studio cannot be automatically installed under Windows),
|
||||
the automatic repair function cannot be used for some projects.
|
||||
When encountering a function that cannot be automatically repaired,
|
||||
if you encounter the words `Some check items can not be fixed`,
|
||||
it means that it cannot be automatically repaired.
|
||||
Please submit an issue according to the method displayed on the terminal or repair the environment yourself.
|
||||
|
||||
## Compile Error
|
||||
|
||||
When you encounter a compilation error, if the `--debug` log is not enabled, please enable the debug log first,
|
||||
and then determine the command that reported the error.
|
||||
The error terminal output is very important for fixing compilation errors.
|
||||
When submitting an issue, please upload the last error fragment of the terminal log (or the entire terminal log output),
|
||||
and include the `spc` command and parameters used.
|
||||
|
||||
If you are rebuilding, please refer to the [Local Build - Multiple Builds](./manual-build#multiple-builds) section.
|
||||
142
docs/en/index.md
142
docs/en/index.md
@@ -1,142 +0,0 @@
|
||||
---
|
||||
# https://vitepress.dev/reference/default-theme-home-page
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: "Static PHP"
|
||||
tagline: "Build standalone PHP binary on Linux, macOS, FreeBSD, Windows, with PHP project together, with popular extensions included."
|
||||
image:
|
||||
src: /images/static-php_nobg.png
|
||||
alt: Static PHP CLI Logo
|
||||
actions:
|
||||
- theme: brand
|
||||
text: Get Started
|
||||
link: ./guide/
|
||||
|
||||
features:
|
||||
- title: Static CLI Binary
|
||||
details: You can easily compile a standalone php binary for general use. Including CLI, FPM sapi.
|
||||
- title: Micro Self-Extracted Executable
|
||||
details: You can compile a self-extracted executable and build with your php source code.
|
||||
- title: Dependency Management
|
||||
details: static-php-cli comes with dependency management and supports installation of different types of PHP extensions.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import {VPSponsors} from "vitepress/theme";
|
||||
import Contributors from '../.vitepress/components/Contributors.vue';
|
||||
|
||||
const sponsors = [
|
||||
{ name: 'Beyond Code', img: '/images/beyondcode-seeklogo.png', url: 'https://beyondco.de/' },
|
||||
{ name: 'NativePHP', img: '/images/nativephp-logo.svg', url: 'https://nativephp.com/' },
|
||||
];
|
||||
</script>
|
||||
|
||||
<div class="sponsors-section">
|
||||
<div class="sponsors-header">
|
||||
<h2>Special Sponsors</h2>
|
||||
<p class="sponsors-description">
|
||||
Thank you to our amazing sponsors for supporting this project!
|
||||
</p>
|
||||
</div>
|
||||
<VPSponsors :data="sponsors"/>
|
||||
</div>
|
||||
|
||||
<style scoped>
|
||||
.sponsors-section {
|
||||
margin: 48px auto;
|
||||
padding: 32px 24px;
|
||||
max-width: 1152px;
|
||||
background: linear-gradient(135deg, var(--vp-c-bg-soft) 0%, var(--vp-c-bg) 100%);
|
||||
border-radius: 16px;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.sponsors-section:hover {
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.sponsors-header {
|
||||
text-align: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.sponsors-header h2 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px 0;
|
||||
background: linear-gradient(120deg, var(--vp-c-brand-1), var(--vp-c-brand-2));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.sponsors-description {
|
||||
font-size: 0.95rem;
|
||||
color: var(--vp-c-text-2);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.sponsors-section {
|
||||
margin: 32px 16px;
|
||||
padding: 24px 16px;
|
||||
}
|
||||
|
||||
.sponsors-header h2 {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.sponsors-description {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Hero logo styling */
|
||||
:deep(.VPImage.image-src) {
|
||||
border-radius: 20px;
|
||||
background: linear-gradient(135deg, var(--vp-c-bg-soft) 0%, var(--vp-c-default-soft) 100%);
|
||||
padding: 40px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
:deep(.VPImage.image-src:hover) {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
/* Dark mode adjustments for logo */
|
||||
.dark :deep(.VPImage.image-src) {
|
||||
background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.dark :deep(.VPImage.image-src:hover) {
|
||||
opacity: 1;
|
||||
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
/* Additional styling for the logo image itself */
|
||||
:deep(.VPImage.image-src img) {
|
||||
max-height: 280px;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
:deep(.VPImage.image-src) {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
:deep(.VPImage.image-src img) {
|
||||
max-height: 200px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<Contributors />
|
||||
@@ -1 +0,0 @@
|
||||
> This file is dynamically generated by `bin/spc dev:gen-ext-docs` command.
|
||||
147
docs/index.md
147
docs/index.md
@@ -1,147 +0,0 @@
|
||||
---
|
||||
# https://vitepress.dev/reference/default-theme-home-page
|
||||
layout: home
|
||||
|
||||
hero:
|
||||
name: "Static PHP"
|
||||
tagline: "Build standalone PHP binary on Linux, macOS, FreeBSD, Windows, with PHP project together, with popular extensions included."
|
||||
image:
|
||||
src: /images/static-php_nobg.png
|
||||
alt: Static PHP CLI Logo
|
||||
actions:
|
||||
- theme: brand
|
||||
text: Get Started
|
||||
link: /en/guide/
|
||||
- theme: alt
|
||||
text: 中文文档
|
||||
link: /zh/
|
||||
|
||||
features:
|
||||
- title: Static CLI Binary
|
||||
details: You can easily compile a standalone php binary for general use. Including CLI, FPM sapi.
|
||||
- title: Micro Self-Extracted Executable
|
||||
details: You can compile a self-extracted executable and build with your php source code.
|
||||
- title: Dependency Management
|
||||
details: static-php-cli comes with dependency management and supports installation of different types of PHP extensions.
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import {VPSponsors} from "vitepress/theme";
|
||||
import Contributors from './.vitepress/components/Contributors.vue';
|
||||
|
||||
const sponsors = [
|
||||
{ name: 'Beyond Code', img: '/images/beyondcode-seeklogo.png', url: 'https://beyondco.de/' },
|
||||
{ name: 'NativePHP', img: '/images/nativephp-logo.svg', url: 'https://nativephp.com/' },
|
||||
];
|
||||
</script>
|
||||
|
||||
<div class="sponsors-section">
|
||||
<div class="sponsors-header">
|
||||
<h2>Special Sponsors</h2>
|
||||
<p class="sponsors-description">
|
||||
Thank you to our amazing sponsors for supporting this project!
|
||||
</p>
|
||||
</div>
|
||||
<VPSponsors :data="sponsors"/>
|
||||
</div>
|
||||
|
||||
<style scoped>
|
||||
.sponsors-section {
|
||||
margin: 48px auto;
|
||||
padding: 32px 24px;
|
||||
max-width: 1152px;
|
||||
background: linear-gradient(135deg, var(--vp-c-bg-soft) 0%, var(--vp-c-bg) 100%);
|
||||
border-radius: 16px;
|
||||
border: 1px solid var(--vp-c-divider);
|
||||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.05);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
.sponsors-section:hover {
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
|
||||
transform: translateY(-2px);
|
||||
}
|
||||
|
||||
.sponsors-header {
|
||||
text-align: center;
|
||||
margin-bottom: 24px;
|
||||
}
|
||||
|
||||
.sponsors-header h2 {
|
||||
font-size: 1.5rem;
|
||||
font-weight: 700;
|
||||
margin: 0 0 8px 0;
|
||||
background: linear-gradient(120deg, var(--vp-c-brand-1), var(--vp-c-brand-2));
|
||||
-webkit-background-clip: text;
|
||||
-webkit-text-fill-color: transparent;
|
||||
background-clip: text;
|
||||
}
|
||||
|
||||
.sponsors-description {
|
||||
font-size: 0.95rem;
|
||||
color: var(--vp-c-text-2);
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
.sponsors-section {
|
||||
margin: 32px 16px;
|
||||
padding: 24px 16px;
|
||||
}
|
||||
|
||||
.sponsors-header h2 {
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.sponsors-description {
|
||||
font-size: 0.9rem;
|
||||
}
|
||||
}
|
||||
|
||||
/* Hero logo styling */
|
||||
:deep(.VPImage.image-src) {
|
||||
border-radius: 20px;
|
||||
background: linear-gradient(135deg, var(--vp-c-bg-soft) 0%, var(--vp-c-default-soft) 100%);
|
||||
padding: 40px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
:deep(.VPImage.image-src:hover) {
|
||||
transform: translateY(-4px);
|
||||
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
|
||||
}
|
||||
|
||||
/* Dark mode adjustments for logo */
|
||||
.dark :deep(.VPImage.image-src) {
|
||||
background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
|
||||
opacity: 0.9;
|
||||
}
|
||||
|
||||
.dark :deep(.VPImage.image-src:hover) {
|
||||
opacity: 1;
|
||||
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.7);
|
||||
}
|
||||
|
||||
/* Additional styling for the logo image itself */
|
||||
:deep(.VPImage.image-src img) {
|
||||
max-height: 280px;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
@media (max-width: 768px) {
|
||||
:deep(.VPImage.image-src) {
|
||||
padding: 24px;
|
||||
}
|
||||
|
||||
:deep(.VPImage.image-src img) {
|
||||
max-height: 200px;
|
||||
}
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
<Contributors />
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
static-php.dev
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 29 KiB |
@@ -1,6 +0,0 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 764 100">
|
||||
<path fill="#505b93" d="M29.5,98.4H0V1.2h29.5V98.4z"/>
|
||||
<path fill="#00aaa6" d="M96.7,98.4H67.2V1.2h29.5V98.4z"/>
|
||||
<path fill="#272d48" d="M96.7,98.4H29.5V1.2L96.7,98.4z"/>
|
||||
<path fill="#272d48" d="M102.6,54.5c0-6.2,1.3-11.8,4.1-16.7c2.7-5,6.7-8.8,11.9-11.6c5.2-2.8,11.4-4.2,18.6-4.2c1.1,0,2.8,0.1,5.2,0.3 c4.9,0.4,9.1,1.3,12.5,2.8c3.4,1.5,6.4,3.4,9.1,5.9v-7.2h25.8v74.7h-25.8v-7.2c-2.5,2.6-5.6,4.6-9.4,6.1c-3.8,1.5-7.9,2.4-12.1,2.6 c-0.9,0.1-2.3,0.1-4.1,0.1c-7.2,0-13.4-1.4-18.8-4.1c-5.4-2.7-9.5-6.6-12.4-11.5c-2.9-4.9-4.3-10.5-4.3-16.6V54.5z M128.4,63.9 c0,9.2,5.9,13.8,17.7,13.8c11.8,0,17.7-4.6,17.7-13.8v-5.6c0-9.3-5.9-14-17.7-14c-11.8,0-17.7,4.7-17.7,14V63.9z M208.3,98.4V47h-12.8V23.7l12.8-0.2V1.2h25.9l0.1,22.4h18.3V47h-18.4v51.4 M287.3,98.4h-25.9V23.6h25.9V98.4z M351,98.4H325l-31-74.8H320L338,68l18-44.5h25.9L351,98.4z M454.9,87.6c-4.1,4.2-8.8,7.3-14.1,9.3c-5.3,2-11.8,2.9-19.5,2.9c-8,0-15.1-1.4-21.3-4.2 c-6.2-2.8-11.1-6.7-14.7-11.6c-3.5-5-5.3-10.6-5.3-17V54.6c0-6.5,1.7-12.2,5.2-17.1c3.4-4.9,8.2-8.7,14.2-11.3c6-2.7,12.7-4,20-4 c8,0,15,1.5,21.2,4.3c6.1,2.9,10.9,7,14.4,12.4c3.4,5.4,5.2,11.6,5.2,18.7c0,1.7-0.2,4.2-0.7,7.7l-54.2,0.1v2.1 c0,4.1,1.5,7.3,4.4,9.4c2.9,2.2,6.9,3.2,11.8,3.2c4.6,0,8.5-0.6,11.8-1.8c3.2-1.2,6.4-3.5,9.4-6.8L454.9,87.6z M434.4,51.4 c0-3.1-1.4-5.5-4.2-7.1c-2.8-1.6-6.4-2.4-10.8-2.4s-7.9,0.8-10.5,2.4c-2.6,1.6-3.8,4-3.8,7.1H434.4z M466,98.4V1.2h56c9.9,0,17.8,1.9,23.7,5.6c5.9,3.7,10,8.2,12.2,13.3c2.3,5.1,3.4,10.1,3.4,15 c0,4.8-1.2,9.7-3.5,14.7c-2.3,5-6.4,9.2-12.2,12.8c-5.8,3.6-13.7,5.4-23.7,5.4h-30.2v30.5H466z M522,44.6c9,0,13.6-3.3,13.6-9.9 c0-6.9-4.6-10.3-13.7-10.3h-30.1v20.2H522z M593,98.4h-25.8V1.2H593v38h43.9v-38h25.8v97.2h-25.8V59.9H593V98.4z M668.6,98.4V1.2h56c9.9,0,17.8,1.9,23.7,5.6c5.9,3.7,10,8.2,12.2,13.3c2.3,5.1,3.4,10.1,3.4,15 c0,4.8-1.2,9.7-3.5,14.7c-2.3,5-6.4,9.2-12.2,12.8c-5.8,3.6-13.7,5.4-23.7,5.4h-30.2v30.5H668.6z M724.6,44.6c9,0,13.6-3.3,13.6-9.9 c0-6.9-4.6-10.3-13.7-10.3h-30.1v20.2H724.6z M291.1,20.2h-33.5V0h33.5V20.2z"/>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 965 KiB |
@@ -1,51 +0,0 @@
|
||||
# 贡献指南
|
||||
|
||||
感谢你能够看到这里,本项目非常欢迎你的贡献!
|
||||
|
||||
## 贡献方法
|
||||
|
||||
如果你有代码或文档要贡献,以下是你需要首先了解的内容。
|
||||
|
||||
1. 你要贡献什么类型的代码?(新扩展、修复 Bug、安全问题、项目框架优化、文档)
|
||||
2. 如果你贡献了新文件或新片段,你的代码是否经过 `php-cs-fixer` 和 `phpstan` 的检查?
|
||||
3. 在贡献代码前是否充分阅读了 [开发指南](../develop/)?
|
||||
|
||||
如果你能回答上述问题并对代码进行了修改,可以及时在项目 GitHub 仓库发起 Pull Request。
|
||||
代码审查完成后,可以根据建议修改代码,或直接合并到主分支。
|
||||
|
||||
## 贡献类型
|
||||
|
||||
本项目的主要目的是编译静态链接的 PHP 二进制文件,命令行处理功能基于 `symfony/console` 编写。
|
||||
在开发之前,如果你对它不够熟悉,请先查看 [symfony/console 文档](https://symfony.com/doc/current/components/console.html)。
|
||||
|
||||
### 安全更新
|
||||
|
||||
因为本项目基本上是一个本地运行的 PHP 项目,一般来说不会有远程攻击。
|
||||
但如果你发现此类问题,请**不要**在 GitHub 仓库提交 PR 或 Issue,
|
||||
你需要通过 [邮件](mailto:admin@zhamao.me) 联系项目维护者(crazywhalecc)。
|
||||
|
||||
### 修复 Bug
|
||||
|
||||
修复 Bug 一般不涉及项目结构和框架的修改,所以如果你能定位到错误代码并直接修复它,请直接提交 PR。
|
||||
|
||||
### 新扩展
|
||||
|
||||
对于添加新扩展,你需要了解项目的一些基本结构以及如何根据现有逻辑添加新扩展。
|
||||
这将在本页的下一节中详细介绍。
|
||||
总的来说,你需要:
|
||||
|
||||
1. 评估扩展是否可以内联编译到 PHP 中。
|
||||
2. 评估扩展的依赖库(如果有)是否可以静态编译。
|
||||
3. 编写不同平台的库编译命令。
|
||||
4. 验证扩展及其依赖项与现有扩展和依赖项兼容。
|
||||
5. 验证扩展在 `cli`、`micro`、`fpm`、`embed` SAPIs 中正常工作。
|
||||
6. 编写文档并添加你的扩展。
|
||||
|
||||
### 项目框架优化
|
||||
|
||||
如果你已经熟悉 `symfony/console` 的工作原理,并同时要对项目的框架进行一些修改或优化,请先了解以下事情:
|
||||
|
||||
1. 添加扩展不属于项目框架优化,但如果你在添加新扩展时发现必须优化框架,则需要先修改框架本身,然后再添加扩展。
|
||||
2. 对于一些大规模逻辑修改(例如涉及 LibraryBase、Extension 对象等的修改),建议先提交 Issue 或 Draft PR 进行讨论。
|
||||
3. 在项目早期,它是一个纯私有开发项目,代码中有一些中文注释。项目国际化后,你可以提交 PR 将这些注释翻译为英语。
|
||||
4. 请不要在代码中提交更多无用的代码片段,例如大量未使用的变量、方法、类以及多次重写的代码。
|
||||
@@ -1,7 +0,0 @@
|
||||
---
|
||||
aside: false
|
||||
---
|
||||
|
||||
# craft.yml 配置
|
||||
|
||||
<!--@include: ../../deps-craft-yml.md-->
|
||||
@@ -1,60 +0,0 @@
|
||||
# Doctor 模块
|
||||
|
||||
Doctor 模块是一个较为独立的用于检查系统环境的模块,可使用命令 `bin/spc doctor` 进入,入口的命令类在 `DoctorCommand.php` 中。
|
||||
|
||||
Doctor 模块是一个检查单,里面有一系列的检查项目和自动修复项目。这些项目都存放在 `src/SPC/doctor/item/` 目录中,
|
||||
并且使用了两种 Attribute 用作检查项标记和自动修复项目标记:`#[AsCheckItem]` 和 `#[AsFixItem]`。
|
||||
|
||||
以现有的检查项 `if necessary tools are installed`,它是用于检查编译必需的包是否安装在 macOS 系统内,下面是它的源码:
|
||||
|
||||
```php
|
||||
use SPC\doctor\AsCheckItem;
|
||||
use SPC\doctor\AsFixItem;
|
||||
use SPC\doctor\CheckResult;
|
||||
|
||||
#[AsCheckItem('if necessary tools are installed', limit_os: 'Darwin', level: 997)]
|
||||
public function checkCliTools(): ?CheckResult
|
||||
{
|
||||
$missing = [];
|
||||
foreach (self::REQUIRED_COMMANDS as $cmd) {
|
||||
if ($this->findCommand($cmd) === null) {
|
||||
$missing[] = $cmd;
|
||||
}
|
||||
}
|
||||
if (!empty($missing)) {
|
||||
return CheckResult::fail('missing system commands: ' . implode(', ', $missing), 'build-tools', [$missing]);
|
||||
}
|
||||
return CheckResult::ok();
|
||||
}
|
||||
```
|
||||
|
||||
属性的第一个参数就是检查项目的名称,后面的 `limit_os` 参数是限制了该检查项仅在指定的系统下触发,`level` 是执行该检查项的优先级,数字越大,优先级越高。
|
||||
|
||||
里面用到的 `$this->findCommand()` 方法为 `SPC\builder\traits\UnixSystemUtilTrait` 的方法,用途是查找系统命令所在位置,找不到时返回 NULL。
|
||||
|
||||
每个检查项的方法都应该返回一个 `SPC\doctor\CheckResult`:
|
||||
|
||||
- 在返回 `CheckResult::fail()` 时,第一个参数用于输出终端的错误提示,第二个参数是在这个检查项可自动修复时的修复项目名称。
|
||||
- 在返回 `CheckResult::ok()` 时,表明检查通过。你也可以传递一个参数,用于返回检查结果,例如:`CheckResult::ok('OS supported')`。
|
||||
- 在返回 `CheckResult::fail()` 时,如果包含了第三个参数,第三个参数的数组将被当作 `AsFixItem` 的参数。
|
||||
|
||||
下面是这个检查项对应的自动修复项的方法:
|
||||
|
||||
```php
|
||||
#[AsFixItem('build-tools')]
|
||||
public function fixBuildTools(array $missing): bool
|
||||
{
|
||||
foreach ($missing as $cmd) {
|
||||
try {
|
||||
shell(true)->exec('brew install ' . escapeshellarg($cmd));
|
||||
} catch (RuntimeException) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
```
|
||||
|
||||
`#[AsFixItem()]` 属性传入的参数即修复项的名称,该方法必须返回 True 或 False。当返回 False 时,表明自动修复失败,需要手动处理。
|
||||
|
||||
此处的代码中 `shell()->exec()` 是项目的执行命令的方法,用于替代 `exec()`、`system()`,同时提供了 debug、获取执行状态、进入目录等特性。
|
||||
@@ -1,27 +0,0 @@
|
||||
# 开发简介
|
||||
|
||||
开发本项目需要安装部署 PHP 环境,以及一些 PHP 项目常用的扩展和 Composer。
|
||||
|
||||
项目的开发环境和运行环境几乎完全一致。你可以参照 **手动构建** 部分安装系统 PHP 或使用本项目预构建的静态 PHP 作为环境。这里不再赘述。
|
||||
|
||||
抛开用途,本项目本身其实就是一个 `php-cli` 程序,你可以将它当作一个正常的 PHP 项目进行编辑和开发,同时你需要了解不同系统的 Shell 命令行。
|
||||
|
||||
本项目目前的目的就是为了编译静态编译的独立 PHP,但主体部分也包含编译很多依赖库的静态版本,所以你可以复用这套编译逻辑,用于构建其他程序的独立二进制版本,例如 Nginx 等。
|
||||
|
||||
## 环境准备
|
||||
|
||||
开发本项目需要 PHP 环境。你可以使用系统自带的 PHP,也可以使用本项目构建的静态 PHP。
|
||||
|
||||
无论是使用哪种 PHP,在开发环境,你需要安装这些扩展:
|
||||
|
||||
```
|
||||
curl,dom,filter,mbstring,openssl,pcntl,phar,posix,sodium,tokenizer,xml,xmlwriter
|
||||
```
|
||||
|
||||
static-php-cli 项目本身不需要这么多扩展,但在开发过程中,你会用到 Composer 和 PHPUnit 等工具,它们需要这些扩展。
|
||||
|
||||
> 对于 static-php-cli 自身构建的 micro 自执行二进制,仅需要 `pcntl,posix,mbstring,tokenizer,phar`。
|
||||
|
||||
## 开始开发
|
||||
|
||||
继续向下查看项目结构文档,你可以学习 `static-php-cli` 是如何工作的。
|
||||
@@ -1,51 +0,0 @@
|
||||
# 对 PHP 源码的修改
|
||||
|
||||
由于 static-php-cli 在静态编译过程中为了实现良好的兼容性、性能和安全性,对 PHP 源码进行了一些修改。下面是目前对 PHP 源码修改的说明。
|
||||
|
||||
## micro 相关补丁
|
||||
|
||||
基于 phpmicro 项目提供的补丁,static-php-cli 对 PHP 源码进行了一些修改,以适应静态编译的需求。[补丁列表](https://github.com/easysoft/phpmicro/tree/master/patches) 包含:
|
||||
|
||||
目前 static-php-cli 在编译时用到的补丁有:
|
||||
|
||||
- static_opcache
|
||||
- static_extensions_win32
|
||||
- cli_checks
|
||||
- disable_huge_page
|
||||
- vcruntime140
|
||||
- win32
|
||||
- zend_stream
|
||||
- cli_static
|
||||
- macos_iconv
|
||||
- phar
|
||||
|
||||
## PHP <= 8.1 libxml 补丁
|
||||
|
||||
因为 PHP 官方仅对 8.1 进行安全更新,旧版本停止更新,所以 static-php-cli 对 PHP 8.1 及以下版本应用了在新版本 PHP 中已经应用的 libxml 编译补丁。
|
||||
|
||||
## gd 扩展 Windows 补丁
|
||||
|
||||
在 Windows 下编译 gd 扩展需要大幅改动 `config.w32` 文件,static-php-cli 对 gd 扩展进行了一些修改,使其在 Windows 下编译更加方便。
|
||||
|
||||
## yaml 扩展 Windows 补丁
|
||||
|
||||
yaml 扩展在 Windows 下编译需要修改 `config.w32` 文件,static-php-cli 对 yaml 扩展进行了一些修改,使其在 Windows 下编译更加方便。
|
||||
|
||||
## static-php-cli 版本信息插入
|
||||
|
||||
static-php-cli 在编译时会在 PHP 版本信息中插入 static-php-cli 的版本信息,以便于识别。
|
||||
|
||||
## 加入硬编码 INI 的选项
|
||||
|
||||
在使用 `-I` 参数硬编码 INI 到静态 PHP 的功能中,static-php-cli 会修改 PHP 源码以插入硬编码内容。
|
||||
|
||||
## Linux 系统修复补丁
|
||||
|
||||
部分编译环境可能缺少一些头文件或库,static-php-cli 会在编译时自动修复这些问题,如:
|
||||
|
||||
- HAVE_STRLCAT missing problem
|
||||
- HAVE_STRLCPY missing problem
|
||||
|
||||
## Windows 系统下 Fiber 问题修复补丁
|
||||
|
||||
在 Windows 下编译 PHP 时,Fiber 扩展会出现一些问题,static-php-cli 会在编译时自动修复这些问题(修改 php-src 的 `config.w32`)。
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user