简体   繁体   English

在启用 Argon2 的 Amazon Linux 2 上安装 PHP

[英]Installing PHP on Amazon Linux 2 with Argon2 Enabled

I am having a problem with enabling Argon2 for password hashing.我在为密码散列启用 Argon2 时遇到问题。 I am building PHP from source of Amazon Linux 2 but once the build have finishing and PHP is compiled, the PASSWORD_ARGON2I constant is undefined and the algorithm is not available.我正在从 Amazon Linux 2 的源代码构建 PHP,但是一旦构建完成并编译了 PHP, PASSWORD_ARGON2I常量未定义并且算法不可用。

I have tried numerous different ways to compile PHP using different libraries but none of them give me the Argon2 algorithm that I need.我尝试了多种不同的方法来使用不同的库编译 PHP,但没有一种方法能提供我需要的 Argon2 算法。 Below I will list some steps I have taken:下面我将列出我采取的一些步骤:

1) Giving flag --with-sodium 1) 给标志--with-sodium

Compiling with this flag completes, but running a test script that includes the function password_hash() shows that Argon2I is not available.使用此标志编译完成,但运行包含函数password_hash()的测试脚本显示 Argon2I 不可用。

2) Compiling with flag --with-password-argon2 2) 编译标志--with-password-argon2

This fails to compile due to a missing library which can be seen in the error below.由于缺少库,编译失败,可以在下面的错误中看到。

checking for Argon2 support... yes
checking for Argon2 library... not found
configure: error: Please ensure the argon2 header and library are installed

From this, I assume that I am missing a library required for the flag to work so I have installed Libsodium .由此,我假设我缺少该标志工作所需的库,因此我安装了Libsodium Trying again has the same result.再次尝试具有相同的结果。

3) Next I install some more dependencies on the recommendation from a tutorial. 3) 接下来,我根据教程的推荐安装更多依赖项。 These are: - argon2 - libargon2-0 - libargon2-0-dev它们是: - argon2 - libargon2-0 - libargon2-0-dev

This does give me the cli tool argon2 which works, however compiling PHP again doesn't work with the same errors.这确实为我提供了可以工作的 cli 工具argon2 ,但是再次编译 PHP 不会出现相同的错误。

At the point Im not sure what my next step is, any help would be greatly appreciated.目前我不确定我的下一步是什么,任何帮助将不胜感激。

I received an Argon2i not supported.. error when trying to install the LexikJWTAuthenticationBundle on my Cloud9 EC2 instance where PHP72 is running.我在运行 PHP72 的 Cloud9 EC2 实例上尝试安装 LexikJWTAuthenticationBundle 时收到Argon2i not supported..错误。 After much research I came up with a solution.经过大量研究,我想出了一个解决方案。

Here are the steps to follow.以下是要遵循的步骤。

Install libsodium:安装 libsodium:

$ sudo yum install libsodium-devel

After it is installed, if you run this command to view your PHP modules, you would expect to see libsodium listed, but it is not there.安装后,如果您运行此命令来查看您的 PHP 模块,您会期望看到列出的 libsodium,但它不在那里。

$ php -m 

The package is actually installed as sodium.so and not libsodium.so (perhaps that is the root of the problem?) To get PHP to load the module, some manual steps are required.该包实际上安装为 sodium.so 而不是 libsodium.so(也许这是问题的根源?)要让 PHP 加载模块,需要一些手动步骤。

Go to the directory that PHP looks for installed modules.转到 PHP 查找已安装模块的目录。

$ cd /etc/php.d

Create a file that will point to the sodium.so package.创建一个指向 sodium.so 包的文件。

$ sudo touch libsodium.ini

Give the file read/write permissions.授予文件读/写权限。

$ sudo chmod 666 20-libsodium.ini

Open the file in an editor.在编辑器中打开文件。 I like to use vim.我喜欢用 vim。

$ vi libsodium.ini

Click the 'i' key to get into the insert mode and paste the following:单击“i”键进入插入模式并粘贴以下内容:

; Enable sodium extension module
extension=sodium.so

Save the file by clicking the escape key and typing:通过单击转义键并键入以下内容来保存文件:

:wq!

Now if you look at the installed PHP modules by typing php -m, you will see libsodium listed.现在,如果您通过键入 php -m 查看已安装的 PHP 模块,您将看到列出了 libsodium。

At this point you should be able to run whatever was throwing the Argon2i errors.在这一点上,您应该能够运行任何引发 Argon2i 错误的东西。

FYI, I am not a PHP developer, nor an AWS expert, but I had to get this working to deploy a company PHP application on EC2.仅供参考,我不是 PHP 开发人员,也不是 AWS 专家,但我必须让它工作才能在 EC2 上部署公司 PHP 应用程序。 So if you have any issues with the above, I may not be able to help..but I'll try;)因此,如果您对上述内容有任何疑问,我可能无法提供帮助……但我会尽力;)

I was able to resolve this issue.我能够解决这个问题。 I created a new AWS Amazon Linux 2 instance and followed these steps:我创建了一个新的 AWS Amazon Linux 2 实例并执行了以下步骤:

Install Argon2安装 Argon2

sudo -s
git clone https://github.com/P-H-C/phc-winner-argon2.git
cd phc-winner-argon2
make
make test
make install PREFIX=/usr
cp /usr/lib/libargon2.so.1 /lib64/

Navigate back to the parent directory导航回父目录

cd ..

Install PHP 7.3.5安装 PHP 7.3.5

wget https://www.php.net/distributions/php-7.3.5.tar.gz
tar -zxvf php-7.3.5.tar.gz
cd php-7.3.5
./configure --with-password-argon2
make 
make test
make install
exit

Navigate back to the parent directory导航回父目录

cd ..

Check your PHP version检查您的 PHP 版本

php --version

Create the following PHP script (pwd.php).创建以下 PHP 脚本 (pwd.php)。

<?php

  error_reporting(E_ALL);

  $hash = \password_hash('password', PASSWORD_ARGON2ID);
  echo "$hash\n";

?>

Execute the PHP script to test Argon2 functionality执行 PHP 脚本以测试 Argon2 功能

php pwd.php

You will receive an output similiar to the following:您将收到类似于以下内容的输出:

$argon2id$v=19$m=1024,t=2,p=2$dlB2SWdpUEFYZE9RSWNmQg$JGWNTXEomWX1hyM8OfzkRNx5C3zmBu3sqKU1hwohNOU

sudo yum install -y libargon2 libargon2-devel

This worked for me.这对我有用。

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

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