4

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?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Lookahead
  • 41
  • 1
  • 5
  • See https://www.php.net/manual/en/zip.installation.php. Your PHP installation doesn't seem to have been built with it. – deceze Oct 30 '19 at 08:30
  • I think Catalina replaced my version of PHP with one without ZipArchive, because MacOS doesn’t use zip natively. Pre Catalina, ZipArchive existed. Post Catalina, it was gone. How to fix it? Unknown. For now I am using System(‘zip xxx’); – Lookahead Oct 31 '19 at 14:36
  • Install your own desired PHP version, don't rely on the builtin one. That's pretty much always been true. http://brew.sh – deceze Oct 31 '19 at 14:41
  • 1
    There's a good tutorial on how to fix it: https://affinitybridge.com/blog/adding-php-extensions-system-php-under-os-x-1015-catalina – IonV Oct 26 '20 at 19:18

2 Answers2

8

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?

  • 2
    Note that your path may be different from the one above. Mine is: /usr/local/Cellar/php@7.3/7.3.14/lib/httpd/modules/libphp7.so One your line is changed, type "sudo apachectl restart" for it to take effect. – Bernz Jan 26 '20 at 19:38
0

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.

Faisal
  • 752
  • 6
  • 9