Posted on 2019/03/10 at 12:13 am
So, setting up a server gets pretty easy after a while especially when using them for local projects or LAN servers. Yet, running on port 80 is awkward when not as root user. Let's fix that.
acc
OK, this whole process revolves around an awesome program called authbind. Let's install it by doing the following:
sudo apt-get install authbind
Once installed, we need to do some setup work. (Don't worry, it's very easy.) Do the following:
sudo touch /etc/authbind/byport/80
sudo chmod 500 /etc/authbind/byport/80
sudo chown <yourUserOrGroupName> /etc/authbind/byport/80
What we are doing here is creating a file called "80" in the "byport" folder which resides in the /etc/authadmin/ directory. The "byport" directory is one of three folders in authadmin's "config zone". We then change the permission values of the file to only allow read and execute functions for just the user. After that, we make sure it's owned by the user/group that will be running the server.
OK, we are setup and ready to test. At this point, it becomes a question of how you run your server. But, here is how we run on port 80 with PHP's built-in server software without sudo privileges. We of course setup an index.php somewhere representing our site. We then run the following in a terminal in the directory of our site/app:
authadmin php -S 0.0.0.0:80
We then open up 0.0.0.0 in a tab of our favorite browser and vualá! We're in business! No sudo needed. No weird permission escalations. Just preceding any server start command with authbind.