How to install iconv extension without recompiling whole PHP
When we install PHP on our system, often we install extensions that are common like curl, mbstring etc. However, there are times when we are asked to install and enable one or more specific extensions when we try to install a specific software. Installing an extension over an already installed PHP often raise some obvious questions like:
- Will there be any impact on my already running software / applications if I recompile?
- Will there be any chance of my installed PHP getting messed up due to recompilation?
Well, an experienced server guy or a developer might have answers for the above questions? But a beginner will have a certain dilemma. Isn’t there a way to do this in a safer way? Yes! There is. You can install an extension on already installed PHP without recompiling the entire PHP!!
In the following example I will install iconv PHP extension on my alredy existing php 5.6.22 installation.
Step 1: Create a temporary folder somewhere on your hard drive.
$ sudo mkdir php-extention-installer-test $ cd php-extention-installer-test
Now check the PHP version you have by typing
$ php -v
For me the version is 5.6.22. So I will now download this version from museum.php.net and extract the compressed file.
$ sudo wget http://museum.php.net/php5/php-5.6.22.tar.bz2 $ tar -jxf php-5.6.22.tar.bz2
Once the files are extracted move into the following folder:
$ php-5.6.22/ext/iconv and prepare php extension to compile it. $ phpize
Then run the following commands one by one:
$ aclocal $ ./configure $ make $ make test $ make install
Now add this extension to php.ini file:
echo "extension=iconv.so" >> /home/emfluence/.phpbrew/php/php-5.6.22/etc/php.ini
Please use the actual location of your active php.ini file.
php -i | grep -i "iconv support"
If everything went right, the above command will output the following:
iconv support => enabled