I have installed ImageMagick using brew install imagemagick. This all worked fine and I can run any ImageMagick command from the Terminal / Command line.
Now when I try to use the ImageMagick classes in PHP, I get an error Class 'Imagick' not found in .... I guess this is because the ImageMagick module is not loaded.
Could anyone help me to get this thing working in PHP? Thanks!
Additional info:
Mac OS X Version: 10.8: Mountain Lion
PHP Version: 5.3.13
I just did this after a lot of experimenting. For now, this seems to be the way to do it for php 5.3:
brew tap josegonzalez/php
brew tap homebrew/dupes
brew install php53-imagick
No idea who Jose Gonzalez is but apparently we are in his debt....
php72-imagick is now deprecated as imagick is part of php binary itself. Use pecl to install imagick e.g.:
brew install php
brew install imagemagick
brew install pkg-config
pecl install imagick
Your ImageMagick installation is not enough. You also need the Imagick package (possibly called php72-imagick or similar for home brew).
Imagick doesn't do the work itself, it is a native PHP extension for creating and modifying images using the ImageMagick API.
Try to search for the exact name of the package via brew search imagick.
I'm using Yosemite. For me, the solution is a combination of the answer and comment already listed here.
brew install imagemagick
brew install php55-imagick
Edit /etc/php.ini to include imagick
extension=/usr/local/Cellar/php55-imagick/{version of php55-imagick}/imagick.so
Example:
extension = /usr/local/Cellar/php55-imagick/3.1.2_1/imagick.so
I had the same issue. These are the steps that worked for me if you are using php 5.6
brew install php56-imagick
brew install imagemagick
find /usr/local/Cellar -name "imagick.so"
copy the path from the output of this command into your php.ini file
e.g. extension=/usr/local/Cellar/php56-imagick/3.3.0_2/imagick.so
save your file. Now to double check that the imagemagick class exists type
php -r "print(class_exists('imagick'));"
Brew symlinking wasn't working for me so I had to put the full pathname into the php.ini file to get it to work.
Hope this helps
this one worked for me:
brew install imagemagick # If it's not already installed
mkdir /usr/local/lib/php/pecl # On my system this dir didn't exist and this caused pecl install to fail
pecl install imagick
here
Try:
brew install homebrew/php/php53-imagick
I've looking for correct way to install imagick on Mojavie and found solution that fully worked.
brew install imagemagick#6
brew install php#7.1
Install headers (Xcode-select --install)
Download imagick source code from: https://pecl.php.net/package/imagick
Open terminal and enter unzipped folder imagick-3.4.3/imagick-3.4.3 (in my case)
Run command phpize
./configure
make
And now if error occurs like MagicWand not found, edit file Makefile and look for CPPFLAGS = -I/usr/local/opt/imagemagick#6/include/. Inspect if in include folder there is no other folder. In my case it should be like this:
CPPFLAGS = -I/usr/local/opt/imagemagick#6/include/ImageMagick-6
save and return to terminal and type make (after finished)
sudo make install
imagick.so is located in imagick-3.4.3/imagick-3.4.3/modules
Ok after 1 hour at this I have figured it out. The mac is not giving the pecl script permissions to make a PHP directory. To resolve do as follows.
brew install imagemagick
Sudo pecl install imagick .
php --ini | grep "Loaded Configuration File"
Add extension=imagick.so under extensions.
The install will be complete. Then, to test run:
php -r "print(class_exists('imagick'));"
From: php error: Class 'Imagick' not found
Did you add extension=imagick.so to your php.ini (or /etc/php.d/imagick.ini) file?
I had the same error having already installed imagemagick and php71-imagick.
brew upgrade imagemagick - did the trick for me.
You may need sudo:
sudo brew upgrade imagemagick
You may need to restart apache / php-fpm / <other webserver>.
I cannot add comments because of reputation, but to add to this anwser:
answered Apr 12 at 16:52
Grzegorz Miśkiewicz
I was getting a missing php.h file, so as per Installing xdebug on MacOs Mojave - 'php.h' file not found I installed the necessary file via the below command:
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
Related
sorry if there is a duplicate question for this but I'm trying to set this up for hours now and it just doesn't work.
I have a Debian 11 server with "KeyHelp" installed on it (little brother of plesk). It comes with PHP 7.4 but provides a simple Dashboard where you can install other PHP versions. I installed PHP 8.1 and tried to install the mongodb extension via PECL.
After "pecl install mongodb" I added "extension=mongodb.so" and after that didn't show up the extension on the phpinfo page, I double checked if the extension is really in the extension folder of php, where it was.
Turns out that I installed the extension for PHP 7.4 and not for PHP 8.1. Finally I tried to force PECL to install it for PHP 8.1 but it says "phpize8.1 command not found". I found no way to install phpize8.1, can somebody help me out with that?
Thanks in advance!
I am using Ubuntu 20.04
I have PHP 8.1 version. You have to install modules of PHP
sudo apt install php8.1-mongodb
List the modules
php -m
It's not exactly Debian. I hope it helps you.
If you run command:
sudo apt install php-dev
System will install automatically the correct version of php{x}-dev for your distribution, and all it's dependencies, included PECL.
another way is try to run:
/usr/bin/phpize
If this command works, you need to add phpize to your PATH:
PATH=$PATH\:/usr/bin; export PATH
In this way phpize will work in future.
Can anyone help me install php-redis in MAC OSX .
brew install php-redis
not working.
pecl install php-redis
also not working getting -
invalid package name/package file "php-redis".
Homebrew Error:
homebrew_error
git clone https://www.github.com/phpredis/phpredis.git
cd phpredis
phpize && ./configure && make && sudo make install
Add extension=redis.so in your php.ini
brew services restart php#7.2
make test
You can check working or not
php -r "if (new Redis() == true){ echo \"\r\n OK \r\n\"; }"
As of 2019, with homebrew php7.2 and up, pecl is now installed by default alongside the php binaries.
To see this for yourself type which pecl.
Steps to install
Check your version of redis, then find a suitable version of the extension here.
If unfamiliar with pecl, type pecl to see the options.
Issue pecl install redis-5.0.2. (or your version). Enter no to each question asked if you're not sure.
If that succeeds check the new file it created at: /usr/local/lib/php/pecl/20180731/redis.so
The install will have added extension="redis.so" to top of your php ini.
Check that by opening the file /usr/local/etc/php/7.3/php.ini.
(assuming you're on 7.3 there)
brew services restart php.
php -i | grep Redis
Redis Support => enabled
Redis Version => 5.0.2
This is what I just did in September 2019 and it works for me.
If what mwal wrote above doesn't work (please try his/her answer first),
first, try to uninstall first (if you have it but broken):
sudo pecl uninstall redis
and after that run:
sudo pecl install redis
After that, ini the php.ini, use full path for the extension.
Mine was /usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so (assuming you are using php#7.3)
so at the top of my php.ini file is like this:
extension="/usr/local/Cellar/php#7.3/7.3.21/pecl/20180731/redis.so"
Here are steps to use pickle, for PHP >= 7.3 (tested with 8.1):
brew install pickle
pickle install redis
Find your php.ini location via php -i|grep php.ini
Edit the php.ini, insert extension=redis. Preferable at Dynamic Extensions section.
No restart of Apache httpd service is required. You may test your PHP code with Redis
Bonus
If you use VS Code, to enable intellisense / auto complete, at Preference -> paste intelephense.stubs at Search setting box -> Add Item -> select redis.
If you got the following error,
Please make sure the PHP Redis extension is installed and enabled
despite doing everything in the verified answer above, try valet restart . It worked for me
I have tried all these solutions but didn't work for me for a while so I tried this link https://developer.redis.com/develop/php/ from the original docs and it works as charm
If someone gets an error during sudo pecl install redis
Warning: mkdir(): File exists in System.php on line 294
PHP Warning: mkdir(): File exists in /opt/homebrew/Cellar/-----/pear/System.php on line 294
that means you need to create the broken directory manually.
Try to create the directory...
pecl config-get ext_dir | pbcopy
mkdir -p {paste clipboard value}
# in my case, it was
mkdir -p /opt/homebrew/lib/php/pecl/20200930
Now try to install any pecl extensions.
sudo pecl install redis
After installing any extension, restart php
brew services restart php
Happy coding :)
My operating system is:Mac OSX 10.11
I'm trying to install Phabricator on my Mac, when I execute the command of
phabricator cpopt$ ./bin/phd start
I got an error:
"ERROR: The PHP extension 'pcntl' is not installed. You must install it to run daemons on this machine."
I've search this problem on google and I got lots of solutions,but they all don't work to me,I'm almost in despair.
How can I achieve that?
Do you have brew installed (read here to install http://brew.sh/)?
Try:
brew install php
or if you need to install PHP 5.6 with brew you could do this:
brew install php#5.6
Then to include it in your PATH (if it is not automatically added), it may be necessary to run the commands in the CLI you may need to update your path, e.g. (this is the case if you were to brew install php#7.1 but was not the case when I just tested with brew install php - if you are using bash instead of zsh, change .zshrc to .bashrc.
echo 'export PATH="/usr/local/opt/php#7.1/bin:$PATH"' >> ~/.zshrc
echo 'export PATH="/usr/local/opt/php#7.1/sbin:$PATH"' >> ~/.zshrc
If that doesn't work, I wonder if phabricator is calling the right version of php.
Out of curiosity, what is the output you get from this? That is what phabricator is using to determine your php version.
/usr/bin/env php -v
Also... is your php.ini updated to have the pcntl extension? Run this to see your modules and look for pcntl:
php -i | grep pcntl
Double-check the php.ini that the php-cli is running:
php -i | grep php.ini
I had to do this to install the platform.sh command line tool. This was the top hit in Google so I'm adding this information. The process I followed was as below.
In Terminal:
Add yourself to the 'wheel' user group.
sudo dscl . append /Groups/wheel GroupMembership <username>
Grant group write access to /usr/local/bin
sudo chmod -R g+w /usr/local/bin
Link libpng for brew
brew link libpng
Install pcntl for php (5.6 in my case)
brew install homebrew/php/php56-pcntl
Just in case anyone else uses MAMP, I recently updated it to the latest version. Then I was getting the error
"ERROR: The PHP extension 'pcntl' is not installed. You must install it to run daemons on this machine."
I had not restarted my terminal since I updated it. After reloading the session everything worked fine.
PHP was not working for me as I was encountering this libpng issue, so I reinstalled a new version with Homebrew.
However, I'm getting a similar error with libjpeg this time:
$ php -v
dyld: Library not loaded: /usr/local/lib/libjpeg.8.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
Trace/BPT trap: 5
Any suggestions?
As proposed by #jirson-tavera in the homebrew-php repo issue, this can be fixed without overriding your brew installation:
wget -c http://www.ijg.org/files/jpegsrc.v8d.tar.gz
tar xzf jpegsrc.v8d.tar.gz
cd jpeg-8d
./configure
make
cp ./.libs/libjpeg.8.dylib /usr/local/opt/jpeg/lib
Even though the solution in the accepted answer works, it's not the right way to fix the problem. It violates brew's metadata integrity.
Problem
The issue is that Homebrew's jpeg formula has been upgraded to v9 but the existing "bottled" PHP formula is still built and linked against the previous version, v8, which is no longer exists on your system.
You have a few options to fix the issue.
1. Recompile phpxx formula from source (highly recommended)
Uninstall your php formula, and rebuild it from the source instead of using the bottled version. This way, php will use and link against the currently installed version of jpeg. Assuming that you're dealing with php71:
brew reinstall php71 --build-from-source
2. Downgrade jpeg formula the right way (preferred over recompiling it manually)
If you haven't run brew cleanup, you already got the previous jpeg version in your brew's cellar, switch to it:
brew switch jpeg 8d
If you get a jpeg does not have a version "8d" in the Cellar. error, you need to first restore it by reverting the history:
cd $(brew --prefix)/Homebrew/Library/Taps/homebrew/homebrew-core
git checkout b231469
HOMEBREW_NO_AUTO_UPDATE=1 brew install jpeg
git checkout master
brew switch jpeg 8d
You can find out the commit hash by using brew log jpeg and going through the commit messages.
The downside is that there might be other formulas that require the newer version to work properly, e.g. imagemagick. If you face such incompatibility issues, check the first solution above.
3. Downgrade jpeg by manually recompiling (not recommended)
Fetch the source, compile and overwrite brew's version. Refer to Denis' answer for details.
This is not recommended because it violates the integrity of your brew metadata. Brew thinks that it has the 8b version, however, you manually compiled 9b and overwrote the files.
4. Manually symlink the old version (seriously?)
Do not manually symlink the leftover libjpeg.8.dylib. If the file is there, you can just brew switch to it as mentioned in the second solution above.
It's just the worst hack you can do here.
Such issues will be eventually fixed.
I encountered the similar problem today. The cause of the problem was a newer version of libjpeg. And the solution that worked was building php bottle from source.
Check available version of libjpeg:
$brew info libjpeg
jpeg: stable 9b (bottled)
Image manipulation library
http://www.ijg.org
/usr/local/Cellar/jpeg/9b (20 files, 724KB) *
Poured from bottle on 2017-08-07 at 12:06:42
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/jpeg.rb
Install php from source:
brew install --build-from-source php56
Update:
If you have already installed php you have to uninstall it prior to building from source. It also applies to extensions.
I had the same problem and I solved it by downloading the libjpeg tarball manuallu from here and running:
tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
cp /usr/share/libtool/config.sub .
cp /usr/share/libtool/config.guess .
./configure --enable-shared --enable-static
make
sudo make install
sudo ranlib /usr/local/lib/libjpeg.a #Optionally
I was getting a similar problem trying to upgrade composer:
dyld: Library not loaded: /usr/local/opt/jpeg/lib/libjpeg.8.dylib
Referenced from: /usr/local/bin/php
Reason: image not found
composer: PHP Phar support is required for this formula
Error: An unsatisfied requirement failed this build.
Problem was php couldn't find libjpeg library anymore. One way to fix this is to reinstall php and libjpeg. Here's how I reinstalled them:
# find out which version of php is installed
brew list | grep php
# uninstall php
brew uninstall php70 --ignore-dependencies
# uninstall libjpeg
brew uninstall libjpeg --ignore-dependencies
# install libjpeg again
brew install libjpeg
# install php again
brew install php70
I was then able to upgrade everything again :)
brew update && brew upgrade
🍻
Following command worked for me.
brew switch libjpeg 8d
A dirty solution, that work fine for me.
ln -s /usr/local/lib/libjpeg.9.dylib /usr/local/lib/libjpeg.8.dylib
I didn't try Jirson's answer, but what worked for me was:
brew uninstall libjpeg
brew install libjpeg
I was having the same problem and the only thing that helped was to use the --build-from-source parameter:
brew install php70 --build-from-source
I had also this problem. I solved it in this way:
Uninstall jpeg/8b:
brew uninstall --ignore-dependencies libjpeg
Uninstall jpeg/9b:
brew uninstall --ignore-dependencies jpeg
Re install jpeg/9b
brew install jpeg
I am sharing this as I had the same issue when using PHP5.4. Originally, I had PHP5.6 and it was working fine. Then I downgraded to php5.4 as my app only supports PHP5.4.
Then this error came up. I noticed that I have libjpeg.9.dylib and PHP5.4 is looking for libjpeg.8.dylib.
Doing the following sorted the issue:
brew uninstall php54
brew install --build-from-source php54
As #lifecom notes, this is fixed with homebrew's php70 update, but you might still run into the problem if brew upgrade is trying to update other packages before upgrading php70.
Fix this by manually updating php70 first with brew upgrade php70 and you then should be able to run brew upgrade no problem (or, well, at least without this problem).
In some cases, especially in Catalina, the Homebrew cask for the package may exist but not be properly linked. In that case try:
brew link libjpeg
brew reinstall php --build-from-source
Homebrew php has been updated and no longer an issue with libjpeg
I need to install imagick extension for php. I have already installed Image Magick. Then I did "sudo pecl install imagick". After this I had such output in console:
Installing '/usr/include/php/ext/imagick/php_imagick.h'
Installing
'/usr/include/php/ext/imagick/php_imagick_defs.h'
Installing
'/usr/include/php/ext/imagick/php_imagick_shared.h'
Installing
'/usr/lib/php/extensions/no-debug-non-zts-20090626/imagick.so'
but as I'm using XAMPP, my extension dir( as I understand ) is /Applications/XAMPP/xamppfiles/lib/php/php-5.3.1/extensions/no-debug-non-zts-20090626. So what should I do to make this working, I tried to put .so file in extensions dir and to add extension=imagick.so record in php.ini and to restart apache, unfortunately this didn't work. Forgot to mention, I'm using osX and XAMPP
I followed #Nodashi link:
http://www.imagemagick.org/script/download.php#macosx
Here are steps you can to follow since I'm same Mac developer.
To install imagemagick:
brew install imagemagick
Successfully:
🍺 /usr/local/Cellar/imagemagick/7.0.10-0: 1,487 files, 24.3MB
To install ghostscript:
brew install ghostscript
Successfully:
🍺 /usr/local/Cellar/ghostscript/9.51_1: 671 files, 87.4MB
Find the magick:
which magick
Then:
/usr/local/bin/magick
Try to run it to test a image then you will find it works:
magick origin.jpg converted.png
So let's do it by PHP way
Create a new php file:
sudo touch magick.php
Enter the code which we will use the 'exec' function to run the magick program:
<?php
shell_exec('magick origin.jpg converted_php.png');
?>
After that we run it by:
sudo /Applications/XAMPP/xamppfiles/bin/php magick.php
Great, we can see there is a image file converted_php.png !!
Did you install ImageMagick that is required to use imagick : ImageMagick for MacOSx