I have bought https://shop.pimoroni.com/products/pan-tilt-hat , it works fine, but I want to control it through a php webserver, but every time I try, it requires sudo but when I use sudo I get an error in /var/log/apache2/error.log

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

sudo: no tty present and no askpass program specified

Another question could be: How do I avoid having to use sudo with the pan tilt hat library


2 Answers 2


Give the apache user permissions to run sudo commands without password. Assuming the user in question is called www-data, add the following line to your sudoers file:


Once you get that working, you can restrict commands which could be run without password to hat-related only, so if your web server gets hacked, the attacker will not be able to run random commands as root.


the PanTiltHAT library doesn't require sudo. It requires membership of the i2c group, so all I needed to do to achieve a similar end result (control of PanTiltHAT mounted camera from a web UI) was to add the www-data user to the i2c group in the OS. A Linux command for that is

sudo gpasswd -a www-data i2c

Although, I was using a flask (not PHP) based web application, so I could very easily integrate calls through the python interface library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.