Use of undefined constant MCRYPT_RIJNDAEL_128 - as

2019-01-25 13:24发布

I have successfully installed Laravel, but after running php artisan serve and going to localhost:8000 I get this error:

Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'

I have checked phpinfo() on localhost:8888 and it says that mcrypt is properly installed. However the only thing I can think of is that maybe my path is wrong?

in my .bash_profile I have

PATH=/usr/local/bin:$PATH

Every time I try to run Laravel commands I have to type this in the terminal:

export PATH="~/.composer/vendor/bin:$PATH" 

I am running on a Mac. Is there a simple way I can set up my bash_profile so that I can consistently change between localhost addresses and still have all the proper PHP functions working?

7条回答
等我变得足够好
2楼-- · 2019-01-25 13:44

For Mac users's specially - install it using Home Brew

I’ve installed an empty Laravel installation and got the following error message when navigating to http://localhost/kanban/public/:

Notice: Use of undefined constant MCRYPT_RIJNDAEL_128 – assumed ‘MCRYPT_RIJNDAEL_128′ in /Library/WebServer/Documents/xxx/config/app.php on line 83

Googling for this error message return many tutorials on how to install mcrypt on Mac OS X (whether building it from source or using Homebrew). The problem was that both the mcrypt and the php55-mcrypt packages were properly installed:

$ brew install mcrypt
Warning: mcrypt-2.6.8 already installed
$ brew install php55-mcrypt
Warning: php55-mcrypt-5.5.20 already installed

Mcrypt was also properly loaded by PHP:

$ php -m | grep mcrypt
mcrypt

$ php -i | grep mcrypt
Additional .ini files parsed => /usr/local/etc/php/5.5/conf.d/ext-mcrypt.ini,
Registered Stream Filters => zlib.*, bzip2.*, convert.iconv.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk, mcrypt.*, mdecrypt.*
mcrypt
mcrypt support => enabled
mcrypt_filter support => enabled
mcrypt.algorithms_dir => no value => no value
mcrypt.modes_dir => no value => no value

for more details refer this link - http://benohead.com/mac-os-x-php-notice-use-undefined-constant-mcrypt_rijndael_128/

查看更多
别忘想泡老子
3楼-- · 2019-01-25 13:45

I just adjusted the .bash_profile in MacOS and it worked:

export PATH="/usr/local/sbin:$PATH"
PHP_AUTOCONF="/usr/local/bin/autoconf"
source ~/.bash_aliases
查看更多
迷人小祖宗
4楼-- · 2019-01-25 13:46

More simple way on ubuntu

  • apt-get install php5-mcrypt
  • mv -i /etc/php5/conf.d/mcrypt.ini /etc/php5/mods-available/
  • php5enmod mcrypt
  • service apache2 restart

Note: if you don't have "/etc/php5/conf.d" just skip that step and it will work ok

check http://php.net/manual/en/mcrypt.installation.php

查看更多
Animai°情兽
5楼-- · 2019-01-25 13:54

I also had this problem in trying to deploy a Laravel to Apache on Mac OS Sierra. I eventually found this post that gave step-by-step instructions to resolve this issue. These instructions assume that you have Homebrew installed; if you don't have it installed, then paste the following into a Terminal window to install it:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Here is the relevant steps pasted from the post given above:

Step 1: Install autoconf and mcrypt

I used homebrew to install autoconf and mcrypt, which is as easy as:

brew install autoconf mcrypt

If this does not work for you, or you don't want to use homebrew, then check out this tutorial.

Step 2: Build the PHP extension

To build the PHP extension you will need the PHP 5.4.17 source code that is available for download here and extract it:

cd ~/Downloads
unzip PHP-5.4.17.zip

Then build the extension using the following commands:

cd php-src-PHP-5.4.17/ext/mcrypt/
/usr/bin/phpize
./configure
make
sudo make install

Step 3: Enable the extension

All that is left is to enable the extension by editing /etc/php.ini. If this file is not present, copy /etc/php.ini.default and rename it:

sudo cp /etc/php.ini.default /etc/php.ini

Edit the /etc/php.ini file and add the following:

extension=mcrypt.so

Step 4: Restart apache Now just restart apache and you're done!

sudo apachectl restart

ADDITIONAL NOTES AND CLARIFICATION

I did encounter two issues with following these steps:

  1. I had to match the PHP zip file that I downloaded to the version of PHP that was installed on my machine.

So I did

php -v

to determine the version number and then changed the download to match that version number. In my case the PHP version was 5.6.28 and so I needed to download the PHP source from

https://github.com/php/php-src/archive/PHP-5.6.28.zip
  1. I got an exception at step 2 when I tried to do the sudo make install, the exception was caused by SIP, a security featured added by El Capitan. The exception is outlined in this question, and the resolution to this problem I found in this answer.

Applying the information from this answer changed the step 2 listed above and replaced the sudo make install with the following:

mkdir -p /usr/local/lib/php/extensions
sudo make EXTENSION_DIR='/usr/local/lib/php/extensions' install

Take note that because of this change, step 4 above also needs to changed to include the path to mcrypt.so. So the following must go in the php.ini:

extension=/usr/local/lib/php/extensions/mcrypt.so
查看更多
霸刀☆藐视天下
6楼-- · 2019-01-25 13:56

If you are seeing this on ubuntu or other flavors of *nix , it might help to do the following:

service php5-fpm restart
查看更多
戒情不戒烟
7楼-- · 2019-01-25 14:02

This problem relative to the PHP extensions loader. You no need to use laravel command at all after successful installation. Laravel framework need Mcrypt Library for the security module and encrypt some of configure file.

The things that you need is theses steps.

  1. Download Mcrypt http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download

then configure make and install it.

  1. Download php http://php.net/releases/index.php Above 5.5.14 are suggested. (Use this path later on step 4)

  2. then download Autoconfigure

    curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
    tar xvfz autoconf-latest.tar.gz
    cd autoconf-2.69/
    ./configure
    make
    sudo make install
    
  3. then you have to go to directory level

    cd ***YOURPHPDIRECTORY***/ext/mcrypt/
    

    and run phpize within this directory level

    /usr/bin/phpize
    ./configure
    make
    sudo make install
    
  4. modify your php.ini to enable the mcrypt extension by insert this into php.ini

    extension=mcrypt.so
    
  5. Restart web server.
查看更多
登录 后发表回答