正在使用不同版本的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.

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

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