Authenticate using OS (Ubuntu) username and password


I’m wondering if there’s a way to integrate Yii2 authentication with the operating system (mainly Ubuntu) so the users are authenticated and can login using their Ubuntu username and password.

I’ve done some research and can see PHP had a module (now deprecated) called PHP PAM but being deprecated, it may not be a good option.

The other option I’m thinking is to do the authentication on the web server level (in this case Apache2) and not the web application itself, but again not having done this in the past has made me reach out to the experts on this forum.

The web application I’m working on will not have many users and the intention is to not have application level users but be able to login with the OS user and also perform OS level tasks (and run OS level commands) and display the results.

Any advice is greatly appreciated.

Thank you.



Then don’t do any user management in Yii and use Apache (or other) functionality instead.

Maybe. :)

My point is: if the OS already have user management, and you want to use that, use that.

Thank you Jacmoe for your prompt response.

The only issue I see with the Apache functionality though is the fact that it’s not very user friendly (because of browser popup), in the sense that it defeats the purpose of having a modern looking web application, so I was wondering whether there’s a way to bypass the browser’s popup and have a nice looking login form, but instead of authenticating against a database, still make use of the basic authentication of Apache and maybe use cookies or some sort of javascript / jQuery / other scripts to handle it?

Also, other than the PHP system() function, are you familiar with any other methods to invoke OS (Ubuntu) level commands?

Thank you.



I haven’t done this, but I think that you could try this Yii2 Extension:

skeeks-semenov / yii2-http-basic-auth