I'd like to be able to run PHP scripts without needing to use sudo in every command. My user is not root obviously. How can I accomplish this feat? I'm new to Linux, and I have a little knowledge of permissions, but assume I don't.

I thought PHP scripts would be sent to the background and run under a different user that does have root permissions, and the user kicking those scripts off wouldn't need to have the same access. In any case, the PHP scripts will need database read/write access, will need to be able to read/write files, will need access to start/stop the apache web server, and any other task that a typical PHP script does.

If I'm scheduling these scripts with anacron, do I need to do anything differently?

  • why don't you want to use sudo? to avoid entering a password? also, php scripts don't usually handle starting/stopping the web server, unless you're using php as a general scripting language the way other people would use bash or Python. – roadmr Mar 12 '12 at 20:08
  • FYI, you can also configure sudo to allow a particular user to perform a certain action without a password. – Chev_603 Sep 24 '15 at 22:23

Your script, php, python, bash, perl, or otherwise has to run as a user with privileges to access the files and services you are managing.

Since some of the tasks you mention require root access (start/stop apache), you will have to run it as root (with sudo). Schedule your scripts to be run as root (from root's anacron)

A more common user case is to run php in a web server (LAMP). In that event, normally one would have /var/www owned by the apache user (www-data), or at least any files php needs to modify. php scripts are then called by apache, and run as www-data and have access to files in /var/www. Just take care, unless you harden php the scripts have access outside of /var/www

The following links may be helpful



| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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