72
root@ip-10-131-9-200:/etc/php5/apache2# php -a
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/curl.so' - /usr/lib/php5/20090626+lfs/curl.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/mcrypt.so' - /usr/lib/php5/20090626+lfs/mcrypt.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/mysql.so' - /usr/lib/php5/20090626+lfs/mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/mysqli.so' - /usr/lib/php5/20090626+lfs/mysqli.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/pdo.so' - /usr/lib/php5/20090626+lfs/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/pdo_mysql.so' - /usr/lib/php5/20090626+lfs/pdo_mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
Interactive shell
hakre
  • 193,403
  • 52
  • 435
  • 836
user1391283
  • 729
  • 1
  • 6
  • 3

13 Answers13

141

Even though several other answers suggest it, installing more unnecessary software is generally not the best solution. Instead, you should fix the underlying problem. The reason these messages appear is because you are trying to load those extensions, but they are not installed. So the easy solution is simply to tell PHP to stop trying to load them:

First, find out which files are trying to load the above extensions:

$ grep -Hrv ";" /etc/php5 | grep -E "extension(\s+)?="

Example output for Ubuntu:

/etc/php5/mods-available/gd.ini:extension=gd.so
/etc/php5/mods-available/pdo_sqlite.ini:extension=pdo_sqlite.so
/etc/php5/mods-available/pdo.ini:extension=pdo.so
/etc/php5/mods-available/pdo_mysql.ini:extension=pdo_mysql.so
/etc/php5/mods-available/mysqli.ini:extension=mysqli.so
/etc/php5/mods-available/mysql.ini:extension=mysql.so
/etc/php5/mods-available/curl.ini:extension=curl.so
/etc/php5/mods-available/sqlite3.ini:extension=sqlite3.so
/etc/php5/conf.d/mcrypt.ini:extension=mcrypt.so
/etc/php5/conf.d/imagick.ini:extension=imagick.so
/etc/php5/apache2/php.ini:extension=http.so

Now just find the files that are loading the extensions that are causing the errors and comment out those lines with a ;. For some reason this happened to me with the default install of Ubuntu, so hopefully this helps someone else.

Mike
  • 23,542
  • 14
  • 76
  • 87
  • 4
    I encountered the same errors after a dist-upgrade from Debian 6.x to 7.1. I didn't know `suhosin` and `idn` modules got removed in this newer packages.. so big thx for the nice `grep` line. – Daniel W. Jul 24 '13 at 10:15
  • Thank you very much. This worked pretty fine in Ubuntu 12.04.2 LTS. I yet have a question: If I disable the extensions causing the error by placing a ; symbol at the beggining of the line, will they be re-enabled after an upgrade? – Geppettvs D'Constanzo Aug 12 '13 at 16:21
  • 1
    @GeppettvsD'Constanzo When upgrading, sometimes it will prompt you whether to overwrite the config file. If you overwrite it, it MAY overwrite these ones, but I'm not too sure. Just choose no. – Mike Aug 12 '13 at 19:52
  • 1
    I agree, if you don't need it the extension why install it? – d0001 Sep 18 '13 at 20:28
  • In my case (Ubuntu 12.04, update PHP 5.3.x -> 5.4.x) I had to remove the conf file associated to the extension in /etc/php5/cli/conf.d/ – arg Jun 11 '14 at 07:54
  • 1
    I like this kind of answers because they make you understand what's going on AKA = know-how – nulll Jul 10 '14 at 08:46
  • i like this answer too BUT, re: "but they are not installed" comment by Mike isn't always 100% true. My php.ini file had a common config: `extension_dir = "./usr/lib64/php/modules"`, but when i tried to run php at the prompt (ex: `#php my_file.php`) it would trigger this error because it points to a RELATIVE path. By changing the setting to `extension_dir = "/usr/lib64/php/modules"` (without the preceding dot) i no longer received this error, because the modules were indeed installed, and could now be found when running php from anywhere on my server. – aequalsb Nov 02 '15 at 17:35
  • This regex is not applicable on all case, for exemple in Newrelic .ini file they are spaces around equal sign: `/etc/php5/mods-available/newrelic.ini:extension = "newrelic.so"` – Jack NUMBER Jun 22 '16 at 21:50
  • is controversial, altough this answer helped a lot of people should also explain how to fix it when really we need the extension, that's my case. I need that extensión loaded and this doesn't help me :S – Sredny M Casanova Jan 30 '17 at 13:48
  • On ubuntu 16.04 I had to go to `/etc/php/7.0/cli/php.ini` to comment out those lines. – Pranay Aryal Jun 06 '17 at 14:31
47
sudo apt-get install php5-mcrypt
sudo apt-get install php5-mysql

...etc resolved it for me :)

hope it helps

Jeff
  • 13,943
  • 11
  • 55
  • 103
user1568807
  • 593
  • 4
  • 3
  • Your answer got my site working again! thank you so much, I really appreciate this. I have spend hours on this. I followed some instructions to upgrade mysql and they must have omitted this part. – pgee70 Nov 18 '13 at 09:02
13

Look /etc/php5/cli/conf.d/ and delete corresponding *.ini files. This error happens when you remove some php packages not so cleanly.

dimcha
  • 141
  • 1
  • 2
12

Seems like you upgraded PHP to newer version and old .ini files are still pointing to old location.

The solution: find out where are modules located now

ls -l /usr/lib/php5

There should be a directory similar to old 20090626. In my case it is now 20131226

The .ini files giving you an error are located at /etc/php5/cli/conf.d/

Just edit those .ini files which module gives you an error. For example, in case the error is for mcrypt module:

sudo vi /etc/php5/cli/conf.d/20-mcrypt.ini

Change the line:

extension=/usr/lib/php5/20090626/mcrypt.so

to reflect the new path for .so file. In my case the correct path should be:

extension=/usr/lib/php5/20131226/mcrypt.so

That's it! The error is gone. Ofc you'd have to do it with each module giving you an error.

ruuter
  • 2,453
  • 2
  • 30
  • 44
6

If you put the ; symbol, this action inactive the extension.

I had the same problem and did the following:

  1. Uninstall php with purge parameter:

    sudo apt-get --purge remove php5-common
    
  2. And install again:

    sudo apt-get install php5 php5-mysql
    
Jose Ayram
  • 198
  • 1
  • 14
2

My problem was solved by the following command

sudo apt-get install php5-mcrypt

I have

  • PHP 5.3.10-1ubuntu3.4 with Suhosin-Patch (cli)
  • Ubuntu Desktop 12.04
  • Mysql 5.5
Jeff
  • 13,943
  • 11
  • 55
  • 103
GP Das
  • 59
  • 2
2

I found this solution by blog.tordeu.com, and it's

sudo aptitude purge php5-suhosin

I'm not sure, but it seems that the suhosin is no longer needed, it worked for my, my PHP version:

PHP 5.4.34-1+deb.sury.org~lucid+1 (cli) (built: Oct 17 2014 15:26:51)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
Edwin Yip
  • 4,089
  • 4
  • 40
  • 86
2

If you are using 5.6 php,

sudo apt-get install php5.6-curl

Amjith
  • 445
  • 5
  • 15
0

Somehow the gmp.so file seems to have been deleted from my system. This is what fixed it for me:

sudo apt-get install --reinstall php5-gmp

0

Well for Ubuntu 14.04 I was getting that error just for mcrypt:

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

If you have a closer look at the error, php is looking for mcrypt.ini and not for mcrypt.so at that location. I just copy mcrypt.so to mcrypt.ini and that's it, the warning is gone and the extension now is properly installed. It might look a bit dirty but it worked!

0

I had enabled the extension_dir in php.ini by uncommenting,

  extension_dir = "ext"
  extension=phpchartdir550.dll

and copying phpchartdir550 dll to the extension_dir (/usr/lib/php5/20121212), resulted in the same error.

  PHP Warning:  PHP Startup: Unable to load dynamic library 'ext/phpchartdir550.dll' - ext/phpchartdir550.dll: cannot open shared object file: No such file or directory in Unknown on line 0
  PHP Warning:  PHP Startup: Unable to load dynamic library 'ext/pdo.so' - ext/pdo.so: cannot open shared object file: No such file or directory in Unknown on line 0
  PHP Warning:  PHP Startup: Unable to load dynamic library 'ext/gd.so' - ext/gd.so: cannot open shared object file: No such file or directory in Unknown on line 0

As @Mike pointed out, it is not necessary to install all the stuff when they are not actually required in the application.

The easier way is to provide the full path to the extensions to be loaded after copying the libraries to the correct location.

Copy phpchartdir550.dll to /usr/lib/php5/20121212, which is the extension_dir in my Ubuntu 14.04 (this can be seen using phpinfo()) and then provide full path to the library in php.ini,

;   extension=/path/to/extension/msql.so
extension=/usr/lib/php5/20121212/phpchartdir550.dll

restart apache: sudo service apache2 restart

even though other .so's are present in the same directory, only the required ones can be selectively loaded.

nbs
  • 311
  • 1
  • 12
0

I had a similar problem, which led me here:

$ phpunit --version
PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php5/20131226/profiler.so' - /usr/lib/php5/20131226/profiler.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHPUnit 5.7.17 by Sebastian Bergmann and contributors.

Unlike the above, installing the software did not resolve my problem because I already had it.

$ sudo apt-get install php5-uprofiler
Reading package lists... Done
Building dependency tree       
Reading state information... Done
php5-uprofiler is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 52 not upgraded.

I found my solution via : Debian Bug report logs

$ sudo vim /etc/php5/mods-available/uprofiler.ini

I edited the ini file, changing extension=profiler.so to extension=uprofiler.so .... the result, happily:

$ phpunit --version
PHPUnit 5.7.17 by Sebastian Bergmann and contributors.

i.e. no more warning.

owenmck
  • 388
  • 3
  • 9
0

(For Ubuntu users)

I had the same problem, but none of the answers above solved that. Here is how I solved the problem.

Open your php.ini file (mine was in /etc/php/7.3/cli/php.ini).

You may have something like this:

extension=pdo_mysql

Or maybe:

extension=/here/is/the/path/to/your/file/pdo_mysql.so

Add the following line before extension=pdo_mysql

extension=pdo

So, you will have:

extension=pdo
extension=pdo_mysql

It seems that the problem is (at least in my case) that we need to load pdo extension first to load the pdo_mysql extension.

Hope that helps!