Where is my php extensions directory?
Photo by Don Graham and used under Creative Common 2.0 Attribution-ShareAlike license. Show Taking a break from development for a day or two and upgrading my laptop to Catalina seemed like a good way to kick off the new year. Catalina upgrades the System PHP version from 7.2.x to 7.3.9, which is a change I am eager to get as PHP 7.2 is no longer actively supported by the PHP developer community. The OS X upgrade process always includes a few surprises for developers, however. A big surprise in this upgrade was that Catalina improves security by adding a read-only file system for critical system files you don't want tampered with. That makes a lot of sense, but it also complicates using PECL or phpize, because the paths under /usr that they references are read-only now. After the upgrade my dev sites were by-and-large working well, but on one site I ran into the following error:
It turns out that the PHP 7.3 that ships with Catalina does not include the zip/ZipArchive support. This project requires ZipArchive, so either I could switch to a different method of installing PHP, like using brew or a Docker or Lando environment, or I could figure out how to reenable zip support in the system PHP. I went with the latter approach. Personally, I love Lando for secondary PHP versions but I find the performance penalty running Docker on a Mac too high to use it for my primary environment. This project, for example requires frequent site rebuilds, which make the efficiency gains from making that a 10 minute process rather than close to an hour critical to my productivity. A lot of the developers at Affinity Bridge use brew to run multiple PHP versions on their laptops. I've used that approach too but have experienced headaches managing dependencies that way, with what is intended to be a small change to my AMP stack triggering updates of seemingly unrelated tools like python3 that cause breakage elsewhere in my environment. So if I can avoid this approach, I do. I gleaned information from a number of other developers who've run into similar problems and I came up with a solution. Step 1: Install PEAR/PECL support
(credit) Step 2: Download zip extension source I tried installing zip with pecl, but that failed because the PHP header files were missing. So I downloaded the source for the zip extension from pecl.
Step 3: Download PHP src/header files To build PHP extensions, you need the header files for the version of PHP you are targetting. On OS X this is done with XCode (credit).
To verify that the header files are available now and find their path:
Step 4: Copy/modify phpsize and php-config In order to make phpize and php-config find the PHP header files in the location that XCode places them rather than in /usr/include/php -- a read-only location now -- I followed some tips I found elsewhere and copied and modified phpize and php-config to change the include directory in each of them.
Then I edited the include path in each of them. Here are the diffs:
Step 5: Build the zip PHP extension With all of those changes in place, I could now build the zip extension.
Step 6: Install zip PHP extension make install fails to install the extension, again because of the read-only file system. So instead I created an extension directory under /usr/local/php.
Step 7: Update your PHP.ini Finally we need to tell PHP to load this extension.
Add the following line:
Restart apache with sudo apachectl restartand you'll see the zip extension being loaded now. I expect the PHP and Mac development community will work out the issues with the read-only filesystem causing make and PECL install to fail, but knowing how to compile your own PHP extensions and use them with the system PHP on OS X is super useful. Presumably this process could be used for other useful PHP extensions like xdebug. Happy coding! How do I see PHP extensions?If your server only has a single PHP version installed, you can run this PHP command anywhere, and it will give you the same list of modules. The general command we will be using is php -m. This command will give you the full list of installed PHP modules/extensions.
How do I install PHP extensions?How To Compile And Install PHP Extensions From Source. Install the PHP development package. On Ubuntu/debian, you can use apt-get, it's a piece of cake. ... . Download & unzip the PHP5 source code. ... . Prepare the extension (phpize) ... . Configure & Make the extension. ... . Move the extension. ... . Edit your PHP. ... . Restart your php.. How can I see PHP extensions in cPanel?How to Enable/Disable PHP Extensions From cPanel?. Login to cPanel.. Locate Select PHP version and click on it.. Choose your desired PHP version and click on Set as Current. ... . To set the PHP extensions, Click on Switch to PHP settings.. Click on the extension you wish to change, enter the value and save the settings.. What are PHP extensions?A PHP extension is a specially formed library or plug-in that provides a function that can be used by many applications.
|