Example: we build PHP 8.2 on Windows 11
Step 1: install Microsoft Visual Studio 2019
Step 2: create workspace folder
F:\php-sdk
Step 3: download PHP SDK binary tools
https://github.com/microsoft/php-sdk-binary-tools/archive/refs/heads/master.zip
Step 4: extract PHP SDK binary tools to workspace folder F:\php-sdk
Step 5: download PHP source https://windows.php.net/download/
Example PHP 8.2 https://windows.php.net/downloads/releases/php-8.2.16-src.zip
Step 6: Run VS 2019 x64 Native Tools Command Prompt with Administrator Privileges
cd F:\php-sdk F: phpsdk-starter.bat -c vs16 -a x64 phpsdk_buildtree php-dev
Result:
********************************************************************** ** Visual Studio 2019 Developer Command Prompt v16.11.34 ** Copyright (c) 2021 Microsoft Corporation ********************************************************************** [vcvarsall.bat] Environment initialized for: 'x64' C:\Windows\System32>cd F:\php-sdk C:\Windows\System32>F: F:\php-sdk>phpsdk-starter.bat -c vs16 -a x64 [vcvarsall.bat] Environment initialized for: 'x64' PHP SDK 2.2.1-dev OS architecture: 64-bit Build architecture: 64-bit Visual C++: 14.16.27050.0 PHP-SDK path: F:\php-sdk F:\php-sdk $ phpsdk_buildtree php-dev F:\php-sdk\php-dev\vs16\x64
Note:
PHP 7.1 use vc14
PHP 7.2 7.3 7.4 use vc15
PHP 8.x use vs16
Step 7: Extract PHP Source
F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src
Step 8: download dependencies
cd php* phpsdk_deps -u
Result:
F:\php-sdk\php-dev\vs16\x64 $ cd php* F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src $ phpsdk_deps -u Configuration: 8.2-vs16-x64-stable Processing package apache-2.4.43-vs16-x64.zip Processing package c-client-2007f-1-vs16-x64.zip Processing package fbclient-3.0.6-nocrt-x64.zip Processing package freetype-2.11.1-vs16-x64.zip Processing package glib-2.53.3-1-vs16-x64.zip Processing package ICU-71.1-vs16-x64.zip Processing package libargon2-20190702-vs16-x64.zip Processing package libavif-0.9.0-1-vs16-x64.zip Processing package libbzip2-1.0.8-vs16-x64.zip Processing package libcurl-7.85.0-vs16-x64.zip Processing package libenchant2-2.2.8-vs16-x64.zip Processing package libffi-3.3-4-vs16-x64.zip Processing package libiconv-1.16-5-vs16-x64.zip Processing package libintl-0.18.3-8-vs16-x64.zip Processing package libjpeg-turbo-2.1.0-vs16-x64.zip Processing package liblmdb-0.9.22-6-vs16-x64.zip Processing package liblzma-5.2.5-vs16-x64.zip Processing package libonig-6.9.8-vs16-x64.zip Processing package libpng-1.6.34-8-vs16-x64.zip Processing package libpq-11.4-1-vs16-x64.zip Processing package libqdbm-1.8.78-vs16-x64.zip Processing package libsasl-2.1.27-3-vs16-x64.zip Processing package libsodium-1.0.18-vs16-x64.zip Processing package libssh2-1.10.0-2-vs16-x64.zip Processing package libtidy-5.6.0-2-vs16-x64.zip Processing package libwebp-1.3.2-vs16-x64.zip Processing package libxml2-2.10.3-vs16-x64.zip Processing package libxpm-3.5.12-8-vs16-x64.zip Processing package libxslt-1.1.37-vs16-x64.zip Processing package libzip-1.7.1-1-vs16-x64.zip Processing package mpir-3.0.0-vs16-x64.zip Processing package net-snmp-5.7.3-3-vs16-x64.zip Processing package nghttp2-1.49.0-vs16-x64.zip Processing package openldap-2.4.47-1-vs16-x64.zip Processing package openssl-3.0.13-vs16-x64.zip Processing package sqlite3-3.39.2-vs16-x64.zip Processing package wineditline-2.206-vs16-x64.zip Processing package zlib-1.2.12-vs16-x64.zip Updates performed successfully. Old dependencies backed up into 'F:\php-sdk\php-dev\vs16\x64\deps.202402231618'.
Step 9: compile PHP
F:\php-sdk\phpsdk-vs16-x64.bat buildconf configure --disable-all --enable-cli nmake
note: to disable thread safety in PHP use:
configure --disable-all --enable-cli --disable-zts
result:
F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src $ F:\php-sdk\phpsdk-vs16-x64.bat [vcvarsall.bat] Environment initialized for: 'x64' PHP SDK 2.2.1-dev OS architecture: 64-bit Build architecture: 64-bit Visual C++: 14.16.27050.0 PHP-SDK path: F:\php-sdk F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src $ buildconf Rebuilding configure.js Now run 'configure --help' F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src $ configure --disable-all --enable-cli PHP Version: 8.2.16 Saving configure options to config.nice.bat Checking for cl.exe ... <in default path> Detected compiler Visual C++ 2019 Detected x64 compiler Checking for link.exe ... <in default path> Checking for nmake.exe ... <in default path> Checking for lib.exe ... <in default path> Checking for bison.exe ... <in default path> Detected bison version 3.3.2 Checking for sed.exe ... <in default path> Checking for re2c.exe ... <in default path> Detected re2c version 1.1.1 Checking for zip.exe ... <in default path> Checking for lemon.exe ... <in default path> Checking for 7za.exe ... <in default path> Checking for mc.exe ... C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64 Checking for mt.exe ... C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64 Enabling multi process build Build dir: F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS PHP Core: php8ts.dll and php8ts.lib Checking for ML64.exe ... <in default path> Checking for wspiapi.h ... <in default path> Enabling IPv6 support Enabling SAPI sapi\cli Checking for library edit_a.lib;edit.lib ... <in deps path> \lib\edit_a.lib Checking for editline/readline.h ... <in deps path> \include Enabling extension ext\date Enabling extension ext\hash Checking for KeccakHash.h ... ext/hash/sha3/generic64lc Checking for PMurHash.h ... ext/hash/murmur Checking for xxhash.h ... ext/hash/xxhash Enabling extension ext\json Enabling extension ext\pcre Enabling extension ext\random Enabling extension ext\reflection Enabling extension ext\spl Checking for timelib_config.h ... ext/date/lib Enabling extension ext\standard Creating build dirs... Generating files... Generating Makefile Generating main/internal_functions.c Generating main/config.w32.h Generating phpize Done. Enabled extensions: ----------------------- | Extension | Mode | ----------------------- | date | static | | hash | static | | json | static | | pcre | static | | random | static | | reflection | static | | spl | static | | standard | static | ----------------------- Enabled SAPI: ------------- | Sapi Name | ------------- | cli | ------------- ----------------------------------------- | | | ----------------------------------------- | Build type | Release | | Thread Safety | Yes | | Compiler | Visual C++ 2019 | | Target Architecture | x64 | | Host Architecture | x64 | | Optimization | PGO disabled | | Native intrinsics | SSE2 | | Static analyzer | disabled | ----------------------------------------- Type 'nmake' to build PHP F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src $ nmake Microsoft (R) Program Maintenance Utility Version 14.16.27050.0 Copyright (C) Microsoft Corporation. All rights reserved. Recreating build dirs bison.exe --output=Zend/zend_ini_parser.c -v -d Zend/zend_ini_parser.y bison.exe --output=Zend/zend_language_parser.c -v -d Zend/zend_language_parser.y "re2c.exe" --no-generation-date --case-inverted -cbdFt Zend/zend_ini_scanner_defs.h -oZend/zend_ini_scanner.c Zend/zend_ini_scanner.l "re2c.exe" --no-generation-date --case-inverted -cbdFt Zend/zend_language_scanner_defs.h -oZend/zend_language_scanner.c Zend/zend_language_scanner.l bison.exe --output=sapi/phpdbg/phpdbg_parser.c -v -d sapi/phpdbg/phpdbg_parser.y "re2c.exe" --no-generation-date -cbdFo sapi/phpdbg/phpdbg_lexer.c sapi/phpdbg/phpdbg_lexer.l type ext\pcre\php_pcre.def > F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\php8ts.dll.def "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22000.0\x64\mc.exe" -h win32\ -r F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\ -x F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\ win32\build\wsyslog.mc MC: Compiling win32\build\wsyslog.mc php_cli.c php_cli_process_title.c php_cli_server.c php_http_parser.c ps_title.c zend.c zend_API.c zend_alloc.c zend_ast.c zend_atomic.c zend_attributes.c zend_builtin_functions.c zend_closures.c zend_compile.c zend_constants.c zend_cpuinfo.c zend_default_classes.c zend_enum.c zend_exceptions.c zend_execute.c zend_execute_API.c zend_extensions.c zend_fibers.c zend_float.c zend_gc.c zend_generators.c zend_hash.c zend_highlight.c zend_inheritance.c zend_ini.c zend_ini_parser.c zend_ini_scanner.c zend_interfaces.c zend_iterators.c zend_language_parser.c zend_language_scanner.c zend_list.c zend_llist.c zend_multibyte.c zend_object_handlers.c zend_objects.c zend_objects_API.c zend_observer.c zend_opcode.c zend_operators.c zend_ptr_stack.c zend_smart_str.c zend_sort.c zend_stack.c zend_stream.c zend_string.c zend_strtod.c zend_system_id.c zend_variables.c zend_virtual_cwd.c zend_vm_opcodes.c zend_weakrefs.c block_pass.c compact_literals.c compact_vars.c dce.c dfa_pass.c escape_analysis.c nop_removal.c optimize_func_calls.c optimize_temp_vars_5.c pass1.c pass3.c sccp.c scdf.c zend_call_graph.c zend_cfg.c zend_dfg.c zend_dump.c zend_func_info.c zend_inference.c zend_optimizer.c zend_ssa.c SAPI.c fopen_wrappers.c getopt.c internal_functions.c main.c network.c output.c php_content_types.c php_ini.c php_ini_builder.c php_odbc_utils.c php_open_temporary_file.c php_scandir.c php_syslog.c php_ticks.c php_variables.c reentrancy.c rfc1867.c safe_bcmp.c snprintf.c spprintf.c strlcat.c strlcpy.c cast.c filter.c glob_wrapper.c memory.c mmap.c plain_wrapper.c streams.c transports.c userspace.c xp_socket.c codepage.c console.c dllmain.c fnmatch.c ftok.c getrusage.c glob.c globals.c inet.c ioutil.c nice.c readdir.c registry.c select.c sendmail.c signal.c sockets.c time.c winutil.c wsyslog.c TSRM.c tsrm_win32.c php_date.c astro.c dow.c interval.c parse_date.c parse_iso_intervals.c parse_posix.c parse_tz.c timelib.c tm2unixtime.c unixtime2tm.c hash.c hash_adler32.c hash_crc32.c hash_fnv.c hash_gost.c hash_haval.c hash_joaat.c hash_md.c hash_murmur.c hash_ripemd.c hash_sha.c hash_sha3.c hash_snefru.c hash_tiger.c hash_whirlpool.c hash_xxhash.c KeccakP-1600-opt64.c KeccakHash.c KeccakSponge.c PMurHash.c PMurHash128.c ext\hash\murmur\PMurHash128.c(485): warning C4028: formal parameter 3 different from declaration json.c bison.exe --defines -l ext/json/json_parser.y -o ext/json/json_parser.tab.c "re2c.exe" -t ext/json/php_json_scanner_defs.h --no-generation-date -bci -o ext/json/json_scanner.c ext/json/json_scanner.re json_encoder.c json_parser.tab.c json_scanner.c php_pcre.c pcre2_auto_possess.c pcre2_chartables.c pcre2_compile.c pcre2_config.c pcre2_context.c pcre2_convert.c pcre2_dfa_match.c pcre2_error.c pcre2_extuni.c pcre2_find_bracket.c pcre2_jit_compile.c pcre2_maketables.c pcre2_match.c pcre2_match_data.c pcre2_newline.c pcre2_ord2utf.c pcre2_pattern_info.c pcre2_script_run.c pcre2_serialize.c pcre2_string_utils.c pcre2_study.c pcre2_substitute.c pcre2_substring.c pcre2_tables.c pcre2_ucd.c pcre2_valid_utf.c pcre2_xclass.c random.c engine_combinedlcg.c engine_mt19937.c engine_pcgoneseq128xslrr64.c engine_secure.c engine_user.c engine_xoshiro256starstar.c randomizer.c php_reflection.c php_spl.c spl_array.c spl_directory.c spl_dllist.c spl_exceptions.c spl_fixedarray.c spl_functions.c spl_heap.c spl_iterators.c spl_observer.c cd F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src "re2c.exe" --no-generation-date -b -o ext/standard/url_scanner_ex.c ext/standard/url_scanner_ex.re cd F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src "re2c.exe" --no-generation-date -b -o ext/standard/var_unserializer.c ext/standard/var_unserializer.re array.c assert.c base64.c basic_functions.c browscap.c crc32.c crc32_x86.c credits.c crypt.c crypt_blowfish.c crypt_freesec.c crypt_sha256.c crypt_sha512.c css.c datetime.c dir.c dl.c dns.c dns_win32.c exec.c file.c filestat.c filters.c flock_compat.c formatted_print.c fsock.c ftok.c ftp_fopen_wrapper.c head.c hrtime.c html.c http.c http_fopen_wrapper.c image.c incomplete_class.c info.c iptc.c levenshtein.c link.c mail.c math.c md5.c metaphone.c microtime.c net.c pack.c pageinfo.c password.c php_crypt_r.c php_fopen_wrapper.c proc_open.c quot_print.c scanf.c sha1.c soundex.c streamsfuncs.c string.c strnatcmp.c syslog.c type.c uniqid.c url.c url_scanner_ex.c user_filters.c uuencode.c var.c var_unserializer.c versioning.c avifinfo.c rc /nologo /fo F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\php8ts.dll.res /d FILE_DESCRIPTION="\"PHP Script Interpreter\"" /d FILE_NAME="\"php8ts.dll\"" /d PRODUCT_NAME="\"PHP Script Interpreter\"" /IF:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS /d MC_INCLUDE="\"F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\wsyslog.rc\"" win32\build\template.rc ML64.exe /DBOOST_CONTEXT_EXPORT=EXPORT /nologo /c /Fo F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\Zend\jump_x86_64_ms_pe_masm.obj Zend\asm\jump_x86_64_ms_pe_masm.asm Assembling: Zend\asm\jump_x86_64_ms_pe_masm.asm ML64.exe /DBOOST_CONTEXT_EXPORT=EXPORT /nologo /c /Fo F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\Zend\make_x86_64_ms_pe_masm.obj Zend\asm\make_x86_64_ms_pe_masm.asm Assembling: Zend\asm\make_x86_64_ms_pe_masm.asm Creating library F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\php8ts.lib and object F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\php8ts.exp Creating library F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\php.lib and object F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS\php.exp SAPI sapi\cli build complete
done! output: F:\php-sdk\php-dev\vs16\x64\php-8.2.16-src\x64\Release_TS