Understanding why PHP does not load an extension - php

I've compiled PHP from source (5.5.7), as well as the memcached extension (2.2.0). I've installed memcached and the extension is correctly installed in /usr/local/lib/php/extensions/no-debug-non-zts-20121212 (there is the memcached.so file) and my php -i tells me that the extension directory is correct : extension_dir => /usr/local/lib/php/extensions/no-debug-non-zts-20121212
PHP runs correctly simple files, but when I load an app using memcached, the PHP error log file tells me only PHP Fatal error: Class 'Memcached' not found but I have no more details.
When I run php -m, there is no memcached module listed.
How can I find out why memcached is not loaded by PHP ?

For the record, it's not enough that there is a memcached.so file in the extension_dir of PHP. PHP also needs to extension to be explicitly loaded in the php.init file.
Solved it with the following command
echo 'extension=memcache.so' >> /usr/local/lib/php.ini

Related

Installing mongodb for php & composer error

I am currently using xampp for PHP. I have downloaded php_mongodb-1.13.0-8.1-ts-vs16-x64 in my system and also installed xampp-windows-x64-8.2.0-0-VS16 in my system. In order to configure PHP for mongoDB, I have downloaded php_mongo.dll and pasted the .dll file in the '../php/ext' directory and also added extension=php_mongo.dll in the php.ini file.
Now when I try to install composer, it shows that Composer setup cannot continue with your current settings and throws the following errors.
The PHP exe file you specified did not run correctly:
E:\Project\XAMMP\php\php.exe
The php.ini used by your command-line PHP is: E:\Project\XAMMP\php\php.ini
A setting in your php.ini could be causing the problem: Either the 'extension_dir' value is incorrect or a dll does not exist.
Program Output:
PHP Warning: PHP Startup: mongodb: Unable to initialize module
Module compiled with module API=20210902
PHP compiled with module API=20220829
These options need to match
Any help would be appreciated

PHP Warning: PHP Startup: Unable to load dynamic library '/path/to/extension/mysqli.so' [duplicate]

I run a PHP script and get this error:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/ixed.5.2.lin' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/ixed.5.2.lin: cannot open shared object file: No such file or directory in Unknown on line 0
What does that mean?
It means there is an extension=... or zend_extension=... line in one of your php configuration files (php.ini, or another close to it) that is trying to load that extension : ixed.5.2.lin
Unfortunately that file or path doesn't exist or the permissions are incorrect.
Try to search in the .ini files that are loaded by PHP (phpinfo() can indicate which ones are) - one of them should try to load that extension.
Either correct the path to the file or comment out the corresponding line.
If you're on Linux, you can find all loaded configuration files by typing this in shell:
php -r "print phpinfo();" | grep ".ini"
UPDATE:
As mentioned in comments, this can be even more accurate:
php -i | grep ini
phpStom with XAMPP
TL;DR Except from verifying that the files exist, you might need to add the drive letter to some records in your php.ini file
I suddenly started having a problem using phpStorm 7 for debugging php with xampp and xdebug. When trying to set intellij interperter to be xampps php I got a lot of the warnings like the one in the question, for example:
Unable to load dynamic library '/xampp/php/ext/php_bz2.dll'
For some reason I had to add my drive letter to the records of extension_dir and browscap in the php.ini file:
extension_dir = "\xampp\php\ext"
browscap = "\xampp\php\extras\browscap.ini"
to
extension_dir = "e:\xampp\php\ext"
browscap = "e:\xampp\php\extras\browscap.ini"
If you just want to make the error disappear, and you don't need the extension, then by all means comment the line out in php.ini. But if you actually want to fix the problem here is some additional info.
There are various causes for this based on the exact module, but there are also some general guidelines.
Open phpinfo() and look for extension_dir under the Core section. This is where your modules should be located.
For instance, /usr/lib/php/modules for Unix/Linux.
If the file does in fact exist, make sure permissions are adequate.
If the file does not exist, use the resources below to install it.
Installation on *nix (PEAR)
Installation of extensions on Windows
Loading .dll in Linux
I've encountered this warning message while I was trying to install a php-extension via the php.ini file;
until I figured out that you cannot load .dll extensions in Linux,
but you have to comment the extensions that you want to import ;extension= ... .dll and install it correctly via sudo apt-get install php-...
note: ... is the extension name you want to enable.
php -r "echo php_ini_loaded_file();"
Will show in CLI current ini loaded file, search there for Your extension, path to it is incorrect.
In my case, this message started to appear when I updated the php version to 7.4.
To solve it I had to look for the php.ini files found inside the php version folder (/etc/php/7.4/apache2/ && /etc/php/7.4/cli/) checking the lines where the extensions I could see that the extensions gd2 and intl were uncommented.
Note that you can also get this error if your PHP library doesn't have the "other" directory opening permission. In my particular case, I noticed this when using php -l to syntax check a script in my text editor. This meant that since my account was called "volomike", that account didn't have permission to run the libraries that the php command relied upon.
For instance, on Ubuntu 14.04, I had PHP5 installed automatically into the path /usr/lib/php5/20121212+lfs. However, because I was working in C++ in building some shared objects, I messed around with the directory permissions and screwed things up such that non-root accounts did not have the directory execute (directory open) permissions to view /usr/lib/php5/20121212+lfs. So, I typed the following command to rectify that problem:
sudo chmod o+x /usr/lib/php5/20121212+lfs.
Now when I do php -l example.php as a non-root user, it never gives me this "Unabled to load dynamic library" problem anymore.
I had the same problem on XAMPP for Windows when I try to install composer.
I did php -v and php throwing error :
Unable to load dynamic library '/xampp/php/ext/php_bz2.dll'
It took me a while until I realized that I need to setup my XAMPP. So I run setup_xampp.bat and php return to works like a charm.
I had this error on a number of modules when I had been running different versions of PHP side by side on my server. To sort this out, I needed to install the packages it couldn't find for that specific PHP version. So, for example, if I saw:-
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php/20160303/xml.so'
I would install the library for the PHP version specifically:-
sudo apt-get install php7.1-xml
And then restart Apache. Fixed it for me. You can check your version like this:-
php -v
I had the same problem on XAMPP for Windows10 when I try to install composer.
Unable to load dynamic library '/xampp/php/ext/php_bz2.dll'
Then follow this steps
just open your current_xampp_containing_drive:\xampp(default_xampp_folder)\php\php.ini in texteditor (like notepad++)
now just find - is the current_xampp_containing_drive:\xampp exist?
if not then find the "extension_dir" and get the drive name(c,d or your desired drive) like.
extension_dir="F:\xampp731\php\ext" (here finded_drive_name_from_the_file is F)
again replace with finded_drive_name_from_the_file:\xampp with current_xampp_containing_drive:\xampp and save.
now again start the composer installation progress, i think your problem will be solved.
What I did was;
1 - I first find out what version of PHP I am using thru the function phpinfo()
<?php
phpinfo();
?>
2 - From there you will find the location of your configuration(php.ini) file
3 - Open that file
4 - Comment out the line similar to the image below
This might be a different value but it should be related to extension.
I am no expert but this process helped me solved similar problem.
In my case I got this error because I downloaded a thread-safe version of the dll (infixed with -ts-), but my installation of php was a non-thread-safe (infixed with -nts-). Downloading the right version of the dll, exactly matching my php installation version fixed the issue.
After Windows 10 XAMPP now I installed LAMPP (XAMPP) on Ubuntu. Windows XAMPP had a lot less to configure compare to MAC (iOS) but now with Linux Ubuntu I had a few more since there are more going in Linux (a good thing).
I confused and activated mysqli.dll (and mysql.dll: erase "#" in /etc/php/7.2/cli/php.ini
I started to get the PHP Warning: PHP Startup: Unable to load dynamic library message related to dll. I commented out mysql(and i).dll in the same file but the message didn't go away up until I commented out " " in /opt/lampp/etc/php.ini.
Looks like XAMPP reads php.ini file from /etc/php/7.2/cli and makes modification in php.ini of /opt/lampp/etc. (;extension=php_pdo_mysql.dll after ";" restarted Apache and no more any message.
I encountered a similar error. The mistake I made was to use the "controller" name as "Pages" instead of "pages" in my url.
In Windows, it could be a wrong path in "System environment variables".
"Path" to the php.exe directory must be the good one.
'C:/PHP/5.2.13/ext\php_mcrypt1.dll'
I'd say there's some typo on your php.ini (the extra 1). Perhaps you're loading a different php.ini from what you expect (see the output of php.ini to make sure).
Other than that make sure that php_mcrypt.dll and PHP:
Were linked to the same VC runtime library (typically msvcrt.dll for VC6 or msvcrt90.dll for VC9) – use e.g. the dependency walker for this
Are both debug builds or both release builds
Both have ZTS enabled or ZTS disabled
For libraries that depend on further libraries (DLLs), make sure they are available (e.g. in the same directory as the extension)
PHP should give you meaning errors if any of the first three conditions above is not satisfied, but I wrote those anyway because I'm not sure for PHP 5.2.
From C:\xampp\php\php.exe I got
Unable to load dynamic library ''
C:\xampp\php\ext\php_.dll (The specified module could not be found.)
I solved by commenting out
C:\xampp\php\php.ini
;extension=
I had the same problem when I tried to use php with sql server, when I added the sqlsrv libraries ... it gave me the error, after several days of researching there, I understood that microsoft does not support x64 in this case so what I did was install laragon x86 and use the corresponding libraries. I hope it helps with something
Go to system env variable and set the php ext dir path as
C:\xampp\php\ext
basically it's finding the ext directory and then locating it's file but it's unable to find the files becuase php path is set as different.

How to fix: Unable to load dynamic library 'C:\Program Files\php\ext\php_imagick.dll' - The specified module could not be found in Unknown on line 0?

UPDATE: I realized I need to install ImageMagick on the same server that PHP is running on, in addition to using the php_imagick.dll library. I've tried a series of different combinations of versions of the ImageMagick installer and the php_imagick.dll library to no avail. How do I know which version number of each I should use?
I'm running PHP 5.6.40 (non-thread-safe) on a Windows Server 2019 machine.
My PHP website seems to be working for the most part except when I run php -m in the command line I get the warning that the php_imagick.dll module could not be found.
When I run a test PHP file that calls phpinfo(), the ImageMagick - php_imagick.dll extension is not listed anywhere.
In my php.ini file I have the full path for my extensions directory:
I also have the extension for ImageMagick (php_imagick.dll) listed in the php.ini:
ImageMagick (php_imagick.dll) is definitely in the extensions folder listed above:
Why am I receiving the warning it was unable to load that library when I run php -m from the command line?
Probably, your server uses another *.ini file to load or some permissions are incorrect.
Try to search other configuration files such as php.ini-development and uncomment the line containing your extension in each file.
Make sure your php_imagick.dll library is visible by your PHP-server.
Restart your PHP-server after any changes in configuration files.
refer to this doc, it helps me and solves. As, I am using Php 7.4
https://www.geeksforgeeks.org/how-to-install-imagick-for-php-in-windows/

PDO extension not loading in PHP

So i'm trying to use the PDO module in PHP on a Redhat based distribution (RHEL7) to interact with a database.
In my Php script i have the 'use PDO;' directive, but in the PHP log i get an error : PHP Fatal error: Uncaught Error: Class 'PDO' not found in ...
The extension is uncommented in the php.ini file (extension = pdo.so), i have tried with the relative and the absolute path. I even reinstalled the php-pdo package (yum install), but without success.
I've compared my phpinfo() with a working phpinfo(), and i am missing the PDO section.
I have checked and Apache loads the correct php.ini file
I've passed all my extensions permissions to 755 just to be sure.
I don't get any php warning at startup so i don't know where the problem seems to be.
I found the error :
First i started using php in direct command line, and set the env' variable LD_DEBUG=libs:
./php -c /path/to/php.ini /path/to/php/file.php
So with that i was able to get the debug on the dynamic loading of my modules and on the php.ini.
I saw that there was an uncommented line that was blocking the loading of the modules in the INI file, then you have to load the mysql.so module before the pdo_mysql.so and of course restart you apache server.

Trouble Enabling cURL on Ubuntu 11.10

I have installed curl:
sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
and I have updated my php.ini file to include:
extension=php_curl.dll
I check to see if curl is working with the following command:
php -i | grep curl
and I receive the following message:
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20090626+lfs/php_curl.dll' - /usr/lib/php5/20090626+lfs/php_curl.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 '/usr/lib/php5/20090626+lfs/sqlite.so' - /usr/lib/php5/20090626+lfs/sqlite.so: cannot open shared object file: No such file or directory in Unknown on line 0
Additional .ini files parsed => /etc/php5/cli/conf.d/curl.ini,
curl
I also tested curl by creating a file called testCurl.php which contains the following:
<?php
echo ‘<pre>’;
var_dump(curl_version());
echo ‘</pre>’;
?>
When I navigate to localhost/testCurl.php I get an error: HTTP Error 500
Can anyone help me to get curl working?
You put the wrong info in your php.ini
extension=php_curl.dll
On Ubuntu/Unix that is
extension=php_curl.so
.so means Shared Object, that is a dynamic library the error messages speaks of. On Windows that is .dll, you probably just mixed that.
And it appears you try to load sqlite.so which does not exists. Normally you don't need to change your php.ini file when you install libraries on Ubuntu via apt, because the package scripts take care of that thanks to the work of the package maintainers.
If you'r using Ubuntu or have more than one php.ini you may face this problem of enabling extension=php_curl.dll.
It's curious but I was facing this problem using UBUNTU. For some reason it was calling a .dll file, but linux uses .so files.
First thing to do is echo phpinfo(); in a .php file to check what php.ini is getting loaded.
Configuration File (php.ini) Path /etc/php/7.1/apache2
Loaded Configuration File /etc/php/7.1/apache2/something/php.ini
So if you change only in one file it may not have the correct effect.
In my case whas in /etc/php/7.1/apache2/php.ini and CURL was calling this way:
;extension=curl.dll
Change to
extension=curl.so
Save and restart apache:
sudo systemctl restart apache2
Support for sqlite2 is removed from php5 I think, so sqlite.so is no longer available in the current version of the package. You can manually restore it from the natty packages (this worked for me):
Download the old package from here: http://packages.ubuntu.com/natty-updates/php5-sqlite
Extracts sqlite.so
Move sqlite.so (+pdo_sqlite.so) to /usr/lib/php5/20090626+lfs/
Change file permissions to root:root
(https://lists.ubuntu.com/archives/ubuntu-server-bugs/2011-October/065547.html)

Categories