Giter Club home page Giter Club logo

static-php-cli's Issues

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

gd扩展库存在问题

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

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]
一直卡着不动 半小时没动静

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

大佬: 把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++"

众人拾柴火焰高

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

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

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

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

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

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

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

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

image

有啥考量吗?

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'));

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.

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

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

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

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

碰到一个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

咱么这个支持 zend

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

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

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

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

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

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

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

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.

贴个赞助二维码吧!

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

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

按照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

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.