Installing PHP extensions to the correct PHP version
Solution 1
You can build ImageMagick extension for latest version of PHP using below steps.
- Download source form https://pecl.php.net/package/imagick/download
- Unpack archive and go to unpacked folder.
#cd imagemagick-x.x #path_to_php_home_dir/bin/phpize #./configure --with-imagick=/opt/imagemagick #make #make install
imagick.so will be build in module directory, now copy it to your extension path of php-5.6.7 instance.
MEMCACHE
#cd /usr/src/ #wget http://pecl.php.net/get/memcache-2.2.4.tgz #tar -zxvf memcached-2.2.4.tgz #cd memcached-2.2.4 #path_to_php_home_dir/bin/phpize && ./configure --enable-memcache && make
Now copy memcached extension from module directory to php extension directory
-- UPDATE
You need to specify correct extension_dir path in php.ini which is located at php_install_dir/lib/php.ini.
If php.ini not present then you have to copy php.ini.production from php_source_dir to php_install_dir/lib/ with name php.ini
php.ini parameter for extension dir
extension_dir=/php_install_dir/lib/php/extensions/no-debug-non-zts-20121212/
Also it can be possible that you have php.ini exists in your web application directory (/var/www/app_dir). In that case you have to make changes in both php.ini.
Solution 2
how about using CentOS Software collections? Those are specifically designed for parallel version installs. I would also suggest getting familiar with the process of building those so that you can create your own if needed. Use Copr for build infrastructure as needed.
Related videos on Youtube
PaparazzoKid
Updated on September 18, 2022Comments
-
PaparazzoKid over 1 year
We have two versions of PHP on our Linux CentOS6 machine, 5.3.3 and 5.6.7, and wanted to install PHP extensions, memcache and imagick, to 5.6.7.
Logged in as root, using yum, we installed both of these, but realised they were only usable in 5.3.3 and not in the latest version. This are the commands we used:
$ yum install ImageMagick ImageMagick-devel $ pecl install imagick $ echo "extension=imagick.so" > /etc/php.d/imagick.ini
We tried copying imagick.so and memcache.so from the old extension directory to 5.6.7's extension directory, but without any luck.
How do we install these extensions to our latest version, PHP 5.6.7? Or is there a way to resolve this without reinstalling anything?
Edit:
To install PHP 5.6.7, I used the steps given in this gist:
https://gist.github.com/Stayallive/dbb91ffa6f0fc6ca6ac3
-
Joe about 9 yearsThe standard available RPMs from Centos will only be PHP 5.3.3. How did you get the 5.6.7 installed as well? Either you compiled from source yourself (in which case, to install the modules you would have to recompile with options for those modules enabled), or you got RPMs from a nonstandard repo which "should" also provide the RPMs for that new version.
-
PaparazzoKid about 9 years@Joe - I have just update my question with the link to the gist I used for installing 5.6.7 - I compiled it myself.
-
Joe about 9 yearsIf that's the case, then Vaibhav Panmand's answer should work for you. The important piece being that you use the correct path to the phpize from 5.6.7, and then move the .so files into the 5.6.7 extensiondir
-
PaparazzoKid about 9 yearsThanks for your time, Joe. I followed the steps given by Vaibhav and all seemed to go perfectly fine until I checked phpinfo() and found the extension was still not there. I copied the .so file, checked php.ini for the extension, restarted httpd, but still nothing.
-
Joe about 9 yearsyour phpinfo() clearly shows it is the php 5.6.7? What folder does that phpinfo() state is the extensiondir? Are the exact (case-sensitive) file names in that dir?
-
PaparazzoKid about 9 yearsYes, it shows 5.6.7 and shows php.ini changes too. The installation said the extension was in
/usr/lib64/php/modules/
, so rancp /usr/lib64/php/modules/imagick.so /php/php-5.6.7/lib/php/extensions/no-debug-non-zts-20131226/imagick.so
which is where phpinfo says my extension directory is underextension_dir
variable. I also tried copying it from the modules directorycp /root/imagick-3.1.1/modules/imagick.so /php/php-5.6.7/lib/php/extensions/no-debug-non-zts-20131226/imagick.so
. Before I did this, the 5.6.7 extension directory was empty, and so checked there was a file there after copy -
PaparazzoKid about 9 yearsI meant the new extension directory didn't have imagick.so before copying the extension and did after. It wasn't empty.
-
Joe about 9 yearsif you have
extension=imagick.so
in php.ini and the file is in the right place, it should load it. If phpinfo() still doesn't show it, then there should be a error_log somewhere showing why. Either the apache error_log location, or a error_log file in the location the phpinfo() was run are most likely places -
PaparazzoKid about 9 yearsAnother cause of concern, is for one of our hosted websites in Plesk, I chose that it used 5.6.7 - this probably means that pre-existing websites and new ones I add will default at 5.3.3. Now, logging in as root - which is how I installed extensions - I run
php -v
and it tells me 5.3.3 is being used. Is 5.3.3 being the default version causing this problem I'm seeing? -
Joe about 9 yearsIt is highly likely that having both installed is leading to the confusion. That's why I asked to check the files and everything are all in the 5.6.7 sections
-
Joe about 9 yearsHave you followed this document for Plesk with multiple versions of PHP: download1.parallels.com/Plesk/Doc/en-US/online/… Once this is setup properly, you should be able to change each accounts version between the two as appropriate
-
-
PaparazzoKid about 9 yearsThank you for taking the time to respond. I followed the steps you gave for the first extension, imagick. Everything installed perfectly ok, I copied the .so file to the php5.6.7's extension directory using the modules path that was given at the end of the install and restarted httpd. Phpinfo() doesn't show this extension and fails in an application with 'Fatal error: Class 'Imagick' not found in /var/www/.....'. I have added the extension to php.ini. Any ideas?
-
Vaibhav Panmand about 9 yearsYou need to specify correct extension_dir path in php.ini which is located at php_install_dir/lib/php.ini. ----->>> extension_dir=/php_install_dir/lib/php/extensions/no-debug-non-zts-20121212/