<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ## 介紹 static-php-cli 是一個用于構建靜態編譯的 PHP 二進制的工具,目前支持 Linux 和 macOS 系統。 在本章節中,你將了解到如何使用 static-php-cli 構建獨立的 php 程序。 ## 編譯環境[?](https://static-php.dev/zh/guide/#%E7%BC%96%E8%AF%91%E7%8E%AF%E5%A2%83) 下面是架構支持情況`??` 代表支持 GitHub Action 構建,?? 代表支持本地構建,`空`代表暫不支持。 | OS | x86\_64 | aarch64 | | --- | --- | --- | | macOS | ?? ?? | ?? ?? | | Linux | ?? ?? | ?? ?? | | Windows | ?? ?? | | | FreeBSD | ?? | ?? | 其中,Linux 目前僅在 Ubuntu、Debian、Alpine 發行版測試通過,其他發行版未進行測試,不能保證編譯成功。 對于未經過測試的發行版,可以使用 Docker 等方式本地編譯,避免環境導致的問題。 macOS 下支持 x86\_64 和 Arm 兩種架構,但在其中一個架構上編譯的二進制無法直接在另一個架構上使用。 Rosetta 2 不能保證 Arm 架構編譯的程序可以完全運行在 x86\_64 環境下。 > Windows 目前只支持 x86\_64 架構,不支持 32 位 x86、不支持 arm64 架構。 ## PHP 支持版本 目前,static-php-cli 對 PHP 7.4 ~ 8.3 版本是支持的,對于 PHP 7.4 及更早版本理論上支持,只需下載時選擇早期版本即可。 但由于部分擴展和特殊組件已對早期版本的 PHP 停止了支持,所以 static-php-cli 不會明確支持早期版本。 我們推薦你編譯盡可能新的 PHP 版本,以獲得更好的體驗。 ## 本地構建 ### 手動構建 本項目提供了一個 static-php-cli 的二進制文件,你可以直接下載對應平臺的二進制文件,然后使用它來構建靜態的 PHP。目前`spc`二進制支持的平臺有 Linux 和 macOS。 使用以下命令從自托管服務器下載 ``` curl -fsSL -o spc https://dl.static-php.dev/static-php-cli/spc-bin/nightly/spc-linux-x86_64 ``` > 更多版本:https://static-php.dev/zh/guide/manual-build.html 賦予二進制可執行權限 ``` chmod +x ./spc ``` 查看版本 ```ts ./spc --version static-php-cli 2.3.2 ``` ### 下載依賴包 使用命令`bin/spc download`可以下載編譯需要的源代碼,包括 php-src 以及依賴的各種庫的源碼。 僅下載要編譯的擴展及依賴庫(使用擴展名,包含可選庫) ``` ./spc download --for-extensions=pcntl,zstd --with-php=8.2 ``` ![](https://img.kancloud.cn/b2/ff/b2fff7c6e4ecf7bc262511bc4d2f5b00_830x319.png) ### 環境檢查 如果你可以正常運行`bin/spc`但無法正常編譯靜態的 PHP 或依賴庫,可以先運行`bin/spc doctor`檢查系統自身是否缺少依賴。 ``` ./spc doctor ``` ![](https://img.kancloud.cn/7b/21/7b21bc56c1ed64081c6b9fd7afae3332_1132x657.png) 如果提示以下錯誤,請使用`sudo`權限 ``` [11:12:22] [INFO] [EXEC] ./configure --disable-gcc-wrapper Fix failed Some check item are not fixed ``` cmake版本太低 ``` Checking if cmake version >= 3.18 ... cmake version is too low (3.10.2), please update it manually! Some check items can not be fixed ! ``` 下載解壓 ``` wget https://cmake.org/files/v3.22/cmake-3.22.5.tar.gz tar -zxvf cmake-3.22.5.tar.gz cd cmake-3.22.5 # 編譯安裝 ./configure make sudo make install ``` ![](https://img.kancloud.cn/35/f2/35f296a64e3bf58da9eb9771b6148579_704x239.png) 驗證安裝 ``` cmake --version cmake version 3.22.5 CMake suite maintained and supported by Kitware (kitware.com/cmake). ``` 重新檢測,可以看出以下輸出信息表示環境檢查通過。 ```ts _ _ _ _ ___| |_ __ _| |_(_) ___ _ __ | |__ _ __ / __| __/ _` | __| |/ __|____| '_ \| '_ \| '_ \ \__ \ || (_| | |_| | (_|_____| |_) | | | | |_) | |___/\__\__,_|\__|_|\___| | .__/|_| |_| .__/ v2.3.2 |_| |_| Checking if current OS are supported ... Linux x86_64 ubuntu, supported Checking if necessary tools are installed ... ok Checking if musl-wrapper is installed ... ok Checking if musl-cross-make is installed ... ok Checking if cmake version >= 3.18 ... 3.22.5 Checking if necessary linux headers are installed ... ok Doctor check complete ! ``` ### 編譯 PHP 使用 build 命令可以開始構建靜態 php 二進制,在執行`bin/spc build`命令前,務必先使用`download`命令下載資源,建議使用`doctor`檢查環境。 ``` ./spc build pcntl,zstd --build-cli ``` ![](https://img.kancloud.cn/0b/da/0bda7cec799b66aa83012babb4f4a56c_917x580.png) > 構建結果 ``` _ _ _ _ ___| |_ __ _| |_(_) ___ _ __ | |__ _ __ / __| __/ _` | __| |/ __|____| '_ \| '_ \| '_ \ \__ \ || (_| | |_| | (_|_____| |_) | | | | |_) | |___/\__\__,_|\__|_|\___| | .__/|_| |_| .__/ v2.3.2 |_| |_| [14:52:49] [INFO] Build OS: Linux (x86_64) [14:52:49] [INFO] Build SAPI: cli [14:52:49] [INFO] Extensions (2): pcntl,zstd [14:52:49] [INFO] Libraries (1): zstd [14:52:49] [INFO] Strip Binaries: yes [14:52:49] [INFO] Enable ZTS: no [14:52:49] [INFO] PHP Version: 8.2.22 [14:52:49] [NOTI] Build will start after 2s ... [14:52:51] [NOTI] lib [pkg-config] already built [14:52:51] [INFO] Building required library [zstd] [14:52:51] [INFO] Entering dir: /home/www/build/source/zstd/build/cmake/build [14:52:51] [INFO] [EXEC] cmake -DCMAKE_C_COMPILER=x86_64-linux-musl-gcc -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/ -DCMAKE_INSTALL_BINDIR=/bin -DCMAKE_INSTALL_LIBDIR=/lib -DCMAKE_INSTALL_INCLUDEDIR=/include -DCMAKE_TOOLCHAIN_FILE=/home/www/build/source/toolchain.cmake -DZSTD_BUILD_STATIC=ON -DZSTD_BUILD_SHARED=OFF .. [14:52:53] [INFO] [EXEC] cmake --build . -j 2 [14:54:38] [INFO] [EXEC] make install DESTDIR=/home/www/build/buildroot [14:54:39] [INFO] Patching library [zstd] pkgconfig [14:54:39] [INFO] lib [zstd] setup success, took 107.47 s [14:54:39] [INFO] Entering dir: /home/www/build/source/php-src [14:54:39] [INFO] [EXEC] ./buildconf --force [14:54:42] [INFO] Entering dir: /home/www/build/source/php-src [14:54:42] [INFO] pcntl is using --enable-pcntl [14:54:42] [INFO] zstd is using --enable-zstd --with-libzstd="/home/www/build/buildroot" [14:54:42] [INFO] [EXEC] LD_LIBRARY_PATH=/usr/local/musl/x86_64-linux-musl/lib ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg --enable-cli --disable-fpm --disable-embed --disable-micro --enable-pcntl --enable-zstd --with-libzstd="/home/www/build/buildroot" CFLAGS='' CPPFLAGS='-I/home/www/build/buildroot/include' LDFLAGS='-L/home/www/build/buildroot/lib' LIBS='-ldl -lpthread -lm' [14:55:02] [INFO] cleaning up [14:55:02] [INFO] Entering dir: /home/www/build/source/php-src [14:55:02] [INFO] [EXEC] make clean [14:55:03] [INFO] building cli [14:55:03] [INFO] Entering dir: /home/www/build/source/php-src [14:55:03] [INFO] [EXEC] sed -i "s|//lib|/lib|g" Makefile [14:55:03] [INFO] [EXEC] $SPC_CMD_PREFIX_PHP_MAKE EXTRA_CFLAGS='-g -Os -fno-ident -fPIE' EXTRA_LIBS='/home/www/build/buildroot/lib/libzstd.a ' EXTRA_LDFLAGS_PROGRAM='-all-static' cli [15:02:04] [INFO] Entering dir: /home/www/build/source/php-src/sapi/cli [15:02:04] [INFO] [EXEC] strip --strip-all php [15:02:04] [INFO] Deploying cli file [15:02:04] [INFO] [EXEC] cp '/home/www/build/source/php-src/sapi/cli/php' '/home/www/build/buildroot/bin/' [15:02:04] [INFO] running cli sanity check [15:02:04] [INFO] [EXEC] /home/www/build/buildroot/bin/php -r "echo \"hello\";" [15:02:04] [INFO] Build complete, used 554.717 s ! [15:02:04] [INFO] Static php binary path: /home/www/build/buildroot/bin/php [15:02:04] [INFO] License path: /home/www/build/buildroot/license/ ``` ### 使用 PHP CLi 構建完成之后,會在當前目錄`buildroot/bin`生產一個二進制文件`php`,可以直接分發和使用。 ``` buildroot/bin$ tree -L 1 . ├── php ├── pkg-config ├── unzstd -> zstd ├── zstd ├── zstdcat -> zstd ├── zstdgrep ├── zstdless └── zstdmt -> zstd ``` 查看PHP版本 ``` /buildroot/bin$ ./php -v PHP 8.2.22 (cli) (built: Aug 9 2024 23:01:57) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.22, Copyright (c) Zend Technologies ``` 已安裝模塊`pcntl,zstd` ``` ./php -m [PHP Modules] Core date hash json pcntl pcre random Reflection SPL standard zstd [Zend Modules] ``` 打包編譯好的二進制文件 ``` tar -czvf php-8.2.22-static-bin-x86_64.tar.gz /home/www/build/buildroot/bin/php ``` ### 其他 #### 重復構建、調試 如果你需要重復構建、調試,你可以刪除`buildroot/`和`source/`兩個目錄,這樣你可以從已下載的源碼壓縮包重新解壓并構建: ```ts # remove rm -rf buildroot source # build again bin/spc build bcmath,curl,openssl,ftp,posix,pcntl --build-cli ``` #### 構建多個版本的 PHP 如果你想構建多個版本的 PHP,且不想每次都重復構建其他依賴庫,可以使用`switch-php-version`在編譯好一個版本后快速切換至另一個版本并編譯: ```ts # switch to 8.3 bin/spc switch-php-version 8.3 # build bin/spc build bcmath,curl,openssl,ftp,posix,pcntl --build-cli # switch to 8.0 bin/spc switch-php-version 8.0 # build bin/spc build bcmath,curl,openssl,ftp,posix,pcntl --build-cli ``` ## 命令生成器 文檔:https://static-php.dev/zh/guide/cli-generator.html
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看