3

I know there are a lot of questions about this on SO but none of them address my problem. I've checked everything they mention everything seems to indicate mcrypt is ok except when installing Laravel. Clearly I'm missing something.

When installing Laravel as directed (composer create-project laravel/laravel myproj --prefer-dist) I get the error "Mcrypt PHP extension required" at what seems to be near the end of installation.

As far as I can tell mcrypt is installed and enabled.

Composer uses /usr/bin/env php

$ which composer       
/usr/local/bin/composer

$ cat /usr/local/bin/composer
#!/usr/bin/env bash
/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar $*%   

php on my PATH is 5.5.10 from MAMP

$ php --version
PHP 5.5.10 (cli) (built: Apr 10 2014 17:49:22)

$ which php
/Applications/MAMP/bin/php/php5.5.10/bin/php   

Mcrypt is installed and enabled

$ php -m | grep mcrypt
mcrypt

$ php --info | grep mcrypt                  
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value

$ php --ini                                 
Configuration File (php.ini) Path: /Applications/MAMP/bin/php/php5.5.10/conf
Loaded Configuration File:         /Applications/MAMP/bin/php/php5.5.10/conf/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed:      (none)

$grep mcrypt /Applications/MAMP/bin/php/php5.5.10/conf/php.ini      
extension=mcrypt.so

I can see mcrypt support enabled in a phpinfo page via MAMP too.

What am I missing?

edit: I have export PATH="/Applications/MAMP/bin/php/php5.5.10/bin:$PATH" in .bash_profile and can confirm with echo $PATH and which php

update: a clue.

If I edit /usr/local/bin/composer to be:

#!/usr/bin/env bash
echo $PATH
/usr/bin/env php --ini

and run composer I get

/usr/bin:/bin:/usr/sbin:/sbin
Configuration File (php.ini) Path: /etc
Loaded Configuration File:         (none)
Scan for additional .ini files in: /Library/Server/Web/Config/php
Additional .ini files parsed:      (none)

Why is that PATH different?

Jake
  • 12,713
  • 18
  • 66
  • 96
  • Might be a long-shot but is the `mcrypt.so` file in the configured *extensions* directory? – Phil Jul 29 '14 at 01:23
  • 1
    Check http://laravel.io/forum/02-08-2014-difficulty-installing-laravel-getting-error-mcrypt-php-extension-required?page=1#reply-736. Composer may still be using the system PHP binary (due to `/usr/bin/env php`) – Phil Jul 29 '14 at 01:25
  • Yes and yes. I can see `mcrypt.so` in the dir that's specified in the ini and I have the MAMP php bin folder on my path (see edit) – Jake Jul 29 '14 at 01:33
  • Wait a sec... Everything above your edit uses `/Applications/MAMP/bin/php/php5.5.10` yet your `PATH` contains `/Applications/MAMP/bin/php/php5.4.19`. I'd say that's your problem. Upgraded MAMP recently? – Phil Jul 29 '14 at 01:39
  • Wait, are you running composer as root / via sudo? If so, don't do that – Phil Jul 29 '14 at 01:40
  • Thanks for all your help @phil. Sorry, the `5.4.19` is a typo. It's `5.5.10` really. And no, I'm not using sudo. – Jake Jul 29 '14 at 01:42
  • Better edit your question with the correct data then. Try running `source ~/.bash_profile && composer`. Perhaps your terminal session hasn't picked up the `PATH` changes – Phil Jul 29 '14 at 01:46
  • Nope :( same result. (I've been opening fresh terminal sessions anyway) – Jake Jul 29 '14 at 01:48
  • How did you install composer? It looks like it may have a sticky execute bit (SUID) – Phil Jul 29 '14 at 02:04
  • Installed with `brew`. Permissions are `-rwxr-xr-x` so no SUID, right? – Jake Jul 29 '14 at 03:46
  • 1
    I'm totally at a loss. This is why I use Vagrant on the mac – Phil Jul 29 '14 at 04:20
  • [http://stackoverflow.com/questions/28230327/mcrypt-php-extension-required-in-laravel-with-ubuntu-14][1] [1]: http://stackoverflow.com/questions/28230327/mcrypt-php-extension-required-in-laravel-with-ubuntu-14 – codereal Jul 17 '15 at 17:08

4 Answers4

6

Getting Laravel working on Apache

PHP version : PHP 5.5.9

Ubuntu version : 14.04

After a lot of trial and error and searching around , this is what i discovered . i had a working laravel project on windows, i copied it to ubuntu server and started getting the mcrypt error.

getting artisan command working

i did a lot of trial and error so each time i run the php5enmod command before, i had error messages. but on fresh install there was no error messages. after this step i got artisan command working

sudo rm /etc/php5/mods-available/mcrypt.ini
sudo apt-get purge php5-mcrypt
sudo apt-get install mcrypt
sudo apt-get install php5-mcrypt
sudo php5enmod mcrypt

fixing the browser error

sudo nano /etc/php5/apache2/php.ini

add the following line under the dynamically compiled extensions section of php ini

extension=mcrypt.so

restart the apache server , purge the laravel cache and everything working

Sojan Jose
  • 3,168
  • 6
  • 33
  • 52
1

From what you've posted, it looks like composer is using a different PHP installation than your MAMP version. One workaround would be using the PHAR version instead:

wget https://getcomposer.org/composer.phar
php composer.phar create-project laravel/laravel myproj --prefer-dist

If your CLI php is registering mcrypt as an installed module, this will resolve your installation issue.

Sam Dufel
  • 17,560
  • 3
  • 48
  • 51
  • You'd think so, but even that doesn't work (same error). – Jake Jul 29 '14 at 01:49
  • 1
    @Jake - Do you have libmcrypt installed? Have you verified that you're able to run the mcrypt functions via the CLI? – Sam Dufel Jul 29 '14 at 01:50
  • @SamDufel Good idea. Something like `php -r 'echo MCRYPT_ENCRYPT, PHP_EOL;'` should suffice (result should be `0`) – Phil Jul 29 '14 at 01:59
0

The only thing I can find to make this work is to edit /usr/local/bin/composer and set the PATH in there like so:

#!/usr/bin/env bash
export PATH="/Applications/MAMP/bin/php/php5.5.10/bin:$PATH"
/usr/bin/env php -d allow_url_fopen=On -d detect_unicode=Off /usr/local/Cellar/composer/1.0.0-alpha8/libexec/composer.phar $*

It's hacky and I'd still like to know what's up with my env but it works!

Jake
  • 12,713
  • 18
  • 66
  • 96
0

i had also encounter similar problem, and following command worked for me.

sudo apt-get install php5-mcrypt

Hope it will works your too.