Search code examples
phpwindowscompilationembed

How to compile PHP Embed SAPI with snapshot build extensions statically compiled


The problem


Trying to compile a Windows Embed SAPI PHP binary that includes the core PHP and snapshot extensions, with as many of them as possible statically linked.

Trying with PHP 7.4, ZTS, x64 VC15 (Visual Studio 2017)

What I’ve tried (using Appveyor)


configure.bat --!ZTS_STATE!-zts --enable-object-out-dir=%PHP_BUILD_OBJ_DIR% --with-config-file-scan-dir=%APPVEYOR_BUILD_FOLDER%\build\modules.d --with-prefix=%APPVEYOR_BUILD_FOLDER%\build --with-php-build=%DEPS_DIR% --enable-embed --enable-cli-win32  --enable-snapshot-build --enable-debug-pack --enable-com-dotnet=shared --without-analyzer --disable-phpdbg-webhelper --disable-cgi LDFLAGS=-static


configure.bat --!ZTS_STATE!-zts --enable-object-out-dir=%PHP_BUILD_OBJ_DIR% --with-config-file-scan-dir=%APPVEYOR_BUILD_FOLDER%\build\modules.d --with-prefix=%APPVEYOR_BUILD_FOLDER%\build --with-php-build=%DEPS_DIR% --enable-embed --enable-cli-win32  --enable-snapshot-build --enable-debug-pack --enable-com-dotnet=shared --without-analyzer --disable-phpdbg-webhelper --disable-cgi --enable-static=yes


configure.bat --!ZTS_STATE!-zts --enable-object-out-dir=%PHP_BUILD_OBJ_DIR% --with-config-file-scan-dir=%APPVEYOR_BUILD_FOLDER%\build\modules.d --with-prefix=%APPVEYOR_BUILD_FOLDER%\build --with-php-build=%DEPS_DIR% --enable-embed --enable-cli-win32  --enable-snapshot-build --enable-debug-pack --enable-com-dotnet=shared --without-analyzer --disable-phpdbg-webhelper --disable-cgi --enable-shared=no --enable-static=yes

The above commands give me a number of warinings as per below:

  • Unknown option LDFLAGS; please try configure.js --help for a list of valid options
  • Unknown option --enable-static; please try configure.js --help for a list of valid options
  • The following arguments is invalid, and therefore ignored: --enable-shared --enable-static

Notes


  • I am aware some extensions can not be statically compiled i.e com_dotnet etc
  • Tried variations on the commands provided on the similar question: Compile PHP into Static Binary (This question is very specific to a broken install (relating to libxml2) and I would suggest not be marked as a duplicate of this one)
  • I see references to --enable-static all over google but it doesnt seem to be a valid argument.

Solution

  • Ended up with the following command:

    configure.bat --!ZTS_STATE!-zts --enable-object-out-dir=%PHP_BUILD_OBJ_DIR% --with-config-file-scan-dir=%APPVEYOR_BUILD_FOLDER%\build\modules.d --with-prefix=%APPVEYOR_BUILD_FOLDER%\build --with-php-build=%DEPS_DIR% --disable-cgi --enable-embed=static --enable-cli-win32 --enable-bcmath=static --enable-calendar=static --enable-ctype=static --with-dom=static --enable-filter=static --with-iconv=static --enable-json=static --with-libxml=static --with-mysqlnd=static --enable-pdo --enable-phar --with-readline=static --enable-session=static --enable-tokenizer=static --with-xml=static --enable-xmlreader=static --enable-xmlwriter=static --enable-zip=static --enable-zlib=static --with-sodium=static --with-sqlite3=static --enable-sysvshm=static --with-tidy=static --with-xmlrpc=static --with-xsl=static --with-bz2=static --with-com_dotnet=shared --with-curl=static --with-dba=static --with-enchant=static --enable-exif=static --with-ffi=static --enable-fileinfo=shared --enable-ftp=static --with-gd --with-gettext=static --with-gmp=static --with-imap=static --enable-intl=static --with-ldap=static --enable-mbstring=static --with-mysqli=static --enable-odbc=static --enable-opcache --with-openssl=static --with-pdo_sqlite=shared --enable-shmop --with-snmp=static --enable-sockets
    

    Which resulted in the following build:

    -----------------------
    | Extension  | Mode   |
    -----------------------
    | bz2        | static |
    | com_dotnet | static |
    | date       | static |
    | dba        | static |
    | exif       | static |
    | ffi        | static |
    | fileinfo   | shared |
    | ftp        | static |
    | gettext    | static |
    | gmp        | static |
    | hash       | static |
    | iconv      | static |
    | intl       | shared |
    | json       | static |
    | ldap       | static |
    | mbstring   | static |
    | mysqlnd    | static |
    | openssl    | static |
    | pcre       | static |
    | pdo        | static |
    | phar       | static |
    | readline   | static |
    | reflection | static |
    | shmop      | static |
    | snmp       | static |
    | sockets    | static |
    | sodium     | static |
    | spl        | static |
    | sqlite3    | static |
    | standard   | static |
    | sysvshm    | static |
    | tidy       | static |
    | xmlrpc     | static |
    | zip        | static |
    -----------------------
    Enabled Zend extensions:
    ----------------------
    | Extension | Mode   |
    ----------------------
    | opcache   | shared |
    ----------------------
    Enabled SAPI:
    -------------
    | Sapi Name |
    -------------
    | cli       |
    | cli_win32 |
    | embed     |
    -------------