Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer

up vote 1 down vote accepted

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

https://help.ubuntu.com/community/FilePermissions

https://help.ubuntu.com/community/RootSudo

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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