mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-17 20:34:51 +08:00
Switch static-php-cli to support PHP 8.3 and 8.4 only (#615)
* Update spc self to PHP 8.4 only * Update workflows * Fix test-extensions, adjust docs order * Fix cs-fix and phpunit * Add PHP_CS_FIXER_IGNORE_ENV * Add compatibility for PHP 8.3 * Change version description in README, adjust composer.json PHP version limit * Switch PHP to 8.4 in spc-alpine-docker * Add deprecation notice
This commit is contained in:
parent
8a17e2384e
commit
29ea46bd17
2
.github/workflows/build-unix.yml
vendored
2
.github/workflows/build-unix.yml
vendored
@ -129,7 +129,7 @@ jobs:
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: ${{ inputs.php-version }}
|
||||
php-version: 8.4
|
||||
tools: pecl, composer
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
|
||||
2
.github/workflows/build-windows-x86_64.yml
vendored
2
.github/workflows/build-windows-x86_64.yml
vendored
@ -6,7 +6,7 @@ on:
|
||||
version:
|
||||
required: true
|
||||
description: php version to compile
|
||||
default: '8.2'
|
||||
default: '8.4'
|
||||
type: choice
|
||||
options:
|
||||
- '8.4'
|
||||
|
||||
2
.github/workflows/ext-matrix-tests.yml
vendored
2
.github/workflows/ext-matrix-tests.yml
vendored
@ -113,7 +113,7 @@ jobs:
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.2
|
||||
php-version: 8.4
|
||||
tools: pecl, composer
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
|
||||
4
.github/workflows/release-build.yml
vendored
4
.github/workflows/release-build.yml
vendored
@ -9,8 +9,8 @@ on:
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
PHP_VERSION: 8.2
|
||||
MICRO_VERSION: 8.2.18
|
||||
PHP_VERSION: 8.4
|
||||
MICRO_VERSION: 8.4.4
|
||||
|
||||
jobs:
|
||||
build-release-artifacts:
|
||||
|
||||
13
.github/workflows/tests.yml
vendored
13
.github/workflows/tests.yml
vendored
@ -34,13 +34,13 @@ jobs:
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
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
|
||||
run: PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix --dry-run --diff --ansi
|
||||
|
||||
phpstan:
|
||||
runs-on: ubuntu-latest
|
||||
@ -52,7 +52,7 @@ jobs:
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: '8.1'
|
||||
php-version: '8.4'
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
tools: composer
|
||||
@ -79,9 +79,6 @@ jobs:
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- php: '8.1'
|
||||
- php: '8.2'
|
||||
- php: '8.3'
|
||||
- php: '8.4'
|
||||
|
||||
steps:
|
||||
@ -125,7 +122,7 @@ jobs:
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.2
|
||||
php-version: 8.4
|
||||
|
||||
- name: Define
|
||||
id: gendef
|
||||
@ -153,7 +150,7 @@ jobs:
|
||||
- name: "Setup PHP"
|
||||
uses: shivammathur/setup-php@v2
|
||||
with:
|
||||
php-version: 8.2
|
||||
php-version: 8.4
|
||||
tools: pecl, composer
|
||||
extensions: curl, openssl, mbstring
|
||||
ini-values: memory_limit=-1
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,6 +32,7 @@ packlib_files.txt
|
||||
!/bin/spc*
|
||||
!/bin/setup-runtime*
|
||||
!/bin/spc-alpine-docker
|
||||
!/bin/php-cs-fixer-wrapper
|
||||
|
||||
# exclude windows build tools
|
||||
/php-sdk-binary-tools/
|
||||
|
||||
@ -64,6 +64,8 @@ return (new PhpCsFixer\Config())
|
||||
'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'])
|
||||
|
||||
@ -58,7 +58,7 @@ static-php-cli(简称 `spc`)有许多特性:
|
||||
|
||||
### 编译环境需求
|
||||
|
||||
- PHP >= 8.1(这是 spc 自身需要的版本,不是支持的构建版本)
|
||||
- PHP >= 8.4(这是 spc 自身需要的版本,不是支持的构建版本)
|
||||
- 扩展:`mbstring,tokenizer,phar`
|
||||
- 系统安装了 `curl` 和 `git`
|
||||
|
||||
@ -180,6 +180,9 @@ bin/spc --version
|
||||
# 检查环境依赖,并根据尝试自动安装缺失的编译工具
|
||||
./bin/spc doctor --auto-fix
|
||||
|
||||
# 输出目标项目依赖的扩展列表
|
||||
./bin/spc dump-extensions /path/to/your/project --format=text
|
||||
|
||||
# 拉取所有依赖库
|
||||
./bin/spc download --all
|
||||
# 只拉取编译指定扩展需要的所有依赖(推荐)
|
||||
|
||||
@ -67,7 +67,7 @@ which can be downloaded directly according to your needs.
|
||||
You can say I made a PHP builder written in PHP, pretty funny.
|
||||
But static-php-cli runtime only requires an environment above PHP 8.1 and extensions mentioned below.
|
||||
|
||||
- PHP >= 8.1 (This is the version required by spc itself, not the build version)
|
||||
- PHP >= 8.4 (This is the version required by spc itself, not the build version)
|
||||
- Extension: `mbstring,tokenizer,phar`
|
||||
- Supported OS with `curl` and `git` installed
|
||||
|
||||
@ -195,7 +195,7 @@ Basic usage for building php with some extensions:
|
||||
# fetch all libraries
|
||||
./bin/spc download --all
|
||||
# dump a list of extensions required by your project
|
||||
./bin/spc dump-extensions
|
||||
./bin/spc dump-extensions /path/to/your/project --format=text
|
||||
# only fetch necessary sources by needed extensions (recommended)
|
||||
./bin/spc download --for-extensions="openssl,pcntl,mbstring,pdo_sqlite"
|
||||
# download pre-built libraries first (save time for compiling dependencies)
|
||||
|
||||
4
bin/php-cs-fixer-wrapper
Executable file
4
bin/php-cs-fixer-wrapper
Executable file
@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# get parent dir, and run the php-cs-fixer
|
||||
PHP_CS_FIXER_IGNORE_ENV=1 "$(dirname "$0")/../vendor/bin/php-cs-fixer" "$@"
|
||||
@ -25,7 +25,7 @@ __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.2.13-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.4.4-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__COMPOSER_URL__="https://getcomposer.org/download/latest-stable/composer.phar"
|
||||
|
||||
# use china mirror
|
||||
@ -45,7 +45,7 @@ done
|
||||
|
||||
case "$mirror" in
|
||||
china)
|
||||
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.2.13-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__PHP_RUNTIME_URL__="https://dl.static-php.dev/static-php-cli/bulk/php-8.4.4-cli-${__OS_FIXED__}-${__ARCH__}.tar.gz"
|
||||
__COMPOSER_URL__="https://mirrors.tencent.com/composer/composer.phar"
|
||||
;;
|
||||
|
||||
@ -61,7 +61,7 @@ test -f "${__PROJECT__}"/downloads/runtime.tar.gz || { echo "Downloading $__PHP_
|
||||
test -f "${__DIR__}"/php || { tar -xf "${__PROJECT__}"/downloads/runtime.tar.gz -C "${__DIR__}"/ ; }
|
||||
chmod +x "${__DIR__}"/php
|
||||
# download composer
|
||||
test -f "${__DIR__}"/composer || curl -#fSL -o "${__DIR__}"/composer "$__COMPOSER_URL__"
|
||||
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; }
|
||||
|
||||
@ -51,7 +51,7 @@ if ($action -eq 'add-path') {
|
||||
}
|
||||
|
||||
# get php 8.1 specific version
|
||||
$API = (Invoke-WebRequest -Uri "https://www.php.net/releases/index.php?json&version=8.3") | ConvertFrom-Json
|
||||
$API = (Invoke-WebRequest -Uri "https://www.php.net/releases/index.php?json&version=8.4") | ConvertFrom-Json
|
||||
|
||||
# php windows download
|
||||
$PHPRuntimeUrl = "https://windows.php.net/downloads/releases/php-" + $API.version + "-nts-Win32-vs16-x64.zip"
|
||||
|
||||
5
bin/spc
5
bin/spc
@ -17,6 +17,11 @@ 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) {
|
||||
|
||||
@ -50,9 +50,9 @@ else
|
||||
fi
|
||||
|
||||
# Detect docker env is setup
|
||||
if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-$SPC_USE_ARCH; then
|
||||
if ! $DOCKER_EXECUTABLE images | grep -q cwcc-spc-$SPC_USE_ARCH-v2; then
|
||||
echo "Docker container does not exist. Building docker image ..."
|
||||
$DOCKER_EXECUTABLE build -t cwcc-spc-$SPC_USE_ARCH -f- . <<EOF
|
||||
$DOCKER_EXECUTABLE build -t cwcc-spc-$SPC_USE_ARCH-v2 -f- . <<EOF
|
||||
FROM $ALPINE_FROM
|
||||
$SPC_USE_MIRROR
|
||||
RUN apk update; \
|
||||
@ -79,21 +79,16 @@ RUN apk update; \
|
||||
linux-headers \
|
||||
m4 \
|
||||
make \
|
||||
php82 \
|
||||
php82-common \
|
||||
php82-pcntl \
|
||||
php82-phar \
|
||||
php82-posix \
|
||||
php82-sodium \
|
||||
php82-tokenizer \
|
||||
php82-dom \
|
||||
php82-xml \
|
||||
php82-xmlwriter \
|
||||
composer \
|
||||
pkgconfig \
|
||||
wget \
|
||||
xz
|
||||
|
||||
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/
|
||||
@ -124,4 +119,4 @@ MOUNT_LIST="$MOUNT_LIST -v ""$(pwd)""/pkgroot:/app/pkgroot"
|
||||
# shellcheck disable=SC2068
|
||||
# shellcheck disable=SC2086
|
||||
# shellcheck disable=SC2090
|
||||
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH bin/spc $@
|
||||
$DOCKER_EXECUTABLE run --rm $INTERACT -e SPC_FIX_DEPLOY_ROOT="$(pwd)" $MOUNT_LIST cwcc-spc-$SPC_USE_ARCH-v2 bin/spc $@
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": ">= 8.1",
|
||||
"php": ">= 8.3",
|
||||
"ext-mbstring": "*",
|
||||
"ext-zlib": "*",
|
||||
"laravel/prompts": "^0.1.12",
|
||||
@ -19,7 +19,7 @@
|
||||
"require-dev": {
|
||||
"captainhook/captainhook-phar": "^5.23",
|
||||
"captainhook/hook-installer": "^1.0",
|
||||
"friendsofphp/php-cs-fixer": "^3.25",
|
||||
"friendsofphp/php-cs-fixer": "^3.60",
|
||||
"humbug/box": "^4.5.0 || ^4.6.0",
|
||||
"nunomaduro/collision": "^7.8",
|
||||
"phpstan/phpstan": "^1.10",
|
||||
@ -44,7 +44,7 @@
|
||||
],
|
||||
"scripts": {
|
||||
"analyse": "phpstan analyse --memory-limit 300M",
|
||||
"cs-fix": "php-cs-fixer fix",
|
||||
"cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix",
|
||||
"test": "vendor/bin/phpunit tests/ --no-coverage",
|
||||
"build:phar": "vendor/bin/box compile"
|
||||
},
|
||||
|
||||
2702
composer.lock
generated
2702
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -57,56 +57,6 @@ cd static-php-cli
|
||||
composer update
|
||||
```
|
||||
|
||||
### 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.
|
||||
:::
|
||||
|
||||
### 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 Precompiled Static PHP Binaries
|
||||
|
||||
If you don't want to use Docker and install PHP in the system,
|
||||
@ -133,6 +83,56 @@ This script will download two files in total: `bin/php` and `bin/composer`. Afte
|
||||
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.
|
||||
:::
|
||||
|
||||
## Command - download
|
||||
|
||||
Use the command `bin/spc download` to download the source code required for compilation,
|
||||
|
||||
@ -50,29 +50,29 @@ cd static-php-cli
|
||||
composer update
|
||||
```
|
||||
|
||||
### 使用系统 PHP 环境
|
||||
### 使用预编译静态 PHP 二进制运行 static-php-cli
|
||||
|
||||
下面是系统安装 PHP、Composer 的一些示例命令。具体安装方式建议自行搜索或询问 AI 搜索引擎获取答案,这里不多赘述。
|
||||
如果你不想使用 Docker、在系统内安装 PHP,可以直接下载本项目自身编译好的 php 二进制 cli 程序。使用流程如下:
|
||||
|
||||
```bash
|
||||
# [macOS], 需要先安装 Homebrew. 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
|
||||
```
|
||||
使用命令部署环境,此脚本会从 [自托管的服务器](https://dl.static-php.dev/static-php-cli/) 下载一个当前操作系统的 php-cli 包,
|
||||
并从 [getcomposer](https://getcomposer.org/download/latest-stable/composer.phar) 或 [Aliyun(镜像)](https://mirrors.aliyun.com/composer/composer.phar) 下载 Composer。
|
||||
|
||||
::: tip
|
||||
目前 Ubuntu 部分版本的 apt 安装的 php 版本较旧,故不提供安装命令。如有需要,建议先添加 ppa 等软件源后,安装最新版的 PHP 以及 tokenizer、xml、phar 扩展。
|
||||
|
||||
较老版本的 Debian 默认安装的可能为旧版本(<= 7.4)版本的 PHP,建议先升级 Debian。
|
||||
使用预编译静态 PHP 二进制目前仅支持 Linux 和 macOS。FreeBSD 环境因为缺少自动化构建环境,所以暂不支持。
|
||||
:::
|
||||
|
||||
```bash
|
||||
bin/setup-runtime
|
||||
|
||||
# 对于中国大陆地区等网络环境特殊的用户,可使用镜像站加快下载速度
|
||||
bin/setup-runtime --mirror china
|
||||
```
|
||||
|
||||
此脚本总共会下载两个文件:`bin/php` 和 `bin/composer`,下载完成后,有两种使用方式:
|
||||
|
||||
1. 将 `bin/` 目录添加到 PATH 路径中:`export PATH="/path/to/your/static-php-cli/bin:$PATH"`,添加路径后,相当于系统安装了 PHP,可直接使用 `composer`、`php -v` 等命令,也可以直接使用 `bin/spc`。
|
||||
2. 直接调用,比如执行 static-php-cli 命令:`bin/php bin/spc --help`,执行 Composer:`bin/php bin/composer update`。
|
||||
|
||||
### 使用 Docker 环境
|
||||
|
||||
如果你不愿意在系统安装 PHP 和 Composer 运行环境,可以使用内置的 Docker 环境构建脚本。
|
||||
@ -92,28 +92,25 @@ bin/spc-alpine-docker
|
||||
export SPC_USE_SUDO=yes
|
||||
```
|
||||
|
||||
### 使用预编译静态 PHP 二进制
|
||||
### 使用系统 PHP 环境
|
||||
|
||||
如果你不想使用 Docker、在系统内安装 PHP,可以直接下载本项目自身编译好的 php 二进制 cli 程序。使用流程如下:
|
||||
|
||||
使用命令部署环境,此脚本会从 [自托管的服务器](https://dl.static-php.dev/static-php-cli/) 下载一个当前操作系统的 php-cli 包,
|
||||
并从 [getcomposer](https://getcomposer.org/download/latest-stable/composer.phar) 或 [Aliyun(镜像)](https://mirrors.aliyun.com/composer/composer.phar) 下载 Composer。
|
||||
|
||||
::: tip
|
||||
使用预编译静态 PHP 二进制目前仅支持 Linux 和 macOS。FreeBSD 环境因为缺少自动化构建环境,所以暂不支持。
|
||||
:::
|
||||
下面是系统安装 PHP、Composer 的一些示例命令。具体安装方式建议自行搜索或询问 AI 搜索引擎获取答案,这里不多赘述。
|
||||
|
||||
```bash
|
||||
bin/setup-runtime
|
||||
# [macOS], 需要先安装 Homebrew. 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
|
||||
|
||||
# 对于中国大陆地区等网络环境特殊的用户,可使用镜像站加快下载速度
|
||||
bin/setup-runtime --mirror china
|
||||
# [Debian], you need to make sure your php version >= 8.4 and composer >= 2.0
|
||||
sudo apt install php-cli composer php-tokenizer
|
||||
```
|
||||
|
||||
此脚本总共会下载两个文件:`bin/php` 和 `bin/composer`,下载完成后,有两种使用方式:
|
||||
::: tip
|
||||
目前 Ubuntu 部分版本的 apt 安装的 php 版本较旧,故不提供安装命令。如有需要,建议先添加 ppa 等软件源后,安装最新版的 PHP 以及 tokenizer、xml、phar 扩展。
|
||||
|
||||
1. 将 `bin/` 目录添加到 PATH 路径中:`export PATH="/path/to/your/static-php-cli/bin:$PATH"`,添加路径后,相当于系统安装了 PHP,可直接使用 `composer`、`php -v` 等命令,也可以直接使用 `bin/spc`。
|
||||
2. 直接调用,比如执行 static-php-cli 命令:`bin/php bin/spc --help`,执行 Composer:`bin/php bin/composer update`。
|
||||
较老版本的 Debian 默认安装的可能为旧版本(<= 8.3)版本的 PHP,建议先升级 Debian 或使用 Docker 或自带的静态二进制环境。
|
||||
:::
|
||||
|
||||
## 命令 download - 下载依赖包
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ use Symfony\Component\Console\Application;
|
||||
*/
|
||||
final class ConsoleApplication extends Application
|
||||
{
|
||||
public const VERSION = '2.4.5';
|
||||
public const VERSION = '2.5.0';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
||||
@ -163,6 +163,8 @@ if ($argv[1] === 'download_cmd') {
|
||||
} else {
|
||||
passthru('./bin/spc ' . $build_cmd . ' --build-embed', $retcode);
|
||||
}
|
||||
} else {
|
||||
$retcode = 0;
|
||||
}
|
||||
|
||||
exit($retcode);
|
||||
|
||||
@ -15,7 +15,7 @@ class SystemUtilTest extends TestCase
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Linux') {
|
||||
self::markTestIncomplete('This test is only for Linux');
|
||||
self::markTestSkipped('This test is only for Linux');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ class SystemUtilTest extends TestCase
|
||||
public static function setUpBeforeClass(): void
|
||||
{
|
||||
if (PHP_OS_FAMILY !== 'Darwin') {
|
||||
self::markTestIncomplete('This test is only for macOS');
|
||||
self::markTestSkipped('This test is only for macOS');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user