简体   繁体   中英

MacOS Catalina: Class 'ZipArchive' not found

Upgrading to 10.15.1 (19B88) Mac OS Catalina broke my PHP 7.3.9 development environment.

$zip = new \ZipArchive;

Yields Exception 'Error' with message 'Class 'ZipArchive' not found'

zip and unzip are installed at Terminal command line.

Trying to use PECL failed. Trying to use Homebrew failed.

Do you know how to properly install ZipArchive manually on MacOS?

I had the same problem and this is what helped me. Basically what I did is I just installed php using brew and then linked the php that I have installed using brew inside of httd.conf file. Here are the steps:

  1. Install php using home brew

    brew install php@7.3

This will install php. Now we need to link it

brew link php@7.3

If the command above wont work because of the missing directories, then just create them using mkdir and run it again.

  1. Link you php in httd.conf file

Open the httpd.conf file which is located here /private/etc/apache2/httpd.conf Open it and change this line

LoadModule php7_module libexec/apache2/libphp7.so

to this:

LoadModule php7_module /usr/local/Cellar/php/7.3.11/lib/httpd/modules/libphp7.so

What this basically dow is it just makes apache to use php that is installed using homebrew. Hope this was helpful to you.

Here is a link where it is better described how to connect homebrew installed php:

How to use the php that brew installed?

What I did was the following,

brew install php@7.3

php version 7.3.19 was installed.

Then edited my httpd.conf using

sudo nano /private/etc/apache2/httpd.conf 

The following line in http.conf

LoadModule php7_module libexec/apache2/libphp7.so

was replaced with

LoadModule php7_module /usr/local/opt/php@7.3/lib/httpd/modules/libphp7.so

Added the following to http.conf right after modules block

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

In nano I searched for DirectoryIndex using ctrl+W added index.php to finally make it

DirectoryIndex index.php index.html

Then I updated my PATH variable using

echo 'export PATH="/usr/local/opt/php@7.3/bin:$PATH"' >> /Users/<your user>/.bash_profile
echo 'export PATH="/usr/local/opt/php@7.3/sbin:$PATH"' >> /Users/<your user>/.bash_profile

Then I made a new directory sbin as following,

sudo mkdir /usr/local/sbin

Changed ownership to current user,

sudo chown -R $(whoami) /usr/local/sbin

Linked brew

brew link php@7.3 --force

Restarted Apache

sudo apachectl restart

Please Note: You do not have to probably do all of the steps or do it in same order, I only wanted to share what I did and worked for me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM