Я перекомпилировал весь php. Если потребность некоторое учебное руководство http://docs.moodle.org/en/Development:Install_Moodle_On_Ubuntu_with_Nginx/PHP-fpm
It seemed that I was missing something fundamental. After messing up my whole PAM and NSS configuration by hand, I reinstalled the machine (it was a fresh install before my messing). After installing all the necessary packages I did before, running one single magic command by hand did the trick:
pam-auth-update
As soon as I get back to that machine tomorrow, I will post the resulting pam.d files.