Can't save files in /var/www using lamp installed with tasksel

20,683

If you are going to be the user maintaining the site, then make it so that your userid can edit the files.

cd /var/www && sudo chown -R `whoami`:`whoami` .

If you do this, then you will be able to modify the files under /var/www because the files will belong to you and your personal group. The -R runs the command recursively - it runs on the current file (the directory) and all the files in and under the directory (included the hidden files)

If you have not run a sudo command recently (a few minutes), it will ask you for your personal password.

It is also possible to set up groups and all that. However, this is the simplest way.

Make sure that the files are readable by the web server. If this is a problem, then - because you own the files now you can use chmod command:

cd /var/www && chmod -R o+r .

If this does not make the directories executable, you may want to also do:

find /var/www -type d -print0 | xargs -0 chmod o+x

This will (find) collect the list of directory names and pass them on (as a null delimited list) to xargs, which will execute the chmod to make the directories executable.

As reported at related: Whats the simplest way to edit and add files to "/var/www"?, – Desmond Hume Nov 12 '12 at 14:42 suggested to @DonFaulkner

For security reasons, it's probably better keep /var/www owned by root:root, so instead of sudo chgrp -R www-data /var/www it better be sudo chgrp -R www-data /var/www/*

Share:
20,683

Related videos on Youtube

Nikos Grigoriadis
Author by

Nikos Grigoriadis

Web Developer | Digital Marketer Github : github.com/grrnikos

Updated on September 18, 2022

Comments

  • Nikos Grigoriadis
    Nikos Grigoriadis over 1 year

    I just installed lamp with tasksel and it works. But

    1. inside /var/www I can create files only with sudo from terminal, I don't know why. In another Ubuntu installation I didn't have such problem.
    2. I created a file named index.php and I can't even save it.

    That's the error I get from Sublime Text:

    Unable to save /var/www/index.php
    Error: unable to create tmp file in /var/www
    

    And that's from Geany:

    Error opening file '/var/www/index.php': Permission denied
    The file on disk may now be truncated!
    
  • Nikos Grigoriadis
    Nikos Grigoriadis over 10 years
    Like a boss. Do you know why I had to do this?
  • ElderDelp
    ElderDelp over 10 years
    I'm not sure which installer you used before and this time, but as an alternate answer, to amplify the group suggestion, you can look at: Whats the simplest way to edit and add files to “/var/www”