I am using ubuntu 11.04 and when I am opening terminal and typing php -a it is showing some error like this

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626/gd.so' - /usr/lib/php5/20090626/gd.so: cannot open shared object file: No such file or directory in Unknown on line 0

I think there is some problem with GD library.Is there any option to solve it?

share|improve this question
up vote 31 down vote accepted

Yeah. Just try:

sudo apt-get install php5-gd

You probably will have to remove the offending line in your php.ini, either in php.ini or in /etc/php5/conf.d/gd.ini maybe.

share|improve this answer
1  
thanks it worked for me. – NewUser May 27 '11 at 6:43
3  
Alternate solution, if you don't need the php5-gd package, is to purge it: sudo apt-get purge php5-gd – bonsaiviking May 9 '12 at 16:26
    
I had to purge and then reinstall - that worked. – Joe Corneli Jun 20 '13 at 0:11
    
purging and reinstalling worked for me too. – Villi Magg Jul 1 '13 at 2:19
    
Tnx, it worked. – deanpodgornik Apr 8 '14 at 9:53

Personally I think it makes a lot more sense to use the wrapper library called Imagine (available on packagist https://packagist.org/packages/imagine/imagine or you can download it directly from Github https://github.com/avalanche123/Imagine/tree/develop), other than calling the GD API directly. It's much more user friendly, easier to learn, and a huge time saver for me.

Because it's a wrapper library, you'll need to install one of the following libraries to use it,

  • GD2
  • Imagick
  • Gmagick

I use Imagick, to install it run sudo apt-get install php5-imagick

I wrote a guide to setup many useful libraries on Ubuntu for PHP development, you might find it helpful http://www.shenghua.co.uk/ubuntu-zero-to-hero-guide-best-for-php-developers/.

share|improve this answer

For me the solution was:

locate --regex /mcrypt[.]so\$ /gd[.]so\$ /suhosin[.]so\$ /pdo_mysql.so\$ /pdo[.]so /mysqli[.]so\$ '/php5/.*/mysql[.]so$'

Which returned the location of all the libraries that my php5 install was having trouble finding:

/usr/lib/php5/20090626+lfs/gd.so
/usr/lib/php5/20090626+lfs/mcrypt.so
/usr/lib/php5/20090626+lfs/mysql.so
/usr/lib/php5/20090626+lfs/mysqli.so
/usr/lib/php5/20090626+lfs/pdo.so
/usr/lib/php5/20090626+lfs/pdo_mysql.so

I was a little worried that these look they might be old versions, but I used their paths anyway. Stefgosselin identified the location of the ini files, /etc/php5/conf.d/. I modified them all. The command below will modify all of the *.ini files there, so make sure all of yours really need modifying. Obviously you need to use the target path you discovered with the locate command in place of mine, /usr/lib/php5/20090626+lfs/:

 sudo sed -ri -e "s|^(extension=)(\w{2,10}[.]so)$|\1/usr/lib/php5/20090626+lfs/\2|g" /etc/php5/conf.d/*.ini

Before finding this solution I tried several apt-get purge and apt-get reinstall commands without luck. I'm not sure, but my problem may have originated with installation of zend from source or phpmyadmin with aptitude. It never caused any php errors, just the annoying warning you mentioned. Finally php5 can launch without errors:

php5 --version

gives ...

PHP 5.3.5-1ubuntu7.2 with Suhosin-Patch (cli) (built: May  2 2011 23:18:30)  Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH
share|improve this answer
    
Although your solution does do the trick, you gave yourself a lot of trouble. Simply removing the offending line in gd.ini and reinstalling the latest gd binary would of also done the trick. But hey, I +1'ed your solution for the sed usage! Happy coding buddy, thanks for contributing. – stefgosselin Aug 25 '11 at 5:05
    
@stefgosselin, I may have tried that before the more complicated solution, but will try again to make sure. Thanks. Thanks for upvote too. – hobs Aug 29 '11 at 5:55
1  
On little addition, if you're using php5-fpm you'll need to restart it, e.g. sudo service php5-fpm restart – ur5us Dec 19 '13 at 3:13
    
Ok this solution does what it says but not necessarily solves the problem. I had the same scenario as yours but the command you provide effectively changes the affected files indisde of /etc/php5/conf.d but it made some other things stop working. Maybe I missed out something? – Geppettvs D'Constanzo Apr 25 '14 at 17:48

Probably something like

sudo apt-get install php-gd

should do it, if not try

apt-cache search php | grep gd
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.