Skip to content

Environment variables

All environment variables mentioned in the list on this page have default values unless otherwise noted. You can override the default values by setting these environment variables.

Generally, you don't need to modify any of the following environment variables as they are already set to optimal values. However, if you have special needs, you can set these environment variables to meet your needs (for example, you need to debug PHP performance under different compilation parameters).

If you want to use custom environment variables, you can use the export command in the terminal or set the environment variables directly before the command, for example:

shell
# export first
export SPC_CONCURRENCY=4
bin/spc build mbstring,pcntl --build-cli

# or direct use
SPC_CONCURRENCY=4 bin/spc build mbstring,pcntl --build-cli

General environment variables

General environment variables can be used by all build targets.

var namedefault valuecomment
BUILD_ROOT_PATH{pwd}/buildrootThe root directory of the build target
BUILD_LIB_PATH{pwd}/buildroot/libThe root directory of compilation libraries
BUILD_INCLUDE_PATH{pwd}/buildroot/includeHeader file directory for compiling libraries
BUILD_BIN_PATH{pwd}/buildroot/binCompiled binary file directory
PKG_ROOT_PATH{pwd}/pkgrootDirectory where precompiled tools are installed
SOURCE_PATH{pwd}/sourceThe source code extract directory
DOWNLOAD_PATH{pwd}/downloadsDownloaded file directory
SPC_CONCURRENCYDepends on CPU coresNumber of parallel compilations

OS specific variables

These environment variables are system-specific and will only take effect on a specific OS.

Windows

var namedefault valuecomment
PHP_SDK_PATH{pwd}\php-sdk-binary-toolsPHP SDK tools path
UPX_EXEC$PKG_ROOT_PATH\bin\upx.exeUPX compression tool path

macOS

var namedefault valuecomment
CCclangC Compiler
CXXclang++C++ Compiler
SPC_DEFAULT_C_FLAGS--target=arm64-apple-darwin or --target=x86_64-apple-darwinDefault C flags (not the same as CFLAGS)
SPC_DEFAULT_CXX_FLAGS--target=arm64-apple-darwin or --target=x86_64-apple-darwinDefault C flags (not the same as CPPFLAGS)
SPC_CMD_PREFIX_PHP_BUILDCONF./buildconf --forcePHP buildconf command prefix
SPC_CMD_PREFIX_PHP_CONFIGURE./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbgPHP configure command prefix
SPC_CMD_PREFIX_PHP_MAKEmake -j$SPC_CONCURRENCYPHP make command prefix
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS$SPC_DEFAULT_C_FLAGS -Werror=unknown-warning-optionCFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS-I$BUILD_INCLUDE_PATHCPPFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS-L$BUILD_LIB_PATHLDFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS-g0 -Os or -g -O0 (the latter when using --no-strip)EXTRA_CFLAGS variable of PHP make command
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBS-lresolvExtra EXTRA_LIBS variables for PHP make command

Linux

var namedefault valuecomment
UPX_EXEC$PKG_ROOT_PATH/bin/upxUPX compression tool path
GNU_ARCHx86_64 or aarch64CPU architecture
CCAlpine: gcc, Other: $GNU_ARCH-linux-musl-gccC Compiler
CXXAlpine: g++, Other: $GNU_ARCH-linux-musl-g++C++ Compiler
ARAlpine: ar, Other: $GNU_ARCH-linux-musl-arStatic library tools
LDld.goldLinker
PATH/usr/local/musl/bin:/usr/local/musl/$GNU_ARCH-linux-musl/bin:$PATHSystem PATH
SPC_DEFAULT_C_FLAGSemptyDefault C flags
SPC_DEFAULT_CXX_FLAGSemptyDefault C++ flags
SPC_CMD_PREFIX_PHP_BUILDCONF./buildconf --forcePHP buildconf command prefix
SPC_CMD_PREFIX_PHP_CONFIGURELD_LIBRARY_PATH={ld_lib_path} ./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbgPHP configure command prefix
SPC_CMD_PREFIX_PHP_MAKEmake -j$SPC_CONCURRENCYPHP make command prefix
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS$SPC_DEFAULT_C_FLAGSCFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS-I$BUILD_INCLUDE_PATHCPPFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS-L$BUILD_LIB_PATHLDFLAGS variable of PHP configure command
SPC_CMD_VAR_PHP_CONFIGURE_LIBS-ldl -lpthreadLIBS variable of PHP configure command
SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS-g0 -Os -fno-ident -fPIE or -g -O0 -fno-ident -fPIE (the latter when using --no-strip)EXTRA_CFLAGS variable of PHP make command
SPC_CMD_VAR_PHP_MAKE_EXTRA_LIBSemptyExtra EXTRA_LIBS variables for PHP make command
SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS_PROGRAM-all-static (when using clang: -Xcompiler -fuse-ld=lld -all-static)Additional LDFLAGS variable for make command
SPC_NO_MUSL_PATHemptyWhether to not insert the PATH of the musl toolchain (not inserted when the value is yes)

{ld_lib_path} value is /usr/local/musl/$GNU_ARCH-linux-musl/lib

FreeBSD

Due to the small number of users of the FreeBSD system, we do not provide environment variables for the FreeBSD system for the time being.

Unix

For Unix systems such as macOS, Linux, FreeBSD, etc., the following environment variables are common.

var namedefault valuecomment
PATH$BUILD_BIN_PATH:$PATHSystem PATH
PKG_CONFIG_PATH$BUILD_LIB_PATH/pkgconfigpkg-config search path
PKG_CONFIG$BUILD_BIN_PATH/pkg-configpkg-config executable path

Library Environment variables (Unix only)

Starting from 2.2.0, static-php-cli supports custom environment variables for all compilation dependent library commands of macOS, Linux, FreeBSD and other Unix systems.

In this way, you can adjust the behavior of compiling dependent libraries through environment variables at any time. For example, you can set the optimization parameters for compiling the xxx library through xxx_CFLAGS=-O0.

Of course, not every library supports the injection of environment variables. We currently provide three wildcard environment variables with the suffixes:

  • _CFLAGS: CFLAGS for the compiler
  • _LDFLAGS: LDFLAGS for the linker
  • _LIBS: LIBS for the linker

The prefix is the name of the dependent library, and the specific name of the library is subject to lib.json. Among them, the library name with - needs to replace - with _.

Here is an example of an optimization option that replaces the openssl library compilation:

shell
openssl_CFLAGS="-O0"

The library name uses the same name listed in lib.json and is case-sensitive.

TIP

When no relevant environment variables are specified, except for the following variables, the remaining values are empty by default:

var namevar default value
pkg_config_CFLAGSmacOS: $SPC_DEFAULT_C_FLAGS -Wimplicit-function-declaration -Wno-int-conversion, Other: empty
pkg_config_LDFLAGSLinux: --static, Other: empty
imagemagick_LDFLAGSLinux: -static, Other: empty
imagemagick_LIBSmacOS: -liconv, Other: empty
ldap_LDFLAGS-L$BUILD_LIB_PATH
openssl_CFLAGSLinux: $SPC_DEFAULT_C_FLAGS, Other: empty
others...empty

The following table is a list of library names that support customizing the above three variables:

lib name
brotli
bzip
curl
freetype
gettext
gmp
imagemagick
ldap
libargon2
libavif
libcares
libevent
openssl

TIP

Because adapting custom environment variables to each library is a particularly tedious task, and in most cases you do not need custom environment variables for these libraries, so we currently only support custom environment variables for some libraries.

If the library you need to customize environment variables is not listed above, you can submit your request through GitHub Issue.

Released under the MIT License.