Code Monkey home page Code Monkey logo

Comments (4)

jingjingxyk avatar jingjingxyk commented on August 23, 2024

experiment 分支新增:

  1. 允许指定扩展下载地址
  2. 可以使用curl 、 git 等方式下载库或者扩展,
  3. 新增简易webui 辅助: https://swoole-cli-ui.jingjingxyk.com/
  4. 新增快速初始化PHP 运行环境脚本setup-php-runtime.sh
  5. 编译gd 扩展,扩展启用依赖 libavif 库,为了支持 avif 格式的图片,编译时添加 --with-libavif=1

build_native_php分支新增:

  1. 继承 experiment 分支功能
  2. 可指定 PHP 版本,例如: --with-php-version=8.2.11
  3. 可指定 C 编译器 为GCC,例如: --with-c-compiler=gcc
  4. 可指定 构建类型,用于新增扩展时,验证扩展启用参数,例如: --with-build-type=dev
  5. 可指定 http 代理,用于下载,扩展和依赖库 ,例如: --with-http-proxy=http://192.168.3.26:8015
  6. 可编译swow扩展的PHP可执行文件,例如: php prepare.php -swoole +swow
  7. 可在 debian 、ubuntu 容器环境中验证静态编译

from swoole-cli.

jingjingxyk avatar jingjingxyk commented on August 23, 2024

PHP 静态编译 完整的流程

(只启用redis 扩展 和 默认扩展)

要添加扩展,你只要依照添加redis 方式添加即可(过程中,你会发现需要解决很多很多静态链接库问题)

解决静态链接库问题,并且把解决步骤固定下来,也就是swoole-cli 项目做的事情

准备构建环境,alpine:3.17

运行容器,并将自动进入容器终端

docker run --rm   -ti --init  -w /work alpine:3.17

安装构建环境必要软件包

apk update

apk add vim alpine-sdk xz autoconf automake linux-headers clang-dev clang lld libtool cmake bison re2c gettext coreutils gcc g++
apk add bash p7zip zip unzip flex pkgconf ca-certificates
apk add wget git curl
apk add libc++-static libltdl-static
apk add vim 

准备构建脚本

vi build-static-php.sh

#!/bin/env bash
set -uex

PHP_VERSION=8.1.21

test -f php-${PHP_VERSION}.tar.gz || wget -O php-${PHP_VERSION}.tar.gz https://github.com/php/php-src/archive/refs/tags/php-${PHP_VERSION}.tar.gz
test -d php-src && rm -rf php-src
mkdir -p php-src
tar --strip-components=1 -C php-src -xf php-${PHP_VERSION}.tar.gz

test -f redis-5.3.7.tgz || wget -O redis-5.3.7.tgz https://pecl.php.net/get/redis-5.3.7.tgz
mkdir -p redis
tar --strip-components=1 -C redis -xf redis-5.3.7.tgz

test -d php-src/ext/redis && rm -rf php-src/ext/redis
mv mongodb php-src/ext/

export CC=clang
export CXX=clang++
export LD=ld.lld

cd php-src

./buildconf --force

./configure \
  --disable-all \
  --disable-cgi \
  --enable-shared=no \
  --enable-static=yes \
  --enable-cli \
  --disable-phpdbg \
  --without-valgrind \
  --enable-session \
  --enable-redis

make -j $(nproc)

file sapi/cli/php
readelf -h sapi/cli/php

执行构建即可

bash build-static-php.sh

# 构建完毕 ,生成的如下文件,就是希望得到的二进制文件
sapi/cli/php 
sapi/cli/php -m 
sapi/cli/php -v 
sapi/cli/php --ri redis 

from swoole-cli.

jingjingxyk avatar jingjingxyk commented on August 23, 2024

swoole-cli 就是在上述基础之上,做了进行裁剪 、优化、整合 、打包 等,并默认启用了swoole 扩展。

from swoole-cli.

jingjingxyk avatar jingjingxyk commented on August 23, 2024

一句命令即可 为 linux 、macOS 准备 PHP 运行环境 (依赖 curl 、wget 、bash 、xz)

curl https://github.com/swoole/swoole-cli/blob/main/setup-php-runtime.sh?raw=true -sSfL | bash -s -- --mirror china
curl https://swoole-cli.jingjingxyk.com/setup-php-runtime.sh  -sSf | bash -s -- --mirror china

from swoole-cli.

Related Issues (20)

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.