2

I have created and set the permissions to some files and folders under /var/www/mywebsite.

For files 644 and for folders 755.

I am the owner of those files and folders, since I created them under that directory.

However, I am not able to write and save the files under /var/www/mywebsite

If I change permissions to 777 I can edit them normally but if I upload them to my server, files keep their permissions as 777 and I have to change them back to 755 and 644. This adds an extra step for total development process, and I was wondering if there is a better practice when working with a php projects and ubuntu. Should I move the web folder of apache to another directory, for example home and work from there?

Here is the output of ls -l /var/www

themhz@hal9000:~$ ls -l /var/www
total 10
drwxr-sr-x 18 themhz   root       4096 Μάι   3 05:58 mywebsite
drwsr-sr-x 18 themhz   root       4096 Οκτ  28  2013 agorasite.gr
drwsr-xr-x 17 themhz   themhz     4096 Οκτ  28  2013 agorasite
drwsr-xr-x 17 themhz   root       4096 Δεκ   9  2012 aimodosia
lrwxrwxrwx  1 root     root         22 Φεβ  14 09:25 apc.php -> /usr/share/php/apc.php
drwsr-xr-x  3 themhz   root       4096 Αύγ  30  2011 apolo
-rw-r--r--  1 themhz   root     297307 Φεβ  20  2013 background5.jpg
drwxr-sr-x  3 themhz   root       4096 Αύγ  17  2013 backups
drwsr-xr-x 10 themhz   root       4096 Ιούλ  2  2012 booking

Any advises or suggestions for best practices when developing php applications and setting up a dev working system?

My system is running Ubuntu 12.04

thank you

  • 2
    Are you sure you're the owner? What's the output of ls -l /var/www? – Louis Matthijssen May 3 '14 at 15:36
  • I get a list of all the sub directories and the directory that I am working on is drwxr-sr-x 18 themhz root. – themhz May 4 '14 at 13:49
  • Could you update your question with the output of the command? – Louis Matthijssen May 4 '14 at 13:54
1

One solution is to create the project in your home directory:

cd ~
mkdir my_project

then create a link to my_project in the webroot directory:

sudo ln –s ~/my_project /var/www/.

Now copy all project files inside my_project directory.
Finally, if apache need to write inside project, change group:

cd my_project
sudo chgrp www-data folder/to/change

You may need to run this command every time you will add files or directories.

This allows you to work in your home, without having to modify the permissions on webroot.

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.