I have installed LAMP as:

sudo apt-get update 
sudo apt-get upgrade
sudo apt-get install lamp-server^

If I understand correctly, apache server will be running with sudo privileges? If yes, for a php script to be able to write in its own directory does it only require RWX for root user?

It doesn't work for me. I have to give 777 privileges to the directory and the script for it write a new file into the particular directory. I do not understand, how is it functioning. Why cannot the apache, that is running as root able to write when 2775 have been set up earlier?

I had earlier given permissions as : (using shell commands)

groupadd www;
usermod -a -G www $(whoami);
adduser $(whoami) sudo;
DocumentRoot=$(grep "DocumentRoot"  $default_conf_file);
chown -R root:www $DocumentRoot;
chmod 2775 $DocumentRoot;
find $DocumentRoot -type d -exec sudo chmod 2775 {} \;
find $DocumentRoot -type f -exec sudo chmod 0664 {} \;
  • Note that Apache workers never run as 'root' or super user unless explicitly configured to (and that's a dangerous configuration). The master process may run as root but all workers which actually access web files and write to disk on behalf of web applications run as www-data in a default installation. – Thomas Ward Mar 21 '16 at 13:31
  • @ThomasW. I have added the shell commands I run after installing lamp – Suhail Gupta Mar 21 '16 at 13:34
  • @ThomasW. How to give worker threads the write permission? – Suhail Gupta Mar 21 '16 at 13:38

you need to add "www-data" user into your newly created group "www" using (gpasswd -a www-data www)

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.