Install php-gd on Ubuntu without recompiling php
For some reason one of my client's website stopped showing captcha codes for the mad4joomla component, the server is running nginx with php-fpm instead of Apache.
Looking at the error.log, I got
Time to check the server, that function is supposed to be part of the GD library.
First, I checked if GD was loaded:
# php5 -m | grep -i gd
ok, so GD is there… now on to the function.
# php -r "var_dump( function_exists(‘imageantialias'));"
hmm…
So, on I went to google, trying to find out how I can get imageantialias() to work (again)… to my surprise I actually stumbled upon a post talking about the exact same issue, while using the same server setup -- Ubuntu with ISP Config. The solution presented was to recompile php, which I was reluctant to do.
After some more searching I came across this amazing little page (http://nossie.addicts.nl/php5-gd.html) which I am going to post (slightly modified) right here, mainly because it looks like that page could be gone tomorrow…
Like many other people out there, I ran into the problem that the version of php-gd shipped with Ubuntu (and Debian) is different from the version used by many other distributions.
The version Ubuntu uses misses some functions like imagerotate and imageantialias, which are needed by an increasing number of software projects.
One solution to this problem is recompiling PHP with the bundled version of GD.
It is not particularly hard to do, but there are a reasons not to do it, one of them being that it is not neccesary.
The following steps solved the problem for me.
Install what is needed to do this:
# sudo apt-get install php5-cli php5-gd rpm mc
Check what version of php you are running (php5 -v). In my case it was 5.3.2-1ubuntu4.7
Go to rpmfind.net and search for php-gd-bundled
Download the version that matches your PHP version and architecture, php-gd-bundled-5.3.2-1mdv2010.1.x86_64.rpm in my case.
If you have installed mc (midnight commander) and rpm, you can use mc to open the downloaded .rpm file (start mc, goto the .rpm file and hit enter)
Inside the .rpm file you will see CONTENT.cpio, navigate to that and hit enter. Goto usr/lib64/php/extensions, there you will find gd-bundled.so.
The original php5-gd is installed at /usr/lib/php5/20090626/gd.so (for my installation), backup the original gd.so, and copy the gd-bundled.so to that location and rename to gd.so (you can copy files with F5 in mc).
The new gd.so expects to find libjpeg.so.8, this was not present on my system, but that can be sovled by creating a symlink from the installed libjpeg.so
On my system I found /usr/lib/libjpeg.so.64.0.0
Create the symlink with:
# ln -s /usr/lib/libjpeg.so.62.0.0 /usr/lib/libjpeg.so.8
This is it, restart apache and you should be running with the bundled version of gd.
# php -r "var_dump(function_exists(‘imageantialias'));"
Should return bool(true) this time.
Now, if there is an update of the php5-gd package, your modified version gets overwritten. To prevent this from happening, you can hold the php5-gd package so it will not be updated.
# aptitude hold php5-gd
I hope this will help you as much as it did me!
Enjoy
51624
this is awesome; thank you so much!!! Worked like a charm.
Comments like yours keep me posting stuff like this!
Thank you, too
Lets see, install an rpm (redhat package manager) archive, on a ubuntu (dpkg based) system, from a random archive with no security signing, no md5 hashing or other basic safety and sanity checks.
How about… No.
I’ll surf on till I find a more sensible and safe solution.
You don’t even mention that installing unsigned rpm’s or deb’s could potentially compromise your system, because unsigned means no accountability for the contents therein, and they could contain hidden shellcode, etc etc.
How about… reading the post.
Nowhere does it say to install a rpm.
A single file is needed to make this work, and you need to extract it from the rpm.
The rpm in question is from an official Mandriva release.
However, if you find a better solution, please leave another comment.
Thanks
I have a compiled version of PHP running with GD enables but freetype was missing at the time of compilation. Is there any way to add freetype support without recompiling PHP. I tried with using phpize, and comiled gd in ext folder, while loading the gd.so module in php.ini, it says gd already loaded. Any thoughts??
I think you will have to recompile php, the solution you tried would only work, if you had not included GD in the compile.
Thanks for reposting, I too found that op but as you’re on wordpress, I can converse:)
Q: What if the version of php is newer than the newest gd rpm? For example, my php version is 5.5.9-1ubuntu4.6 and the most recent gd-php-bundled I can find dates to 5.4.
Assuming you use 14.04, make sure you have this ppa in your sources.list:
deb http://ppa.launchpad.net/ondrej/php5/ubuntu trusty main
deb-src http://ppa.launchpad.net/ondrej/php5/ubuntu trusty main
once you do, you should be able to just apt-get install php-gd
You can also download the package at: https://launchpad.net/ubuntu/utopic/amd64/php5-gd/5.5.9+dfsg-1ubuntu4
Hi. Thanks for a great post. Just like @dakisan above, I have PHP 5.5.9-1ubuntu4.9 installed.
I added the Deb’s you mentioned, ran apt-get update and received the following error:
W: GPG error: http://ppa.launchpad.net trusty Release: The following signatures couldn’t be verified because the public key is not available: NO_PUBKEY
Would you have any ideas on how to solve this?
Thank you.
I was able to go ahead and install GD by performing the following after adding the DEB’s above.
Missing key: 4F4EA0AAE5267A6C
~$ sudo apt-key adv –keyserver keyserver.ubuntu.com –recv-keys 4F4EA0AAE5267A6C
~$ sudo apt-get update
~$ apt-get install php5-gd
GD installed fine, but still no imageAntialias() unfortunately.
Hmm…
did you do “ln -s /usr/lib/libjpeg.so.62.0.0 /usr/lib/libjpeg.so.8”, changing “/usr/lib/libjpeg.so.62.0.0” to whatever version you have installed?
What does it say when you do: php -r “var_dump(function_exists(‘imageantialias’));”
I also try update php5-gd from that repo. If I don’t change symlink from libjpeg8 to libjpeg62 – php -r “var_dump(function_exists(‘imageantialias’));” show false. But if i change simlink – apache can’t start with error in GD library (something about missed symbol 8). Do you have other ideas how to make antialiasing working on Ubuntu 14.04 ?
I would say you need to get libjpeg8.
http://packages.ubuntu.com/search?keywords=libjpeg8
It’s installed and correctly linked.
aptitude search libjpeg | grep ‘i ‘
i A libjpeg-turbo8 – IJG JPEG compliant runtime library.
i libjpeg62 – Independent JPEG Group’s JPEG runtime libr
i A libjpeg8 – Independent JPEG Group’s JPEG runtime libr
aptitude show libjpeg8
Package: libjpeg8
State: installed
Automatically installed: yes
Multi-Arch: same
Version: 8c-2ubuntu8
Priority: optional
Section: libs
Maintainer: Ubuntu Developers
Architecture: amd64
Uncompressed Size: 26.6 k
Depends: libjpeg-turbo8 (>= 1.1.90+svn722-1ubuntu6)
Breaks: libjpeg8 (!= 8c-2ubuntu8)
Replaces: libjpeg8 (< 8c-2ubuntu8)
Description: Independent JPEG Group's JPEG runtime library (dependency package)
libjpeg8 dependency package, depending on libjpeg-turbo8.
aptitude show php5-gd
Package: php5-gd
State: installed
Automatically installed: no
Version: 5.5.26+dfsg-1+deb.sury.org~trusty+1
Priority: optional
Section: php
Maintainer: Debian PHP Maintainers
Architecture: amd64
Uncompressed Size: 163 k
Depends: libc6 (>= 2.4), libgd3 (>= 2.1.0), libxpm4, phpapi-20121212,
php5-common (= 5.5.26+dfsg-1+deb.sury.org~trusty+1), ucf
PreDepends: dpkg (>= 1.15.7.2~)
Conflicts: php5-gd
Description: GD module for php5
This package provides a module for handling graphics directly from PHP scripts.
It supports the PNG, JPEG, XPM formats as well as Freetype/ttf fonts.
PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open
source general-purpose scripting language that is especially suited for web
development and can be embedded into HTML.
ls /usr/lib/x86_64-linux-gnu/ -l | grep libjpeg
lrwxrwxrwx 1 root root 17 Dec 11 2013 libjpeg.so.62 -> libjpeg.so.62.0.0
-rw-r–r– 1 root root 150184 Dec 11 2013 libjpeg.so.62.0.0
lrwxrwxrwx 1 root root 16 Jul 14 22:30 libjpeg.so.8 -> libjpeg.so.8.0.2
-rw-r–r– 1 root root 281288 Dec 19 2013 libjpeg.so.8.0.2
BUT, php -r “var_dump(function_exists(‘imageamtialias’));”
bool(false)
Hi,
if you have gone to rpm-find and downloaded a matching rpm, then manually copied and renamed gd-bundled.so to gd.so as described, then your issue seems to be unique and probably needs quite a lot of trial and error troubleshooting.
This comment section is not the right place for troubleshooting individual issues though. Please use a forum or help site for that. Once you got it figured out, it would be great to hear the solution though, it may help others having the same issue as you.
Good Luck!
Hi,
No, I don’t use rpm-find or something else I just add repo you advice and inform, that it’s not sovle the problem.
Sorry for offtopic
Please read the original post, you missed an important step in the instruction and that is why imageantialias isn’t working for you.
You HAVE TO go to rpm-find, download a rpm package and copy a certain file to make this work. That is why I asked, if you did that.
Why does the rpmfind repo stop with PHP 5.3? I need something newer, so it’s looking like compiling PHP is the only solution.
Hi, when I search it goes up to 5.4 but try searching for “php-gd” instead, then download one that matches your php version. Haven’t tested it, but it should work.
{ Download the version that matches your PHP version and architecture, php-gd-bundled-5.3.2-1mdv2010.1.x86_64.rpm in my case. }
Problem is how to do that on a deb ubuntu system ?? i get..
550 Failed to change directory
please someone list the ALL the steps and commands for us less experience people to get this problem sorted once and for all.
thank you in advance.
All steps are provide. As stated in the line above the one you quoted: “Go to rpmfind.net and search for php-gd-bundled”.
Meaning, you open your web browser, visit http://www.rpmfind.net, enter “php-gd-bundled” in the search field, click search, and download the version that matches your installed php version… then continue following the steps.
If you are doing this on a server that does not have a GUI, simply use another computer to find the matching RPM and either download the RPM and upload to the server, or write down the download URL and on the server do: wget [URL-TO-DOWNLOAD]
In my example that would be
wget ftp://195.220.108.108/linux/Mandriva/official/2010.1/x86_64/media/contrib/release/php-gd-bundled-5.3.2-1mdv2010.1.x86_64.rpm
Only use my example, if you are using php version 5.3.2, else find the correct rpm on rpmfind.com
Good Luck!
p.s. If the web service running on the server is not mission critical – meaning it’s ok to be offline for an hour or so – then it would be much easier to just recompile php.