Skip to content
Advertisement

How to compile PHP using –with-password-argon2?

I try to use PHP’s password_hash() function with the PASSWORD_ARGON2I algorithm, however, I get the following error message:

Warning: Use of undefined constant PASSWORD_ARGON2I – assumed ‘PASSWORD_ARGON2I’ (this will throw an Error in a future
version of PHP) in some-file.php on line 181

Warning: password_hash() expects parameter 2 to be integer, string given in some-file.php on line 192

Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column ‘password’ cannot be null
in some-file.php:232
Stack trace:
#0 some-file.php(232): PDOStatement->execute()
#1 {main}
thrown in some-file.php on line 232

I followed the official documentation of the function word by word, but I still faced this error.

Then I made some research and I figured out that “PHP should be compiled using –with-password-argon2 (where they refer to this file).

I have no idea how to do this and I could not find any page which would guide me through the steps or provide me more info.

The hashing function works perfectly with PASSWORD_DEFAULT, but that is not what I need at the moment.

Advertisement

Answer

I did not know but OSX comes with pre-installed PHP. I had a very early version so I needed to upgrade it in order to make Argon2 algorithm work. When I checked my version by php --version in the command line, I got the following result:

PHP 5.6.30 (cli) (built: Oct 29 2017 20:30:32)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

So I followed through this guide but I also had to install Argon2 library (which was not mentioned) and use ./configure —with-password-argon2. So here are the steps which solved my problem based on this guide:

  1. Download the latest PHP source code f.e. from here (I used this .GZ file, but make some research whether there is a newer version or not)
  2. Open the command line
  3. Extract the GZ file and navigate to the extracted source code folder in the command line
  4. You will need Homebrew, install it if you don’t have it
  5. Install the dependencies listed in this guide (run brew install libjpeg, brew install pcre, brew install libxml2, etc. in the command line)
  6. Also install Argon2 library (this is not mentioned in the previous guide, you can use this guide)
  7. Now run this in the command line (still same source code folder): ./configure —with-password-argon2
  8. run make test in the command line (time-consuming process, feel free to drink a beer meanwhile)
  9. run sudo make install after
  10. I also restarted my computer, not sure if it was necessary but it worked
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement