Error when loading a php module - php

I added the curl module in /etc/php/7.0/cli/php.ini :
extension = /usr/lib/php5/20121212/curl.so
but when I restart php and I do :
php -m
I get this error :
curl : Unable to initialize module
Module compiled with module API=20121212
PHP compiled with module API=20141010
These options need to match
I also tried :
apt-get install php5-curl
Curl is "already to the new version".
And phpinfo() tells php5 is running :
PHP Version 5.5.9
php.ini Path : /etc/php5/fpm
PHP Extension : 20121212
but when I check on the server with :
which php => /usr/bin/php (for php7)
php -v => PHP 7.0 (with a warning before "Unable to initialize module")
and if I remove curl.so in the php.ini above (the one of php7, at 1st line) the warning disapear.
---------------------------------------
so I added : extension=/usr/lib/php5/20121212/curl.so
in :
/etc/php5/fpm/php.ini
then I restart, but I still can't see this module :
And here the error saying this module is still missing :

So, if you're trying to add the module to webserver's PHP, which is in your case PHP5, you need to add that module to /etc/php5/fpm/php.ini (based on your previous question where you stated that you use NGINX+PHP-FPM).
If you want to add it to the CLI version - you're doing it wrong, cause you're adding PHP5 module to PHP7 - that won't work, you need to install php7-curl and it will auto-add itself where needed.
To elaborate somewhat more. Your phpinfo() tells you that your INI path is in /etc/php5/fpm:
PHP Version 5.5.9
php.ini Path : /etc/php5/fpm
PHP Extension : 20121212
Hence, to add any extensions to that particular PHP - just add them to /etc/php5/fpm/php.ini. Note, you can not (or very rarely) add extensions from one version of PHP to another version of PHP.
I'll add a summary of what's happening on the OP's system for future reference then.
Basically, OP has 2 versions of PHP installed on the system simultaneously, PHP5 and PHP7 with an NGINX werserver with php-fpm extension.
His NGINX is configured to use PHP5, while CLI PHP defaults to PHP7.
The confusion with OP comes from the fact that on an Ubuntu system there's a clear difference between the PHP that's called from the CLI and the PHP that's used by webserver.
CLI tools are available per-version as /usr/bin/php5 and /usr/bin/php7, with one default link /usr/bin/php pointing to one particular version, in this case PHP7.
For the FPM module, there are 2 packages available php5-fpm and php7-fpm, with respective configs in /etc/php5/fpm/php.ini and /etc/php/7.0/php.ini.
For the CLI, there are 2 packages available as well - php5-cli and php7-cli, with respective configs in /etc/php5/cli/php.ini and /etc/php/7.0/cli/php.ini.
For curl extension, there's the same story, php5-curl and php7-curl. Extensions will be auto-wired to the needed INI files by the deb installer.
Installing multiple versions of PHP for fun can create this kind of confusion. :)

That means that your CURL module was compiled against a different version of PHP. Depending on your flavor of Linux (looks like Debian flavor) you might need to install a module
sudo apt-get install php5-curl

What about calling your hosting company to see what versions they have available and which one's your code are picking up?
Maybe they have some unique setup that's picking versions in a way you aren't picturing (one wouldn't picture.)

Related

Mac OS: Intl extension is not loaded

macOS Mojave 10.14.3
PHP 7.1.23
Prestashop 1.7.5.1
I tried to install PHP intl extension on my local server in order to use Prestashop.
I added extension=php_intl.so to etc/php.ini
When I try to install Prestashop I get Intl extension is not loaded.
$ php -m | grep intl
When I do $ php -m | grep intl, I get:
PHP Warning: PHP Startup: Unable to load dynamic library
'/usr/local/lib/php/pecl/20160303/php_intl.so' - d
lopen(/usr/local/lib/php/pecl/20160303/php_intl.so, 9): image not found in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/pecl/20160303/php_intl.so' - dlopen
(/usr/local/lib/php/pecl/20160303/php_intl.so, 9): image not found in Unknown on line 0
intl
It seems that the file php_intl.so doesn't exist.
$ sudo pecl install intl
I also tried $ sudo pecl install intland I get:
make: *** [php_intl.lo] Error 1
ERROR:make' failed`
$ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1
I also tried $ curl -s http://php-osx.liip.ch/install.sh | bash -s 7.1 and it doesn't create the intl.so file.
How can I solve this problem?
Brew's PHP 7.1, 7.2 and 7.3 all have INTL enabled by default.
Most probably, you're just using your Mac OS' bundles version of PHP.
Run
ls -l $(which php)
to find out where the current PHP binary is located and whether it is symlinked to a Brew installation or not. In my case, for example:
lrwxr-xr-x 1 27 May 23 16:30 /usr/local/bin/php -> ../Cellar/php/7.3.5/bin/php
Meaning that my php is linked to Brew's 7.3.5 version.
If you are NOT using Brew's PHP, you'll see something like
-rwxr-xr-x 1 11169664 Mar 21 07:09 /usr/bin/php
Installing PHP through Brew
Find out whether you've already installed PHP:
brew list | grep php
If there is any output, and your version of PHP is present, go to step 2, or use step 1 to update PHP to the latest version.
1. Install Homebrew's PHP
brew install php#7.3
(or 7.2, 7.1). If Brew complains about not being able to find a formula, you might have messed with taps. Instead of php#7.3, you could try to supply the full path to the current php formula:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/master/Formula/php.rb
Still not working, check whether you are running a recent version of Homebrew brew --version.
Homebrew 2.1.3-31-geaf2370
Homebrew/homebrew-core (git revision fd1ef; last commit 2019-05-25)
Homebrew/homebrew-cask (git revision 16d50; last commit 2019-05-26)
2. Link Homebrew's PHP
Now, to have php 'in your path', there are two options.
a) Either homebrew's version must be linked from its install location (/usr/local/bin/Cellar/php....) to a directory in your path (e.g., /usr/local/bin). To do this, run:
brew link --force php#7.3
If you are not able to link, this is typically caused by set permissions or System Integrity Protection. In the first case, try sudo chown "$USER":admin /usr/local/bin/php.
b) Or, add the /usr/local/opt/php#7.3 directory (opt-prefix) to your $PATH variable. E.g., for Bash:
echo 'export PATH="/usr/local/opt/php#7.3/bin:/usr/local/opt/php#7.3/sbin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
3. Validate installation
ls -l $(which php)
should show that php is linked to a Homebrew PHP installation in /usr/local/bin/Cellar.
php -v
should show the recently installed version of PHP. Try to restart your terminal if that's not the case.
php -i | grep -i intl
should show some information about the current install of intl.
If you're using webservers and/or PHP FPM, this is the time to restart those services. (Or restart your system, if you don't know how to do that and cannot figure out).
Possible issues
If you still get warnings about missing extensions (Unable to load dynamic library, etc.), then your php.ini is messed up.
Find the current location of php's ini
$ php -i | grep \.ini
Configuration File (php.ini) Path => /usr/local/etc/php/7.3
Loaded Configuration File => /usr/local/etc/php/7.3/php.ini
Scan this dir for additional .ini files => /usr/local/etc/php/7.3/conf.d
Additional .ini files parsed => /usr/local/etc/php/7.3/conf.d/ext-opcache.ini
....
Edit /usr/local/etc/php/7.3/php.ini and find the offending extension load (e.g., extension="myext.so"). Comment out those that cannot be found.
Homebrew permissions
Some argue that it's a good idea to chown /usr/local.
sudo chown -R "$USER":admin /usr/local
This will make installing things here, by hand and through Homebrew, a lot easier, but also a bit less secure too, since non-root processes are now allowed to write here too.
Your web-application is using a different version of PHP.
Make sure that it doesn't... The configuration of this depends on the used webserver. A first step would be to output the current PHP configuration in your web-application with <?php phpinfo();.
This explains steps for Apache.
Another way to get a webserver + PHP stack running quicly is using Laravel Valet.
Installing additional extensions
To install additional PHP extensions, use PEAR.
pear -V
should output the current PEAR and PHP version.
PEAR Version: 1.10.9
PHP Version: 7.3.5
Zend Engine Version: 3.3.5
Now, to install an extension, for example, PHP's yaml extension:
pear install yaml
I have seen a lot of answers about this problem and anyone helped me, but the last (of course). This is for XAMPP´s use.
Xcode is needed.
Download the version of php you use in xampp from php.net.
Extract it and open the extracted folder in a terminal using cd.
Change to subfolder ext/intl.
Run these commands to build the extension:
/Applications/XAMPP/bin/phpize
./configure --enable-intl --with-php-config=/Applications/XAMPP/bin/php-config --with-icu-dir=/Applications/XAMPP/xamppfiles/
make
sudo make install (password required)
Delete all files you downloaded and also the extracted folders.
Add to php.ini file in xampp/etc folder line
extension="intl.so"
Original link: https://community.apachefriends.org/viewtopic.php?p=255061&sid=27afc55649dfe6ea7b0824cb0bb8486b
Since php 7 it's not necessary load the extension php_intl.so, what do you need to do?, edit your php.ini and delete or comment the line that is loading the extension php_intl.so, after this reload your apache and try again.
There might be an issue with brew
You could try to use this as mentioned there:
brew tap kyslik/homebrew-php
brew install kyslik/php/php71-intl
i tried all but intl not working in mac so please uninstall xampp and install mamp it will work
So, on Pecl Official site ( https://pecl.php.net/package/intl ), it's clear that Intl package is not maintained anymore and has been superseded. Since PHP 5.3.0 you don't need to use Pecl to install intl extension, it's bundled with PHP.
But, it's missing on native instalation of PHP 7.1.24 on Mac OS Mojave.
if you wanna use only native apache and php pre-installed instead of using homebrew, do this:
Download PHP 7.1 from php.net, install XCode Command Line Tools, ICU (http://site.icu-project.org/), Autoconf, reinstall the developer tools header files, and finally install Intl extension using phpize.
Important: you'll have to disable SIP.

CodeIgniter Error After Changing PHP from 5.6 to 7.0 on HostGator via SSH

So as the title describe, I am receiving this error right now on my CI after changing the PHP from 5.6 to 7.0. It works fine if I revert back to 5.6 but I need my server to be on 7.0.
A PHP Error was encountered
Severity: Core Warning
Message: PHP Startup: SourceGuardian: Unable to initialize module Module compiled with module API=20121212 PHP compiled with module API=20151012 These options need to match
Filename: Unknown
Line Number: 0
Backtrace:
From my 2013 blog post: https://delboy1978uk.wordpress.com/2013/10/30/manually-compiling-php-modules-successfully/
This look familiar?
PHP Warning: PHP Startup: memcached: Unable to initialize module
Module compiled with module API=20090626
PHP compiled with module API=20100525
These options need to match
I don’t know about you, but i like to be up to date! My PHP is on 5.5, and I had to install some modules. But sometimes, old versions can rear their ugly head, and cause all manner of grief. Package managers do a good job to take care of all this for you, but sometimes they just don’t work. Leaving you to compile yourself! So lets do it! I’m going to install memcached, and then the imagick libraries (now i know what i’m doing!)
I’m doing this on a CentOS 6 server, but as we are doing the old skool way of compiling etc, this should work on any other flavour of Linux, or indeed Mac OS X.
First step is to download your .tar.gz then unzip it with tar -zxvf file.tar.gz and change into the folder.
Bring up a web page displaying your servers php.ini. You are looking for the version of PHP API, and the extension_dir.
In your terminal, cd into the module source code folder, and type phpize.
If when you check the API versions , they are different from your php.ini, then an old version of php is being used in the terminal, and your module will not work! In this case, you need to get it to use the correct phpize.
type which phpize to find out where the offending file is. (mine was /usr/bin/phpize)
My PHP appeared to be in /usr/local, so I tried running /usr/local/phpize. The API’s matched. So then I did the following:
mv /usr/bin/phpize /usr/bin/phpize-old
ln -s /usr/local/bin/phpize /usr/bin/phpize
Half way there! We need to do the same for php-config
mv /usr/bin/php-config /usr/bin/php-config-old
ln -s /usr/local/bin/php-config /usr/bin/php-config
Now you have done that, installation should be trivial, and work as per loads of tutorial/instrruction pages on the web.
./configure
make
make install
Finally edit your php.ini and add ‘extension = memcached.so’ (or whatever module you compiled), and restart your apache server!
EDIT : you may need to run ‘phpize –clean’ if it is still compiling with the older stuff from within the modules source folder
Download latest SourceGuardian module, which support PHP 7.X:
https://www.sourceguardian.com/loaders/download.php

PHP is not loaded as a module of Apache

I'm currently developing a web page with PHP, and I had to install Pthread extension, I made it in the server (Ubuntu 14) so, before I had all working well, the problem came when I installed the extension, to install this extension I had to compile the php to make the needed configurations of PHP. Now, when I open a simple page, apache shows me the php code, it means that php is not interpreting or is not loaded in the modules of apache.
I went to /etc/apache2/mods-enabled but there's nothing of PHP, but in the linux terminal PHP is working well (so, it's installed). then I made:
sudo a2enmod php5
And I get this response:
ERROR: Module php5 does not exist!
then , I made:
a2query -m php5
but I get:
No module matches php5
I have installed PHP 5.6version, so how can I enable this module in apache. I cannot install the standar version of PHP, I need this one for the mentioned reason. Thanks!
Apache needs a PHP module to execute PHP. In some distros (Debian, etc.) there is a specific package for this. In Ubuntu: libapache2-mod-php5
It does not impact the php installation install but only adds the apache module.
Once installed, one only need to activate the module.

How to check which PHP extensions have been enabled/disabled in Ubuntu Linux 12.04 LTS?

I'm using Ubuntu Linux 12.04 LTS on my local machine. I've installed LAMP long ago on my machine. Now I want to enable following PHP extensions:
php_zip
php_xml
php_gd2
For it first I want to check whether these PHP extensions are enabled or not. I searched a lot about how to check the installed/enabled PHP extensions but every time I found how to install these extensions on Ubuntu Linux. So can someone please let me know how should I check the enabled/disabled PHP extensions in Ubuntu Linux 12.04 LTS?
Checking for installed php modules and packages
In addition to running
php -m
to get the list of installed php modules, you will probably find it helpful to get the list of the currently installed php packages in Ubuntu:
sudo dpkg --get-selections | grep -v deinstall | grep php
This is helpful since Ubuntu makes php modules available via packages.
You can then install the needed modules by selecting from the available Ubuntu php packages, which you can view by running:
sudo apt-cache search php | grep "^php5-"
Or, for Ubuntu 16.04 and higher:
sudo apt-cache search php | grep "^php7"
As you have mentioned, there is plenty of information available on the actual installation of the packages that you might require, so I won't go into detail about that here.
Related: Enabling / disabling installed php modules
It is possible that an installed module has been disabled. In that case, it won't show up when running php -m, but it will show up in the list of installed Ubuntu packages.
Modules can be enabled/disabled via the php5enmod tool (phpenmod on later distros) which is part of the php-common package.
Ubuntu 12.04:
Enabled modules are symlinked in /etc/php5/conf.d
Ubuntu 12.04: (with PHP 5.4+)
To enable an installed module:
php5enmod <modulename>
To disable an installed module:
php5dismod <modulename>
Ubuntu 16.04 (php7) and higher:
To enable an installed module:
phpenmod <modulename>
To disable an installed module:
phpdismod <modulename>
Reload Apache
Remember to reload Apache2 after enabling/disabling:
service apache2 reload
To check if this extensions are enabled or not, you can create a php file i.e. info.php and write the following code there:
<?php
echo "GD: ", extension_loaded('gd') ? 'OK' : 'MISSING', '<br>';
echo "XML: ", extension_loaded('xml') ? 'OK' : 'MISSING', '<br>';
echo "zip: ", extension_loaded('zip') ? 'OK' : 'MISSING', '<br>';
?>
That's it.
You can view which modules (compiled in) are available via terminal through php -m
Perhaps the easiest way to see which extensions are (compiled and) loaded (not in cli) is to have a server run the following:
<?php
$ext = get_loaded_extensions();
asort($ext);
foreach ($ext as $ref) {
echo $ref . "\n";
}
PHP cli does not necessarily have the same extensions loaded.
For information on php extensions etc, on site.
Create a new file and name it info.php (or some other name.php)
Write this code in it:
<?php
phpinfo ();
?>
Save the file in the root (home)of the site
Open the file in your browser. For example: example.com/info.php
All the php information on your site will be displayed.
Search extension in
/etc/php5/apache2/php.ini
Another quick way to see if a module is enabled / disabled vs only installed or not is to use phpquery command.
For example, on my Linux Mint machine, if I want to see if xdebug is enabled I would run:
phpquery -v 8.1 -s apache2 -m xdebug
-v - is to specify for which version you want
-s - to specify the environment (apache2 or cli)
-m - the module you are interested into.
The response for the above example was (in my case):
xdebug (Enabled for apache2 by maintainer script)
Here some more examples.

How to install pthreads on a phpfarm php installation

Documenting my struggles to help others and hopefully get some feedback on how I could have done it better.
The command pecl install pthreads fails due to the php installed on my ubuntu 13.04 box not having zts configured.
Options:
1) The ubuntu respository does not have a php package with zts enabled. As of this post, ubuntu only has php 5.4.9 in it's repository (Released: 22 Nov 2012). It is possible to compile a php version from source - which I eventually did (see below), but..
2) I .. ALSO .. wanted to use phpfarm for the ability to run different versions of PHP on my local setup. On github, there is Christian Weiske's original contribution here (phpfarm) and a fork that he has contributed to, by François Poirotte - also called phpfarm. Francois' fork has a few more options to configure ('post-install customization') but I was not able to make that work with a PECL extension. I'm curious to know if misunderstood how to do that, because it looks to me that it just simply does not take PECL commands.
3). Prior to recompiling php from source, I loaded phpfarm (tried both versions), enabled php-fpm (FastCGI) and was able to get my apache2 server to use a phpfarm version (5.5.10) which showed up in a phpinfo() output. But the php-cli always showed the original php version (5.4.9) in the cli (run: php -v). Running (run: php -i | grep php.ini) showed /etc/php5/cli but I had previously removed php5 and aptitude show php5 returned a state of 'not installed.' I even renamed the /etc/php5 directory to see if I could force the system to use the phpfarm php version. Obviously, this is incorrect thinking and I went on to simply compile php 5.6 from source. But, is there something more to do to get a phpfarm php to be used in the cli? I read that the cli loads it's configuration file on a per command basis, unlike the apache2. If I could have run the 5.5.10 version (configured with zts) then I could have then done pecl install pthreads and then re-complied the phpfarm 5.5.10 version with pthreads enabled. Although it appears I will be able to run various versions of php in the apache server, will I ever be able to switch-phpfarm to another version and see it working in the php-cli? Also, I was uncertain on where I could have loaded a pthreads file for the phpfarm compile process to find and use it; could I have done it that way?
4) This stackoverflow post, essentially posted by Joe Watkins - the developer of pThreads is a perfect how-to on getting pThreads installed on a Ubuntu system that has had php configured with zts (Zend Thread Safety). (Thanks Joe!)
A nice tutorial on using phpfarm configured with fast-cgi and the apache server to help run websites under different php configurations.
So what gives with php, php-cli and the phpfarm?
I'm not sure about phpfarm, but do know of another solution ...
Multi
A tool for maintaining multiple installations of PHP in multiple configurations
https://github.com/datingvip/multi
This is a bit more user orientated, will allow you to build many configurations and versions of php, any tagged release of php, and any patched version from any fork of php-src.
In addition, because I wrote it, it will install pthreads for you.
git clone https://github.com/datingvip/multi
cd multi
VERSION=5.5.10 DBG=no-debug ZTS=zts ./php.multi
The above commands will yield an installation of PHP (in one suitable configuration, of one version) in /opt/php.
Look at php.defaults for configuration options and adjust before building
Should configuration fail on, for example, something related to a library like libxml2, it will usually be the case that
sudo apt-get install library-dev
Where library is replaced with the name of the library holding up the build, will fix the problem for you. If it does not, a quick google should get you going again.
Once the build is complete
source /path/to/multi/php.env 5.5.10
Note: multi will always install pthreads for any zts version automatically
I hope that gets you somewhere ...

Categories