different versions of php being used - php

I am trying to install magento and it keeps throwing the error "PHP extension mcrypt must be loaded". When I tried to install mcrypt I got a message that it is already installed.
So I ran php -v, which php and php -i | grep mcrypt in the command line and got back
PHP 5.4.23 (cli)....
and
/usr/local/bin/php
and
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value
So I added phpinfo(); die(); to my index.php magento file and that returned
Version 5.4.17
Configuration File (php.ini) Path /etc
Loaded Configuration File /etc/php.ini
but no reference to mcrypt
Am I right in reading that as magento is using a different version of php to what the commandline is? and if so how do I resolve this situation?
I am running other installs of Magento and so when I considered trying to delete /etc and letting Magento automatically pick up the correct version, I decided against it as I don't want the other installs to stop working.

You are right when you say that magento is using different php version (altough only subversion). It is most likely that your cli .ini is different from apache .ini
What you can try is add extension=mcrypt.so to /etc/php.ini and restart apache

Echo your phpinfo(). Via cmd it's possible to receive other information then needed. You'll see which PHP version is used and where your php.ini is located.
Open php.ini and search for ;php_mcrypt.dll. Remove the semicolon and restart Apache.
Edit: for Linux versions:
apt-get install php5-mcrypt
service apache2 restart - restart Apache
If you get the 'already installed' message you could use:
apt-get --reinstall install php5-mcrypt
Make sure that the semicolon is remove in php.ini: extension=mcrypt.so

Related

phpMyAdmin does not connect [duplicate]

I receive this error after trying to set up LAMP by following this tutorial, and I find myself receiving the above error after trying to set up phpmyadmin.
Fatal error: Call to undefined function mb_detect_encoding() in
C:\WebServer\Apache\htdocs\phpmyadmin\libraries\php-gettext\gettext.inc
on line 177
I followed the advice over here: PHP Fatal error when trying to access phpmyadmin mb_detect_encoding, and made those changes.
When I run phpinfo(), I see that support for MySQL and mb_string are enabled as shown below:
Install the gd library also.
check this link
http://www.php.net/manual/en/mbstring.installation.php
There's a much easier way than recompiling PHP. Just yum install the required mbstring library:
Example: How to install PHP mbstring on CentOS 6.2
yum --enablerepo=remi install php-mbstring
Oh, and don't forget to restart apache afterward.
Mbstring is a non-default extension. This means it is not enabled by default. You must explicitly enable the module with the configure option.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
In case your php version is 7.0:
sudo apt-get install php7.0-mbstring
sudo service apache2 restart
In case your php version is 5.6:
sudo apt-get install php5.6-mbstring
sudo service apache2 restart
On Windows open the file php.ini and make this changes:
Remove the comment and point to the ext directory
; extension_dir = "./" -> extension_dir = "C:/Php/ext"
Remove the comment of this extensions
extension=php_mbstring.dll
extension=php_mysqli.dll
Restart apache service
httpd -k restart
When I opened my php.ini file, "extension_dir" line looked like following :
extension_dir = "C:/wamp/bin/php/php5.4.16/ext/"
which i changed to:
extension_dir = "C:\wamp\bin\php\php5.4.16\ext\"
and it worked.
Under Windows / WAMP there doesn't seem to be any php_mbstring.dll dependencies on the GD2 extension, the MySQL extensions, nor on external dlls/libs:
deplister.exe ext\php_mbstring.dll
php5ts.dll,OK
MSVCR110.dll,OK
KERNEL32.dll,OK
deplister.exe ext\php_gd2.dll
php5ts.dll,OK
USER32.dll,OK
GDI32.dll,OK
KERNEL32.dll,OK
MSVCR110.dll,OK
Whatever php_mbstring already needs, it's built-in (statically compiled right into the DLL).
Call to undefined function mb_detect_encoding()
This error is also very specific and deterministic...
The function mb_detect_encoding() didn't fail because php_gd, php_mysql, php_mysqli, or another extension was not loaded; it simply was NOT found.
I'm guessing that all the answers that are reported as valid (for Windows / WAMP), that say to load other extensions, to change php.ini extension_dir paths (if this one was wrong to begin with, NO extensions would load), etc, work more due to a) un-commenting the extension = php_mbstring.dll line, or b) restarting Apache or the computer (for changes to take effect).
On Windows, most of the time the problem is that php_mbstring.dll is either:
Blocked by Windows. Unblock it by right-clicking it, check Properties.
Or PHP can't load php_mbstring.dll due to another version getting loaded (e.g., from some improper PHP DLLs install into C:\Windows\system32), some version mismatch, missing run-time DLLs, etc. Check Apache's and PHP's error log files first for clues.
More in-depth answer here: Call to undefined function mb_detect_encoding
For fedora/centos/redhat:
yum install php-mbstring
Then restart apache
you should use only english version of phpmyadmin if you are using all languages you should enable all languages mbstring in php.in file.....just search for mbstring in php.in
The problem could also be that Apache can't find php.ini
If you set PHPIniDir incorrectly.
Mine was set to: PHPIniDir "c:/php7"
But, the folder is actually just "php"
The clue was viewing phpinfo()
Which showed:
Configuration File (php.ini) Path C:\windows
I had the same problem with Ubuntu 17, Ispconfig was not processing the operations queued of any kind and also the server.sh command was not working.
I checked and the running PHP version after the OS upgrade was 7.1 so the solution was to type:
apt-get install php7.1-mbstring
and now is everything ok
Hope this helps some ppl, I got this error when i added the path and extension to "docref_root" "docref_ext" in my php.ini file, I then commented it out and it was ok, but cant get my help to work now.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
PHP.INI XAMP5.6 > In my case, while updating max_ values, I removed
; max_input_time
Default Value: -1 (Unlimited)
After undoing everything works normally.
; max_input_time
; Default Value: -1 (Unlimited)

PDOException “could not find driver” with heroku, postgres and laravel [duplicate]

pdo is working fine with mysql but with pgsql its giving error 'PDOException' with message 'could not find driver' I've installed php5-pgsql package which also includes pdo_pgsql
http://packages.debian.org/sid/php5-pgsql
This package provides a module for PostgreSQL database connections directly from PHP scripts. It also includes the pdo_pgsql module for use with the PHP Data Object extension.
my dsn is pgsql:dbname=DB;host=192.168.0.2
I am using Ubuntu 10.04
This message means you need to install and or activate postgresql extension in PHP
This solution works for me :
To install postgresql extension
[sudo] apt-get install php-pgsql
after, for activating it, uncomment pgsql and pdo-pgsql extensions in etc/php/$PHP_VERSION/apache2/php.ini file
Finally, type :
[sudo] /etc/init.d/apache2 restart
To restart apache server if you use apache such as was my case...
1) Have you enabled pgsql.so in php.ini (extension=pgsql.so)?
2) Is you Postgresql listenin on 192.168.0.2 interface? (You can check it by netstat -tpln)
3) How you authenticate your access into Postgresql?
Make sure you've uncommented the line that tells php where the Postgres driver is (usually extension=pgsql.so) in the main php.ini file.
I had the same issue. First of all - check is it enabled in php.ini. Uncomment extension=php_pdo_pgsql...
than set up extension directory!!
extension_dir = "ext" ; for your case it could be other dir.
and do not forget to restart server after changing the config.
Try to remove semicolon in front of
extension=pgsql
extension=pgsql.so
included in your php.ini file
You can do that from the XAMPP Control Panel.
Here is what I did to solve the problem.
Edit php.ini and remove ; from extension=pdo_pgsql. Also, add extension=pgsql.so to the php.ini file.
Make sure to restart the Apache server before you try to see the result.
I had the same problem with another solution. I lost my around 4 hours to solve this problem. Please check the following to solve this problem.
Check php.ini file and remove semicolon from this line
extension=pgsql
extension=pdo_pgsql
Restart your apache2 server
sudo service apache2 restart
Check if your PDO driver has updated in localhost phpinfo()
I did All the things right and still I had this problem. And you know why? Because I had several versions of php installed. So I was running php7.4 in my php cli but localhost was running on php7.2. So always check your php versions.
Check your php version on localhost and terminal cli
When you do not have postgresql installed on the same machine that is Apache and PHP; you have to install php-pgsql and don't have to add extensions in php.ini manually in Linux (in Windows yes), because redundancies are generated and this does not work (checked in error.log).
$ sudo apt install php-pgsql
Then you can check the existence of the extension enabled automatically in:
$ sudo nano /etc/php/7.0/apache2/conf.d/10-pdo.ini
Observations: In phpinfo() you will find the directory conf.d/ and the file error.log
GL
Just run php --ini and look for Loaded Configuration File in output for the location of php.ini used by your CLI
then check you have enabled the extensions correctly.
Copy libpq.dll from the PHP directory to Apache24\bin (or wherever your installation could be).

Enable MCrypt using MAMP

I'm using MAMP and ive installed a fresh version of Opencart, its telling me i dont have MCrypt enabled, when i go to terminal and type:
php -m | grep mcrypt
output: mcrypt
I can locate the library but it doesn't seem to be enabled.
That fact that php -m | grep mcrypt returns mcrypt, means the mcrypt library is INSTALLED and ENABLED.
Although it may just be enabled for CLI.
You can try editing the PHP.ini file and adding the following line under the ; Extensions section:
extension=mcrypt.so
Restart Apache / MAMP after saving php.ini file.
To find the correct php.ini file to edit, run the following command line:
php --info | grep php.ini
(If the line already exists, you may just need to remove the ; thats in front of it.)
I have tried so many ways but had no luck.
After a lot of trials finally came up with a solution.
Go to bin directory inside current active PHP version directory. In my case it is /Applications/MAMP/bin/php/php7.2.8/bin
It might be different in your case. Now run the below command with sudo
sudo ./pecl install channel://pecl.php.net/mcrypt-1.0.1
Now You should add extension=mcrypt.so to php.ini
Restart MAMP Service and check if it is working.
I had this issue following upgrading to MAMP 5.1 and using PHP 7.1.20...
The issue I found was not that MAMP PHP did not have mcrypt installed, it certainly does come bundled.
The issue was that the MAMP PHP configuration option "Make this version available on the command line" was NOT working and so the version of PHP I was using on the command line [in my case] was the macOS default PHP 7.1.16 without mcrypt (the version included in macOS by default)
Reverting to the old cli php alias meant the correct MAMP version of PHP was used on the command line
Added to .bash_profile
alias php='/Applications/MAMP/bin/php/php7.1.20/bin/php'
try in console
pecl install mcrypt
Using Brew:
Install mcrypt: brew install mcrypt
In Mamp: File -> Edit Template -> PHP (php.ini)-> {PHP version}
Find 'Dynamic Extensions' in the text and add the following below (after the lines starting with ';'):
extension=mcrypt.so
Save, restart and test (with php -i | grep mcrypt for example)

Fatal error: Call to undefined function mb_detect_encoding()

I receive this error after trying to set up LAMP by following this tutorial, and I find myself receiving the above error after trying to set up phpmyadmin.
Fatal error: Call to undefined function mb_detect_encoding() in
C:\WebServer\Apache\htdocs\phpmyadmin\libraries\php-gettext\gettext.inc
on line 177
I followed the advice over here: PHP Fatal error when trying to access phpmyadmin mb_detect_encoding, and made those changes.
When I run phpinfo(), I see that support for MySQL and mb_string are enabled as shown below:
Install the gd library also.
check this link
http://www.php.net/manual/en/mbstring.installation.php
There's a much easier way than recompiling PHP. Just yum install the required mbstring library:
Example: How to install PHP mbstring on CentOS 6.2
yum --enablerepo=remi install php-mbstring
Oh, and don't forget to restart apache afterward.
Mbstring is a non-default extension. This means it is not enabled by default. You must explicitly enable the module with the configure option.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
In case your php version is 7.0:
sudo apt-get install php7.0-mbstring
sudo service apache2 restart
In case your php version is 5.6:
sudo apt-get install php5.6-mbstring
sudo service apache2 restart
On Windows open the file php.ini and make this changes:
Remove the comment and point to the ext directory
; extension_dir = "./" -> extension_dir = "C:/Php/ext"
Remove the comment of this extensions
extension=php_mbstring.dll
extension=php_mysqli.dll
Restart apache service
httpd -k restart
When I opened my php.ini file, "extension_dir" line looked like following :
extension_dir = "C:/wamp/bin/php/php5.4.16/ext/"
which i changed to:
extension_dir = "C:\wamp\bin\php\php5.4.16\ext\"
and it worked.
Under Windows / WAMP there doesn't seem to be any php_mbstring.dll dependencies on the GD2 extension, the MySQL extensions, nor on external dlls/libs:
deplister.exe ext\php_mbstring.dll
php5ts.dll,OK
MSVCR110.dll,OK
KERNEL32.dll,OK
deplister.exe ext\php_gd2.dll
php5ts.dll,OK
USER32.dll,OK
GDI32.dll,OK
KERNEL32.dll,OK
MSVCR110.dll,OK
Whatever php_mbstring already needs, it's built-in (statically compiled right into the DLL).
Call to undefined function mb_detect_encoding()
This error is also very specific and deterministic...
The function mb_detect_encoding() didn't fail because php_gd, php_mysql, php_mysqli, or another extension was not loaded; it simply was NOT found.
I'm guessing that all the answers that are reported as valid (for Windows / WAMP), that say to load other extensions, to change php.ini extension_dir paths (if this one was wrong to begin with, NO extensions would load), etc, work more due to a) un-commenting the extension = php_mbstring.dll line, or b) restarting Apache or the computer (for changes to take effect).
On Windows, most of the time the problem is that php_mbstring.dll is either:
Blocked by Windows. Unblock it by right-clicking it, check Properties.
Or PHP can't load php_mbstring.dll due to another version getting loaded (e.g., from some improper PHP DLLs install into C:\Windows\system32), some version mismatch, missing run-time DLLs, etc. Check Apache's and PHP's error log files first for clues.
More in-depth answer here: Call to undefined function mb_detect_encoding
For fedora/centos/redhat:
yum install php-mbstring
Then restart apache
you should use only english version of phpmyadmin if you are using all languages you should enable all languages mbstring in php.in file.....just search for mbstring in php.in
The problem could also be that Apache can't find php.ini
If you set PHPIniDir incorrectly.
Mine was set to: PHPIniDir "c:/php7"
But, the folder is actually just "php"
The clue was viewing phpinfo()
Which showed:
Configuration File (php.ini) Path C:\windows
I had the same problem with Ubuntu 17, Ispconfig was not processing the operations queued of any kind and also the server.sh command was not working.
I checked and the running PHP version after the OS upgrade was 7.1 so the solution was to type:
apt-get install php7.1-mbstring
and now is everything ok
Hope this helps some ppl, I got this error when i added the path and extension to "docref_root" "docref_ext" in my php.ini file, I then commented it out and it was ok, but cant get my help to work now.
In case your php version is 7.2:
sudo apt-get install php7.2-mbstring
sudo service apache2 restart
PHP.INI XAMP5.6 > In my case, while updating max_ values, I removed
; max_input_time
Default Value: -1 (Unlimited)
After undoing everything works normally.
; max_input_time
; Default Value: -1 (Unlimited)

PostgreSql 'PDOException' with message 'could not find driver'

pdo is working fine with mysql but with pgsql its giving error 'PDOException' with message 'could not find driver' I've installed php5-pgsql package which also includes pdo_pgsql
http://packages.debian.org/sid/php5-pgsql
This package provides a module for PostgreSQL database connections directly from PHP scripts. It also includes the pdo_pgsql module for use with the PHP Data Object extension.
my dsn is pgsql:dbname=DB;host=192.168.0.2
I am using Ubuntu 10.04
This message means you need to install and or activate postgresql extension in PHP
This solution works for me :
To install postgresql extension
[sudo] apt-get install php-pgsql
after, for activating it, uncomment pgsql and pdo-pgsql extensions in etc/php/$PHP_VERSION/apache2/php.ini file
Finally, type :
[sudo] /etc/init.d/apache2 restart
To restart apache server if you use apache such as was my case...
1) Have you enabled pgsql.so in php.ini (extension=pgsql.so)?
2) Is you Postgresql listenin on 192.168.0.2 interface? (You can check it by netstat -tpln)
3) How you authenticate your access into Postgresql?
Make sure you've uncommented the line that tells php where the Postgres driver is (usually extension=pgsql.so) in the main php.ini file.
I had the same issue. First of all - check is it enabled in php.ini. Uncomment extension=php_pdo_pgsql...
than set up extension directory!!
extension_dir = "ext" ; for your case it could be other dir.
and do not forget to restart server after changing the config.
Try to remove semicolon in front of
extension=pgsql
extension=pgsql.so
included in your php.ini file
You can do that from the XAMPP Control Panel.
Here is what I did to solve the problem.
Edit php.ini and remove ; from extension=pdo_pgsql. Also, add extension=pgsql.so to the php.ini file.
Make sure to restart the Apache server before you try to see the result.
I had the same problem with another solution. I lost my around 4 hours to solve this problem. Please check the following to solve this problem.
Check php.ini file and remove semicolon from this line
extension=pgsql
extension=pdo_pgsql
Restart your apache2 server
sudo service apache2 restart
Check if your PDO driver has updated in localhost phpinfo()
I did All the things right and still I had this problem. And you know why? Because I had several versions of php installed. So I was running php7.4 in my php cli but localhost was running on php7.2. So always check your php versions.
Check your php version on localhost and terminal cli
When you do not have postgresql installed on the same machine that is Apache and PHP; you have to install php-pgsql and don't have to add extensions in php.ini manually in Linux (in Windows yes), because redundancies are generated and this does not work (checked in error.log).
$ sudo apt install php-pgsql
Then you can check the existence of the extension enabled automatically in:
$ sudo nano /etc/php/7.0/apache2/conf.d/10-pdo.ini
Observations: In phpinfo() you will find the directory conf.d/ and the file error.log
GL
Just run php --ini and look for Loaded Configuration File in output for the location of php.ini used by your CLI
then check you have enabled the extensions correctly.
Copy libpq.dll from the PHP directory to Apache24\bin (or wherever your installation could be).

Categories