Setup PHP for 4D
Clone or download php-src.
By default, re2c
is missing and bison
is too old.
brew install re2c
brew install bison
echo 'export PATH="/opt/homebrew/opt/bison/bin:$PATH"' >> ~/.zshrc
Restart Terminal.
cd {php-src-master}
autoreconf
export LIBS="-lz"
/configure --enable-static --without-iconv --prefix={path-to-install-dir}
make
make install
This will install static php-cgi
with only the following system dependencies:
/usr/lib/libresolv.9.dylib
/usr/lib/libnetwork.dylib
/usr/lib/libSystem.B.dylib
/usr/lib/libz.1.dylib
/usr/lib/libsqlite3.dylib
For comparision, the v20 php-fcgi-4d
file looks like this:
/usr/lib/libresolv.9.dylib
/usr/lib/libnetwork.dylib
/usr/lib/libSystem.B.dylib
According to the PHP modules support documentation, SQLite3
is enabled so the library must be statically linked. Zip
, Zlib
, Iconv
, as well as XML-releated featured that depend on Zlib
are all disabled.
To create universal binary, restart Terminal using Rosetta, make distclean
, repeat, then lipo -create
.
Download libraries, then lipo -create
:
brew fetch --bottle-tag=arm64_big_sur sqlite
brew fetch --bottle-tag=x86_64_big_sur sqlite
brew fetch --bottle-tag=arm64_big_sur zlib
brew fetch --bottle-tag=x86_64_big_sur zlib
Indicate static library location:
export LDFLAGS="-L{path-to-static-library-dir}"
export LIBS="-lz -lsqlite3"
Error: sqlite3.c:446:6: error: call to undeclared function 'sqlite3_load_extension'
c.f. https://bugs.python.org/issue44997
We could edit /ext/sqlite3/sqlite3.stub.php like so:
#ifndef SQLITE_OMIT_LOAD_EXTENSION
/** @tentative-return-type */
# public function loadExtension(string $name): bool {}
#define SQLITE_OMIT_LOAD_EXTENSION 1
#endif
…but this won't update the source files.
Solution: Remove from ext/sqlite3/sqlite3_arginfo.h
#if !defined(SQLITE_OMIT_LOAD_EXTENSION)
ZEND_BEGIN_ARG_WITH_TENTATIVE_RETURN_TYPE_INFO_EX(arginfo_class_SQLite3_loadExtension, 0, 1, _IS_BOOL, 0)
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
ZEND_END_ARG_INFO()
#endif
…and add to ext/sqlite3/sqlite3.c
#define SQLITE_OMIT_LOAD_EXTENSION 1
This will install static php-cgi
with the same 3 dependencies as php-fcgi-4d
.
Download libraries, then lipo -create
:
brew fetch --bottle-tag=arm64_big_sur libiconv
brew fetch --bottle-tag=x86_64_big_sur libiconv
Error: configure: error: Please reinstall the iconv library.
Indicate static library location:
We could indicate static library location. Also add -liconv
to LDFLAGS
:
export CFLAGS="-I{path-to-user-header-dir}"
export LDFLAGS="-L{path-to-static-library-dir} -liconv"
export LIBS="-lz -lsqlite3 -liconv"
…but this won't eliminate compiler errors.
Solution: Remove #undef
ext/iconv/iconv.c
#ifdef HAVE_LIBICONV
//#undef iconv
#endif
Rename the program as php-fcgi-4d
and replace the one inside 4D.app.
Test call:
var $returnValue : Text
$success:=PHP Execute(""; "phpversion"; $returnValue)
var $response : Text
ARRAY TEXT($labels; 0)
ARRAY TEXT($values; 0)
PHP GET FULL RESPONSE($response; $labels; $values)
Result: $success
is False
. Activity Monitor shows multiple instances of php-fcgi-4d
. X-4DPHP-Error-php-interpreter
contains the message:
PHP Fatal error: Uncaught Error: Call to undefined function mb_convert_encoding() in _4D_Execute_PHP.php:131
Solution: Add --enable-mbstring
to configure
.
The homebrew distribution of libzip is dynamic-only.
Solution: Build from source. Uncheck BUILD_SHARED_LIBS
in CMake.
Modules or Extension | Configure Option | 4D v20 | This Repository |
---|---|---|---|
BCMath | --enable-bcmath |
||
Calendar | --enable-calendar |
||
Character type checking | (default) | ||
Client URL Library | --with-curl=DIR |
disabled | |
Date and Time | (default) | ||
Document Object Model | (default) | disabled | |
Exchangeable image information | --enable-exif |
||
File Information | (default) | ||
Data Filtering | (default) | ||
FTP | --enable-ftp |
||
GNU Multiple Precision | --with-gmp |
disabled | |
HASH Message Digest Framework | (default) | ||
iconv | (default) | disabled | |
Image Processing and GD | --enable-gd --with-avif --with-webp --with-jpeg --enable-gd-jis-conv |
disabled | |
JavaScript Object Notation | (default) | ||
libxml | (default) | disabled | |
Lightweight Directory Access Protocol | --with-ldap |
||
Multibyte String | --enable-mbstring |
||
OpenSSL | --with-openssl |
||
Regular Expressions (Perl-Compatible) | (default) | ||
PHP Data Objects | (default) | ||
SQLite Functions (PDO_SQLITE) | (default) | ||
Phar | (default) | ||
POSIX | (default) | ||
Random Number Generators and Functions Related to Randomness | (default) | ||
Reflection | (default) | ||
Sessions | (default) | ||
SimpleXML | (default) | disabled | |
Sockets | --enable-sockets |
||
SQLite3 | (default) | ||
Standard PHP Library (SPL) | (default) | ||
Tidy | --with-tidy=DIR |
disabled | |
Tokenizer | (default) | ||
XML Parser | (default) | disabled | |
XMLReader | (default) | disabled | |
XMLWriter | (default) | disabled | |
Zip | --with-zip |
disabled | |
Zlib Compression | --with-zlib |
disabled |
./configure
--with-tidy=DIR
--with-ldap=DIR
--with-curl=DIR
--with-openssl=DIR
--with-zlib
--with-gmp
--with-zip
--enable-static
--enable-bcmath
--enable-calendar
--enable-exif
--enable-ftp
--enable-gd --with-avif --with-webp --with-jpeg --enable-gd-jis-conv
--enable-sockets
--enable-mbstring
export LIBS="
-lz
-lsqlite3
-liconv
-lbz2
-lzip
-lzstd
-lonig
-llzma
-lgd
-lwebp -lavif -ltiff -lpng16 -lsharpyuv
-ltidy
-lgmp
-lcrypto -lssl
-lcurl -lnghttp2 -lidn2 -lssh2 -lldap -llber
-lbrotlidec -lbrotlienc -lbrotlicommon
-lsasl2
-lunistring
-lrtmp
-framework GSS
-framework SystemConfiguration
-framework Cocoa
-framework Security
-framework LDAP
-framework Kerberos"
Error: configure: error: There is something wrong. Please check config.log for more information.
Solution: Add path to custom installations:
./configure
--with-curl=DIR
--with-openssl=DIR
Error: Undefined symbols: libunistring
expects a non-plug version of libiconv
.
Solution: Compile and use a hybrid version that contains both names (_iconv
and _libiconv
).
Error: Undefined symbols: libbrotli
constants.
Solution: Specify subdirectory paths to header files:
export CFLAGS="
-I{path-to-user-header-dir}
-I{path-to-user-header-dir}/brotli
-I{path-to-user-header-dir}/curl"
Error: configure: error: Cannot find ldap.h
Solution: Add path to custom installations:
./configure
--with-ldap=DIR
Build static PHP with interactive shell support
Error: configure: error: Please reinstall readline - I cannot find readline.h
Solution: Add path to custom installations:
--with-readline=DIR