Report this

What is the reason for this report?

Unable to install php extension

Posted on December 11, 2018

Hello. I’m unable to install imap php extension. The problem probably is, that I installed php version from php-archive github) and now I have php links broken?

Well, I followed every step from here: http://blog.programster.org/ubuntu16-04-compile-php-7-2-with-pthreads to install php with pthreads. It works perfectly, but when I want to install imap extension, I probably use other version of the extension?

Is I understood, installing extension should be easy as: $ sudo apt-get install php-imap $sudo phpenmod imap

Then extension (imap) should appear on: $ php -m

But this doesn’t happen, so I tried to add it manually (this is probably not how you want do it, I don’t know)

  • I copied file from “/usr/lib/php/20170718/imap.so” into my: “/etc/php7/lib/php/extensions/debug-zts-20170718/imap.so”.
  • I added “extension=imap” to my php.ini file

The problem now is displaying error:

“PHP Warning: PHP Startup: Unable to load dynamic library ‘imap’ (tried: /etc/php7/lib/php/extensions/debug-zts-20170718/imap (/etc/php7/lib/php/extensions/debug-zts-20170718/imap: cannot open shared object file: No such file or directory), /etc/php7/lib/php/extensions/debug-zts-20170718/imap.so (/etc/php7/lib/php/extensions/debug-zts-20170718/imap.so: undefined symbol: file_globals)) in Unknown on line 0”

As I read, “undefined symbol: file_globals” probably means that I have wrong php API version of this extension to compile with php version. Or it has something to do with using zts?

I’m using Ubuntu 16.04 and I was literally searching for 10 hours to fix this, but I’m kinda php and Ubuntu beginner.

Any help would be highly appreciated! Thank you



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Make sure you’re installing the correct version of imap for PHP version you’re running. In other words, is php-imap for php 7.2? Also, is the php you’re running from the CLI actually php version 7.2 (php -v) or some other php version?

It seems like the issue you’re encountering is indeed related to the fact that you are using a custom-compiled version of PHP with pthreads (ZTS enabled), which requires extensions to be compiled with ZTS support as well. The IMAP extension you installed via apt-get is most likely not compiled with ZTS support, which is why it throws the error.

Here’s how you can resolve this by compiling the IMAP extension from source with ZTS support:

1. Install Required Dependencies:

Ensure you have the necessary build tools and dependencies for compiling PHP extensions:

sudo apt-get update
sudo apt-get install build-essential libpcre3-dev libssl-dev libcurl4-openssl-dev libxml2-dev libicu-dev

2. Download PHP Source:

Download the exact version of PHP that you have installed (including ZTS). For example, if you are using PHP 7.2, run:

wget https://www.php.net/distributions/php-7.2.x.tar.gz
tar -xzvf php-7.2.x.tar.gz
cd php-7.2.x/ext/imap

3. Prepare to Compile IMAP Extension:

Now that you’re in the imap extension directory, run phpize to prepare the environment for compiling:

phpize

This will generate the necessary configuration files to compile the extension with your custom PHP build.

4. Configure and Compile:

Next, configure and compile the IMAP extension:

./configure --with-php-config=/path/to/php-config --with-kerberos --with-imap-ssl
make
sudo make install
  • Replace /path/to/php-config with the path to the php-config file for your custom PHP installation. You can locate it using which php-config.
  • The make install step will copy the compiled imap.so file to the correct extensions directory.

5. Enable the Extension:

After the IMAP extension is compiled and installed, enable it by adding the following line to your php.ini file:

extension=imap.so

6. Restart Your Web Server:

Restart your web server (Apache, Nginx, or PHP-FPM):

sudo systemctl restart apache2  # for Apache
sudo systemctl restart php7.x-fpm  # for PHP-FPM

7. Verify the Installation:

Finally, verify that the IMAP extension is loaded by running:

php -m | grep imap

You should see imap listed as one of the installed modules.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.