Giter Club home page Giter Club logo

static-php-cli's Introduction

static-php-cli

Chinese readme English readme Releases CI License Extensions

static-php-cli is a powerful tool designed for building static, standalone PHP runtime with popular extensions.

Static PHP built by static-php-cli supports cli, fpm, embed and micro SAPI.

static-php-cli also has the ability to package PHP projects along with the PHP interpreter into one single executable file.

Features

static-php-cli (you can call it spc) has a lot of features:

  • 👜 Build single-file php executable, without any dependencies
  • 🍔 Build phpmicro self-extracted executable (glue php binary and php source code into one file)
  • 💊 Automatic build environment checker (Doctor module)
  • Linux, macOS, FreeBSD, Windows support
  • 🔧 Configurable source code patches
  • 📚 Build dependency management
  • 📦 Provide spc own standalone executable (built by spc and box)
  • 🔥 Support many popular extensions
  • 💾 UPX integration (significantly reduces binary size)

Single-file standalone php-cli:

out1

Combine PHP code with PHP interpreter using phpmicro:

out2

Documentation

The current README contains basic usage. For all the features of static-php-cli, see https://static-php.dev .

Direct Download

If you don't want to build or want to test first, you can download example pre-compiled artifact from Actions, or from self-hosted server.

Below are several precompiled static-php binaries with different extension combinations, which can be downloaded directly according to your needs.

For Windows systems, there are currently fewer extensions supported, so only cli and micro that run the minimum extension combination of SPC itself are provided: Extension-Combination - spc-min.

Build

Compilation Requirements

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)
  • Extension: mbstring,tokenizer,phar
  • Supported OS with curl and git installed

Here is the supported OS and arch, where :octocat: represents support for GitHub Action builds, 💻 represents support for local manual builds, and blank represents not currently supported.

x86_64 aarch64
macOS :octocat: 💻 :octocat: 💻
Linux :octocat: 💻 :octocat: 💻
Windows 💻
FreeBSD 💻 💻

Currently supported PHP versions for compilation:

⚠️ supported but not maintained

✔️ supported

❌ not supported

PHP Version Status Comment
7.2
7.3 ⚠️ phpmicro and some extensions not supported on 7.x
7.4 ⚠️ phpmicro and some extensions not supported on 7.x
8.0 ✔️ PHP official has stopped maintenance of 8.0
8.1 ✔️
8.2 ✔️
8.3 ✔️

Supported Extensions

Please first select the extension you want to compile based on the extension list below.

If an extension you need is missing, you can submit an issue.

Here is the current planned roadmap for extension support: #152 .

Build Online (using GitHub Actions)

Use GitHub Action to easily build a statically compiled PHP, and at the same time define the extensions to be compiled by yourself.

  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.

Build Locally (using SPC binary)

This project provides a binary file of static-php-cli: spc. You can use spc binary instead of installing any runtime like golang app. Currently, the platforms supported by spc binary are Linux and macOS.

Download from self-hosted nightly builds using commands below:

# Download from self-hosted nightly builds (sync with main branch)
# For Linux x86_64
curl -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64
# For Linux aarch64
curl -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-aarch64
# macOS x86_64 (Intel)
curl -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-macos-x86_64
# macOS aarch64 (Apple)
curl -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 -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

Self-hosted spc is built by GitHub Actions, you can also download from Actions artifacts here.

Build Locally (using git source)

# just clone me!
git clone https://github.com/crazywhalecc/static-php-cli.git

If you have not installed php on your system, we recommend that you use the built-in setup-runtime to install PHP and Composer automatically.

cd static-php-cli
chmod +x bin/setup-runtime
# it will download static php (from self-hosted server) and composer (from getcomposer)
bin/setup-runtime
# initialize composer deps
bin/composer install
# chmod
chmod +x bin/spc
bin/spc --version

Start Building PHP

Basic usage for building php with some extensions:

If you are using the packaged standalone spc binary, you need to replace bin/spc with ./spc or .\spc.exe in the following commands.

# Check system tool dependencies, auto-fix them if possible
./bin/spc doctor --auto-fix

# fetch all libraries
./bin/spc download --all
# only fetch necessary sources by needed extensions (recommended)
./bin/spc download --for-extensions="openssl,pcntl,mbstring,pdo_sqlite"
# download different PHP version (--with-php=x.y, recommend 7.3 ~ 8.3)
./bin/spc download --for-extensions="openssl,curl,mbstring" --with-php=8.1

# with bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl extension, build both CLI and phpmicro SAPI
./bin/spc build "bcmath,openssl,tokenizer,sqlite3,pdo_sqlite,ftp,curl" --build-cli --build-micro
# build thread-safe (ZTS) version (--enable-zts)
./bin/spc build "curl,phar" --enable-zts --build-cli
# build, pack executable with UPX (--with-upx-pack) (reduce binary size for 30~50%)
./bin/spc build "curl,phar" --enable-zts --build-cli --with-upx-pack

Now we support cli, micro, fpm and embed SAPI. You can use one or more of the following parameters to specify the compiled SAPI:

  • --build-cli: build static cli executable
  • --build-micro: build static phpmicro self-extracted executable
  • --build-fpm: build static fpm binary
  • --build-embed: build embed (libphp)
  • --build-all: build all

If anything goes wrong, use --debug option to display full terminal output:

./bin/spc build "openssl,pcntl,mbstring" --debug --build-all
./bin/spc download --all --debug

Different SAPI Usage

Use cli

php-cli is a single static binary, you can use it like normal php installed on your system.

When using the parameter --build-cli or --build-all, the final compilation result will output a binary file named ./php, which can be distributed and used directly. This file will be located in the directory buildroot/bin/, copy it out for use.

cd buildroot/bin/
./php -v                # check version
./php -m                # check extensions
./php your_code.php     # run your php code
./php your_project.phar # run your phar (project archive)

Use micro

phpmicro is a SelF-extracted eXecutable SAPI module, provided by phpmicro project. But this project is using a fork of phpmicro, because we need to add some features to it. It can put php runtime and your source code together.

When using the parameter --build-all or --build-micro, 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, simply copy it out for use.

Prepare your project source code, which can be a single PHP file or a Phar file, for use.

echo "<?php echo 'Hello world' . PHP_EOL;" > code.php
cat micro.sfx code.php > single-app && chmod +x single-app
./single-app

If you package a PHAR file, just replace code.php with the phar file path. You can use box-project/box to package your CLI project as Phar, It is then combined with phpmicro to produce a standalone executable binary.

# Use the micro.sfx generated by static-php-cli to combine,
bin/spc micro:combine my-app.phar
# or you can directly use the cat command to combine them.
cat buildroot/bin/micro.sfx my-app.phar > my-app && chmod +x my-app

# Use micro:combine combination to inject INI options into the binary.
bin/spc micro:combine my-app.phar -I "memory_limit=4G" -I "disable_functions=system" --output my-app-2

In some cases, PHAR files may not run in a micro environment. Overall, micro is not production ready.

Use fpm

When using the parameter --build-all or --build-fpm, the final compilation result will output a file named ./php-fpm, This file will be located in the path buildroot/bin/, simply copy it out for use.

In common Linux distributions and macOS systems, the package manager will automatically generate a default fpm configuration file after installing php-fpm. Because php-fpm must specify a configuration file before running, the php-fpm compiled by this project will not have any configuration files, so you need to write php-fpm.conf and pool.conf configuration files yourself.

Specifying php-fpm.conf can use the command parameter -y, for example: ./php-fpm -y php-fpm.conf.

Use embed

When using the project parameters --build-embed or --build-all, the final compilation result will output a libphp.a, php-config and a series of header files, stored in buildroot/. You can introduce them in your other projects.

If you know embed SAPI, you should know how to use it. You may require the introduction of other libraries during compilation, you can use buildroot/bin/php-config to obtain the compile-time configuration.

For an advanced example of how to use this feature, take a look at how to use it to build a static version of FrankenPHP.

Contribution

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.

If you want to contribute documentation, please go to static-php/static-php-cli-docs.

Now there is a static-php organization, which is used to store the repo related to the project.

Sponsor this project

You can sponsor my project on this page. A portion of your donation will be used to maintain the static-php.dev server.

Open-Source License

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:

The project uses some code from dixyes/lwmbs, such as windows static build target and libiconv support. lwmbs is licensed under the Mulan PSL 2.

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.

static-php-cli's People

Contributors

atrifat avatar crazywhalecc avatar dubbleclick avatar dunglas avatar ikilobyte avatar javalaw avatar jingjingxyk avatar kocoten1992 avatar minbaby avatar mpociot avatar petk avatar simonhamp avatar stloyd avatar szepeviktor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

static-php-cli's Issues

Error when building libxml2 in combination with intl

When building PHP with an extension that requires libxml2 as well as intl the order of the extensions is important.

The libxml2 builder checks if the icu library is available (which it is because of intl).

https://github.com/crazywhalecc/static-php-cli/blob/refactor/src/SPC/builder/macos/library/libxml2.php#L20

But if intl is after the xml extension in the build order, this fails because icu is not yet available.

This fails:

./bin/spc build xml,intl

This works:

./bin/spc build intl,xml

I think it would be good to internally change the order of some extensions when they are required. For example icu could just always be compiled first.
I'm not sure if that's already implemented somewhere.

按照readme的方法自行编译,编译失败

  • 什么都没改过,代码拉下来后执行 docker build -t static-php . --build-arg USE_BACKUP_ADDRESS=no --build-arg COMPILE_PHP_VERSION=7.4.28
[+] Building 30.4s (34/34) FINISHED
 => [internal] load build definition from Dockerfile                                                                                                                                 0.0s
 => => transferring dockerfile: 37B                                                                                                                                                  0.0s
 => [internal] load .dockerignore                                                                                                                                                    0.0s
 => => transferring context: 2B                                                                                                                                                      0.0s
 => [internal] load metadata for docker.io/library/alpine:latest                                                                                                                     1.3s
 => [ 1/30] FROM docker.io/library/alpine:latest@sha256:4edbd2beb5f78b1014028f4fbb99f3237d9561100b6881aabbf5acce2c4f9454                                                             0.0s
 => [internal] load build context                                                                                                                                                    0.0s
 => => transferring context: 236B                                                                                                                                                    0.0s
 => CACHED [ 2/30] RUN if [ "no" = "yes" ]; then         echo "Using backup address..." && sleep 3s;     else         echo "Using original address..." && sleep 3s;     fi           0.0s
 => CACHED [ 3/30] RUN sed -i 's/dl-cdn.alpinelinux.org/'mirrors.ustc.edu.cn'/g' /etc/apk/repositories                                                                               0.0s
 => CACHED [ 4/30] RUN apk add bash wget cmake gcc g++ jq autoconf git libstdc++ linux-headers make m4 libgcc binutils ncurses > /dev/null                                           0.0s
 => CACHED [ 5/30] RUN apk add zlib-dev zlib-static > /dev/null                                                                                                                      0.0s
 => CACHED [ 6/30] RUN apk add oniguruma-dev > /dev/null                                                                                                                             0.0s
 => CACHED [ 7/30] RUN apk add openssl-libs-static openssl-dev openssl > /dev/null                                                                                                   0.0s
 => CACHED [ 8/30] RUN apk add libpng-dev libpng-static > /dev/null                                                                                                                  0.0s
 => CACHED [ 9/30] RUN apk add c-ares-static c-ares-dev > /dev/null                                                                                                                  0.0s
 => CACHED [10/30] RUN apk add libevent libevent-dev libevent-static > /dev/null                                                                                                     0.0s
 => CACHED [11/30] RUN apk add sqlite sqlite-dev sqlite-libs sqlite-static > /dev/null                                                                                               0.0s
 => CACHED [12/30] RUN mkdir /app                                                                                                                                                    0.0s
 => CACHED [13/30] WORKDIR /app                                                                                                                                                      0.0s
 => CACHED [14/30] COPY ac_override_1 /app/                                                                                                                                          0.0s
 => CACHED [15/30] COPY ac_override_2 /app/                                                                                                                                          0.0s
 => CACHED [16/30] COPY download.sh /app/                                                                                                                                            0.0s
 => CACHED [17/30] COPY config.json /app/                                                                                                                                            0.0s
 => CACHED [18/30] RUN chmod +x /app/download.sh                                                                                                                                     0.0s
 => CACHED [19/30] RUN echo "Downloading Extensions ..."                                                                                                                             0.0s
 => CACHED [20/30] RUN ./download.sh swoole no > /dev/null &&     ./download.sh inotify no > /dev/null &&     ./download.sh mongodb no > /dev/null &&     ./download.sh event no >   0.0s
 => CACHED [21/30] RUN echo "Downloading PHP 7.4.28 ..."                                                                                                                             0.0s
 => CACHED [22/30] RUN ./download.sh php no 7.4.28 > /dev/null                                                                                                                       0.0s
 => CACHED [23/30] COPY extensions.txt /app/                                                                                                                                         0.0s
 => CACHED [24/30] COPY check-extensions.sh /app/                                                                                                                                    0.0s
 => CACHED [25/30] COPY compile-php.sh /app/                                                                                                                                         0.0s
 => CACHED [26/30] RUN chmod +x ./check-extensions.sh &&     chmod +x ./compile-php.sh                                                                                               0.0s
 => CACHED [27/30] RUN echo "Checking and Compiling Dependencies ..."                                                                                                                0.0s
 => CACHED [28/30] RUN ./check-extensions.sh check_before_configure > /dev/null                                                                                                      0.0s
 => CACHED [29/30] RUN echo "Compiling PHP ..."                                                                                                                                      0.0s
 => ERROR [30/30] RUN ./compile-php.sh 7.4.28 > /dev/null 2>&1                                                                                                                      28.8s
------
 > [30/30] RUN ./compile-php.sh 7.4.28 > /dev/null 2>&1:
------
executor failed running [/bin/sh -c ./compile-php.sh ${VER_PHP} > /dev/null 2>&1]: exit code: 1

编译后使用curl函数时会报错

报错内容:cURL error 77: error setting certificate verify

项目使用了一个定时自动curl请求第三方地址
正常PHP环境运行 没问题
打包phar后运行·也没有问题
当和php二进制文件组合后报错

大佬: 把pkg-config 充分利用起来,因为编译链接时要连接的库特别多

举个例子:libwebp

我为了启用gd库 扩展,编译PHP 是发现待处理的问题越多;需要解决连接 LIBS ,比如: -lwebpdemux -lm -pthread -lwebpdecoder -lwebp -lturbojpeg -lsharpyuv -lz

越来越多的 各种 lib.pc

 ./bin/spc build "bcmath,tokenizer,pdo,ftp,gd" --cc=clang --cxx=clang++  --debug

image

最好在 编译 php 是 导入变量

    PACKAGES="libbrotlicommon libbrotlidec libbrotlienc libzip  libjpeg libturbojpeg freetype2 libpng libpng16 libwebp "
    export  CPPFLAGS="$(pkg-config --cflags-only-I --static $PACKAGES ) "
    export  LDFLAGS=" $(pkg-config --libs-only-L --static $PACKAGES ) "
    export  LIBS=" $(pkg-config --libs-only-l --static $PACKAGES ) -lstdc++"

贴个赞助二维码吧!

看到你们这么努力的为php生态做贡献,给本就不怎样的php增添了有一种可能,所以还是贴个赞助二维码吧,能收获一些支持也是对你们的肯定 @crazywhalecc

Refactor version bugs and TODO list | 重构版已知 Bug 和待完成任务

Bugs

  • mbstring support is good, but it cannot be compiled with pcntl. (after adding mbstring, configure shows pcntl_fork() not supported by this platform). Fixed via c93a4e8
  • cannot compile libmcrypt on macOS. Maybe this bug will never be fixed. (source is too old to compile)
  • swoole extension for macOS has a dynamic library linked: /usr/lib/libc++.dylib.
  • swoole extension for Linux shows an error: ‘strlcpy’ was not declared in this scope; did you mean ‘strncpy’?
  • #37
  • #43
  • conflicts between libsodium and libargon2 #64
  • build:libs command has no --enable-zts option

TODO List

  • GitHub Action or CI support for quick build (priority is high)
  • php-fpm support (easy)
  • dump license.
  • When system doesn't have php, download a prebuilt static-php-cli and composer. #38
  • macOS doctor: automatically install missing commands using brew.
  • mcrypt support: #27
  • use pkg-config to let system find libraries automatically (priority is high) #42
  • gd extension add JPEG support (need to compile libjpeg) #39 #41
  • #45
  • Error handler: when failed fetching source, tell user a message.
  • Interrupt handler: when keyboard interrupt when downloading, revert or delete broken file.
  • more elegant patching tools for easily reverting patched files to avoid source broken.
  • add ext dependency when libiconv is required (to prevent using system libiconv on macOS)
  • arm docker build action and scripts
  • add event extension support
  • add ssh2 extension support
  • add xdebug test branch
  • add opcache support
  • #65
  • #66
  • rewritable check extension
  • macOS load dynamic extension guide
  • Pack other project with phar command (already integrated with php-cli-helper)
  • Linux auto-setup: automatically install missing commands using package manager like apt, yum, pacman, etc.
  • deploy deploy self command needs a extension checker for self-required extensions like tokenizer, mbstring.
  • curl extension SSL notes in README or WIKI. #24
  • pgsql support. #21
  • Weekly build action
  • write developer document, to those who want to contribute
  • write sanity check scripts for some important extensions
  • Windows auto-setup: automatically install environment or give a windows build SDK download url.
  • Windows support: compile a basic static-php-cli binary.

postgresql静态编译libpq--参考

libpq 静态编译 参考

libpq static compiler reference

# cpu_nums=`nproc 2> /dev/null || sysctl -n hw.ncpu`

cpu_nums=`grep "processor" /proc/cpuinfo | sort -u | wc -l`


wget https://ftp.postgresql.org/pub/source/v15.1/postgresql-15.1.tar.gz

mkdir -p pgsql 

tar --strip-components=1 -C pgsql -xf  postgresql-15.1.tar.gz

cd pgsql


sed -i "s/invokes exit'; exit 1;/invokes exit';/"  src/interfaces/libpq/Makefile

 # 替换指定行内容
sed -i "102c all: all-lib" src/interfaces/libpq/Makefile



export CPPFLAGS="-static -fPIE -fPIC -O2 -Wall "

./configure  --prefix=/usr/pgsql \
--enable-coverage=no \
--with-ssl=openssl  \
--with-readline \
--without-icu \
--without-ldap \
--without-libxml  \
--without-libxslt \
--with-includes="/usr/openssl/include/:/usr/zlib/include:/usr/include" \
--with-libraries="/usr/openssl/lib64:/usr/zlib/lib:/usr/lib"


make -C src/include install 
make -C  src/bin/pg_config install

make -C  src/common -j $cpu_nums all 
make -C  src/common install 

make -C  src/port -j $cpu_nums all 
make -C  src/port install 


make -C  src/backend/libpq -j $cpu_nums all 
make -C  src/backend/libpq install 

make -C src/interfaces/ecpg   -j $cpu_nums all-pgtypeslib-recurse all-ecpglib-recurse all-compatlib-recurse all-preproc-recurse
make -C src/interfaces/ecpg  install-pgtypeslib-recurse install-ecpglib-recurse install-compatlib-recurse install-preproc-recurse
            

make -C src/interfaces/libpq  -j $cpu_nums 

make -C src/interfaces/libpq  install 

编译PHP时指定库的位置

# 编译swoole扩展时需要下面两个参数
export LIBPQ_CFLAGS=$(pkg-config  --cflags --static      libpq)
export LIBPQ_LIBS=$(pkg-config  --libs  --static       libpq)


#编译 php时指定libpq
export CPPFLAGS=$(pkg-config  --cflags --static  libpq)
export LIBS=$(pkg-config  --libs --static   libpq)



编译PHP时指定PGSQL参数

    --enable-swoole  --enable-mysqlnd --enable-swoole-curl --enable-cares  --enable-swoole-pgsql  --with-brotli-dir=/usr/brotli  \
    --with-pgsql=/usr/pgsql \
    --with-pdo-pgsql=/usr/pgsql 

实验程序: https://github.com/jingjingxyk/swoole-cli/blob/5e27c2ca4b9ea672fef8b20157b21cb48fb5f6ea/prepare.php#L1148

碰到一个phar打包二进制的问题

以下代码

<?php

ini_set('display_errors', 'on');
ini_set('display_startup_errors', 'on');

error_reporting(E_ALL);

!defined('BASE_PATH') && define('BASE_PATH', __DIR__);
require BASE_PATH . '/vendor/autoload.php';

use Lib\Parallel;
use function Swoole\Coroutine\run;

run(function () {
   $parallel = new Parallel(1);
   echo 'ok';
});

打包phar正常,打包项目运行就会提示Class "Lib\Parallel" not found in phar://,必须加上对lib下文件的require

intl support

intl with icu cannot be compiled in glibc-based linux. If you want to build it, use bin/spc-alpine-docker to build. Same issue with swoole: #51

gd扩展库存在问题

报错内容:PHP Fatal error: Call to undefined function imagettfbbox()
造成的原因:gd扩展没开freetype

macos 上的mongodb DB扩展关于ZSTD、 ZLIB 、SNNAPY库的处理办法

macos 因为mongodb 扩展对于这三个库,有自动检测,但是没有关闭选项。

https://github.com/crazywhalecc/static-php-cli/actions/runs/5087204006

这个问题我是这么解决的

为啥我知道这个,因为swoole-cli 也是同样的问题,https://github.com/swoole/swoole-cli/actions/runs/5042675610/jobs/9043555754;

	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)
	/usr/lib/libsasl2.2.dylib (compatibility version 3.0.0, current version 3.15.0)
	/usr/lib/libresolv.9.dylib (compatibility version 1.0.0, current version 1.0.0)
	/usr/local/opt/snappy/lib/libsnappy.1.dylib (compatibility version 1.0.0, current version 1.1.10)
	/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 1300.36.0)
	/usr/lib/libnetwork.dylib (compatibility version 1.0.0, current version 1.0.0)
	/usr/local/opt/zstd/lib/libzstd.1.dylib (compatibility version 1.0.0, current version 1.5.5)

解决办法:
办法一: 通过查看mongodb 源码,发现,它可以通过设置环境变量设置值;我就是通过查看源码,发现加上PHP_MONGODB_ZSTD_CFLAGS PHP_MONGODB_ZSTD_LIBS ,解决了它总是链接到系统库的问题

办法二: 卸载系统带有 zstd zlib snappy库以后,在进行编译

 brew uninstall --ignore-dependencies snappy
brew uninstall --ignore-dependencies  zstd

iconv扩展无法正常工作

php --ri iconv 


iconv

iconv support => enabled
iconv implementation => unknown
iconv library version => unknown

Directive => Local Value => Master Value
iconv.input_encoding => no value => no value
iconv.output_encoding => no value => no value
iconv.internal_encoding => no value => no value

可以看到iconv library version 和 iconv implementation 都是unknown

非静态编译

php --ri iconv 

iconv

iconv support => enabled
iconv implementation => glibc
iconv library version => 2.17

Directive => Local Value => Master Value
iconv.input_encoding => no value => no value
iconv.output_encoding => no value => no value
iconv.internal_encoding => no value => no value

测试代码

var_dump(iconv('UTF-8', 'GBK', 'hello'));

Swoole 无法在 Debian、Ubuntu 等非 Alpine 环境编译

和 C++ 静态链接有关系,暂无法解决,搁置。

如果想在 Linux 编译 Swoole 扩展,使用 bin/spc-alpine-docker 代替 bin/spc,将自动构建 Alpine Docker 并在 Docker 内构建静态 php。

bin/spc-alpine-docker build swoole,openssl,tokenizer --build-all --debug

大佬: 单独编译一个依赖库 命令是啥?

比如我要编译 libjpeg
配置比照着 libpng 都加好了,如何单独编译一个 libjpeg 库

./bin/spc build gd --cc=clang --cxx=clang++ --debug 

为啥 把依赖库 合并放到 buildroot 目录下bin 、lib 、include ,而不是每个库独占一个目录

image

有啥考量吗?

linux 没法自动拉取依赖吗?

./bin/spc doctor
一直提示我:musl-libc is not installed on your systemSome check items can not be fixed !
但是我musl-libc 是安装了的

使用:./bin/spc fetch --all
[20:11:34] [INFO] Fetching source php-src [1/42]
一直卡着不动 半小时没动静

Sorry for English! Are builds working for macOS?

I'm running an M1 Mac, but I can't get any of the downloads from the download server to run on my machine. Also all of the build artifacts have expired on github.

I will set up to build myself, I just wanted to try it out first

咱么这个支持 zend

我看swoole php -m 看到支持:
[Zend Modules]

暂这个没有能否添加 这个玩意好像是可以加载zend 插件

众人拾柴火焰高

把步骤这样划分,可好? 每一步,只干一件事

  1. 下载指定版本PHP源码
  2. 下载对应版本的扩展
  3. 下载扩展对应版本的依赖库
  4. 静态编译扩展依赖库
  5. 静态编译之前,准备工作
  6. 修改相应参数
  7. 执行编译
  8. 执行构建
  9. 打包

不同操作系统,不同cpu架构,都执行一遍上面的流程。
linux macos window + CPU arch

当然也可以搞一个webUI 把上面展示出来

建议编译器默认换成 clang clang++ ;

缘由: 为了编译 gd 扩展的依赖,遇到的编译问题,让人头大。遇到问题比较少的是 clang clang++

组合一: gcc g++ 需要链接 glibc ;
组合二: musl-gcc g++ ; debian 环境 和 alpine 环境 差异挺大的。
组合三: clang clang++ ;

备注: 也有可能是我不熟悉配置

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.