简体   繁体   English

使用未定义的常量 MCRYPT_RIJNDAEL_128 - 假设为 'MCRYPT_RIJNDAEL_128'

[英]Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'

I have successfully installed Laravel, but after running php artisan serve and going to localhost:8000 I get this error:我已成功安装 Laravel,但在运行php artisan serve并转到localhost:8000此错误:

Use of undefined constant MCRYPT_RIJNDAEL_128 - assumed 'MCRYPT_RIJNDAEL_128'使用未定义的常量 MCRYPT_RIJNDAEL_128 - 假设为 'MCRYPT_RIJNDAEL_128'

I have checked phpinfo() on localhost:8888 and it says that mcrypt is properly installed.我已经在localhost:8888上检查了phpinfo() ,它说mcrypt已正确安装。 However the only thing I can think of is that maybe my path is wrong?但是我唯一能想到的是,也许我的路径是错误的?

in my .bash_profile I have在我的.bash_profile我有

PATH=/usr/local/bin:$PATH

Every time I try to run Laravel commands I have to type this in the terminal:每次我尝试运行 Laravel 命令时,我都必须在终端中输入:

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

I am running on a Mac.我在 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?有没有一种简单的方法可以设置我的bash_profile以便我可以在本地主机地址之间始终如一地进行更改,并且仍然可以使所有正确的 PHP 函数正常工作?

More simple way on ubuntu 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注意:如果您没有“/etc/php5/conf.d”,请跳过该步骤,它会正常工作

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

This problem relative to the PHP extensions loader.这个问题与 PHP 扩展加载器有关。 You no need to use laravel command at all after successful installation.安装成功后根本不需要使用 laravel 命令。 Laravel framework need Mcrypt Library for the security module and encrypt some of configure file. Laravel 框架需要 Mcrypt 库作为安全模块并加密一些配置文件。

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下载 Mcrypt http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download

then configure make and install it.然后配置make并安装它。

  1. Download php http://php.net/releases/index.php Above 5.5.14 are suggested.下载 php http://php.net/releases/index.php建议 5.5.14 以上。 (Use this path later on step 4) (稍后在步骤 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并在此目录级别内运行 phpize

     /usr/bin/phpize ./configure make sudo make install
  4. modify your php.ini to enable the mcrypt extension by insert this into php.ini通过将其插入 php.ini 来修改您的 php.ini 以启用 mcrypt 扩展

    extension=mcrypt.so
  5. Restart web server.重新启动网络服务器。

For Mac users's specially - install it using Home Brew Mac 用户专用 - 使用Home Brew安装

I've installed an empty Laravel installation and got the following error message when navigating to http://localhost/kanban/public/ :我已经安装了一个空的 Laravel 安装,并在导航到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注意:使用未定义的常量 MCRYPT_RIJNDAEL_128 – 假设 '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).谷歌搜索此错误消息会返回许多有关如何在 Mac OS X 上安装 mcrypt 的教程(无论是从源代码构建还是使用 Homebrew)。 The problem was that both the mcrypt and the php55-mcrypt packages were properly installed:问题是 mcrypt 和 php55-mcrypt 包都已正确安装:

$ 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: Mcrypt 也被 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/有关更多详细信息,请参阅此链接 - http://benohead.com/mac-os-x-php-notice-use-undefined-constant-mcrypt_rijndael_128/

如果您在 ubuntu 或其他版本的 *nix 上看到此内容,执行以下操作可能会有所帮助:

service php5-fpm restart

I use nginx and php-fpm, and already did apt-get install php5-mcrypt , and moved the mcrypt.ini file to mods-available .我使用 nginx 和 php-fpm,并且已经做了apt-get install php5-mcrypt ,并将mcrypt.ini文件移动到mods-available

I had to do sudo service php5-fpm restart before it actually worked.在它实际工作之前,我必须执行sudo service php5-fpm restart

I just adjusted the .bash_profile in MacOS and it worked:我刚刚在 MacOS 中调整了.bash_profile并且它起作用了:

export PATH="/usr/local/sbin:$PATH"
PHP_AUTOCONF="/usr/local/bin/autoconf"
source ~/.bash_aliases

I also had this problem in trying to deploy a Laravel to Apache on Mac OS Sierra .我在尝试将Laravel部署到Mac OS Sierra上的Apache时也遇到了这个问题。 I eventually found this post that gave step-by-step instructions to resolve this issue.我最终找到了这篇文章,其中给出了解决此问题的分步说明。 These instructions assume that you have Homebrew installed;这些说明假设您已安装Homebrew 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第 1 步:安装 autoconf 和 mcrypt

I used homebrew to install autoconf and mcrypt, which is as easy as:我用 homebrew 安装了 autoconf 和 mcrypt,这很简单:

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第 2 步:构建 PHP 扩展

To build the PHP extension you will need the PHP 5.4.17 source code that is available for download here and extract it:要构建 PHP 扩展,您需要 PHP 5.4.17 源代码,可在此处下载并解压缩:

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第 3 步:启用扩展

All that is left is to enable the extension by editing /etc/php.ini.剩下的就是通过编辑 /etc/php.ini 来启用扩展。 If this file is not present, copy /etc/php.ini.default and rename it:如果此文件不存在,请复制 /etc/php.ini.default 并将其重命名:

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

Edit the /etc/php.ini file and add the following:编辑 /etc/php.ini 文件并添加以下内容:

extension=mcrypt.so

Step 4: Restart apache Now just restart apache and you're done!第 4 步:重启 apache现在只需重启 apache 就大功告成了!

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.我必须将下载的PHP zip 文件与安装在我的机器上的 PHP 版本相匹配。

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在我的例子中, PHP版本是 5.6.28,所以我需要从

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 .当我尝试执行sudo make install ,在第 2 步出现异常,该异常是由 SIP 引起的,这是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:应用此答案中的信息更改了上面列出的第 2 步,并将sudo make install替换为以下内容:

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 .请注意,由于此更改,上面的第 4 步也需要更改以包含mcrypt.so的路径。 So the following must go in the php.ini :所以以下必须在php.ini

extension=/usr/local/lib/php/extensions/mcrypt.so

此处有详细说明https://www.php.net/manual/en/install.pecl.windows.php确保选择合适的扩展版本作为 PHP 版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM