How to get zip extension working in PHP in MacOS 10.15.1?

5,138

Good summary. I did not need 2 and 3.

Then for the signature

11. You need to start XCode and add an account.

Add an account to XCode

Download a certificate

12. In terminal check with certtool y for your new Signing Key. It's named like:

Common Name     : Apple Development:
[email protected] (xxxxxxxx)

Still with your user in the terminal sign the file (move it back if not anymore in the build folder, otherwise you end with a permission error)

codesign -f -s "Apple Development: [email protected]" /usr/local/lib/php/extensions/zip.so

Move it to the target folder, run php --version and you end with:

PHP Warning: PHP Startup: Unable to load dynamic library 'zip' (tried: /usr/local/lib/php/extensions/zip (dlopen(/usr/local/lib/php/extensions/zip, 0x0009): dlopen(): file not found: /usr/local/lib/php/extensions/zip), /usr/local/lib/php/extensions/zip.so (dlopen(/usr/local/lib/php/extensions/zip.so, 0x0009): code signature in (/usr/local/lib/php/extensions/zip.so) not valid for use in process: mapping process is a platform binary, but mapped file is not)) in Unknown on line 0 PHP 7.3.11 (cli) (built: Feb 29 2020 02:50:36) ( NTS )

Ok, i looked around the internet (insightful resurce), and the bits i found paint a dark image. In short: It's not possible anymore with Mac Os Catalina.

The errormessage tells it too. The Php environment is signed as system component (platform binary) and is installed by default. Mac Os Catalina enforces that platform binaries only load code which is also a platform binary. Which one can not do, because you are not Apple.

Leaving two possible options. Disabling the whole Signature enforcement stystemwide whic is a bad idea. Or setup a replacement Php completely selfbuild or with homebrew.

Share:
5,138

Related videos on Youtube

WRD
Author by

WRD

Updated on September 18, 2022

Comments

  • WRD
    WRD over 1 year

    I've cobbled the following procedure together from a couple of different questions here, and on the Apple support forums. None of them have worked on their own, but this appears to be close. The problem is I wind up with an unsigned extension that MacOS refuses to load; can anyone help me get that last (I hope) problem resolved?

    1. Install autoconf.

    cd ~/Downloads
    curl -O -L http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz
    tar -xzf autoconf-2.69.tar.gz
    cd autoconf-2.69
    ./configure
    make
    sudo make install
    

    2. Install automake

    cd ~/Downloads
    curl -O -L http://ftpmirror.gnu.org/automake/automake-1.15.tar.gz
    tar -xzf automake-1.15.tar.gz
    cd automake-1.15
    ./configure
    make
    sudo make install
    

    3. Install libtool

    cd ~/Downloads
    curl -OL http://ftpmirror.gnu.org/libtool/libtool-2.4.6.tar.gz
    tar -xzf libtool-2.4.6.tar.gz
    cd libtool-2.4.6
    ./configure
    make
    sudo make install
    

    4. Install CMake

    Download the disk image from: https://github.com/Kitware/CMake/releases/download/v3.16.0-rc3/cmake-3.16.0-rc3-Darwin-x86_64.dmg

    Mount the image and drag the application to your Applications folder.

    Edit your .zshrc file (or create one in your home directory if you don't have one).

    Add the line:

    export PATH="$PATH:/Applications/CMake.app/Contents/bin"
    

    Save the file and type the command:

    source ~/.zshrc
    

    5. Install libzip

    cd ~/Downloads
    curl -OL https://libzip.org/download/libzip-1.5.2.tar.gz
    tar -xzf libzip-1.5.2.tar.gz
    cd libzip-1.5.2
    mkdir build
    cd build
    cmake ..
    make
    sudo make install
    

    6. Create a temporary copy of phpize that uses Xcode's libraries

    cd ~
    cp /usr/bin/phpize ~/Desktop/
    

    Edit the copy of phpize that's now on your desktop, and change this line:

    includedir="`eval echo ${prefix}/include`/php"
    

    ...to:

    includedir="/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/php"
    

    Save the modified phpize file.

    7. Download the source code for the correct version of PHP -- 7.3.9 as of MacOS 10.15.1

    cd ~/Downloads
    curl -O -L https://www.php.net/distributions/php-7.3.9.tar.bz2
    tar -yxf php-7.3.9.tar.bz2
    cd php-7.3.9/ext/zip
    

    8. Build the extension

    ~/Desktop/phpize
    CFLAGS="-I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/php/main -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/php/Zend -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/php/TSRM -I/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/php" ./configure --with-zlib-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr --with-php-config=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/bin/php-config
    make
    make install
    sudo mkdir /usr/local/lib/php/extensions
    sudo mv modules/zip.so /usr/local/lib/php/extensions/
    

    NOTE: I expect make install to fail due to permission errors, but one of the other discussions I found suggested that this step was necessary to sign the code. It doesn't seem to have that effect, however.

    9. Edit the /etc/php.ini file

    extension_dir="/usr/local/lib/php/extensions"
    extension=zip
    

    10. Test with command:

    php --version
    

    Result

    PHP Warning: PHP Startup: Unable to load dynamic library 'zip' (tried: /usr/local/lib/php/extensions/zip (dlopen(/usr/local/lib/php/extensions/zip, 0x0009): dlopen(): file not found: /usr/local/lib/php/extensions/zip), /usr/local/lib/php/extensions/zip.so (dlopen(/usr/local/lib/php/extensions/zip.so, 0x0009): code signature in (/usr/local/lib/php/extensions/zip.so) not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.)) in Unknown on line 0

  • Ramhound
    Ramhound about 4 years
    This answer seems to be incomplete
  • gone
    gone almost 4 years
    With the March 30, 2020 edit, this is a great answer, though it may not be what you were hoping for. I particularly like the explanation concerning certificates (which is a murky topic and most of the time is explained poorly by others, who may be making assumptions of their reader's knowledge). This issue does not prevent php, based on my experience using the default 7.3.11 on Catalina 10.15.3, from executing the PHP scripts from either the CLI or those associated with a website.under brew's Apache. It just produces a PHP Warning; albeit one that would be nice to get rid of.
  • Ares
    Ares almost 3 years
    It is possible but you have to disable (temporarily) the system protection to be able to load the module.