0

I just installed LAMP server, which works fine. But when I code a PHP script and try to save it in /var/www/html, it says:

You don't have permisission necessary to save the file

Help me! How do I fix this problem?

enter image description here

anonymous2
  • 4,298
  • You don't have permission to save a file in a directory that belongs to Apache, it is that simple. The easiest thing would be to create a directory, let's say "webstuff", in your home directory, then move everything from /var/www/html to it, and create (as root) a symbolic link from /var/www/html to the webstuff directory. – Jos Jun 22 '16 at 13:44

1 Answers1

4

Three quick steps

Add your user to the www-data group

sudo usermod -a -G www-data username

Change the owner of /var/www

sudo chown -R username:www-data /var/www

Change the permissions recursively on /var/www

sudo chmod -R 644 /var/www

NB: Replace username in the commands with your username.

anonymous2
  • 4,298
  • 1
    If the user already exists (which I think is correct in this case) you want to use usermod -a -G www-data username – Reuben Swartz Jun 22 '16 at 13:49
  • Thanks for the clarification, @ReubenSwartz. You're right. I'll edit the post. – anonymous2 Jun 22 '16 at 13:50
  • This will work but I would argue that editing files directly on /var/www/html/ is asking for problems. I would use a directory in /home/ to edit the pages. And have a cron job create a backup and copy the edits over when put into a "synch" directory in the same /home. – Rinzwind Jun 22 '16 at 13:56
  • Sure, that's valid, @Rinzwind, and I agree. My attempt was just to make a simple solution that was fine for the average user. Until recently, I always edited my files straight in /var/www (and no I didn't switch because I had issues. :) ) – anonymous2 Jun 22 '16 at 14:02
  • chmod -R 755? What's the need to make all those files executable? – muru Jun 22 '16 at 15:03
  • Hmm, good point again. I do it that way since I fairly frequently have scripts inside /var/www, but it's true that a 644 would be sufficient for the average user. – anonymous2 Jun 22 '16 at 15:07
  • Thank you guys! I fixed this problem.But,End up with another one. http://askubuntu.com/questions/790473/php-scripts-doesnt-executed – margherita pizza Jun 23 '16 at 04:13