Folder permissions on ubuntu

0

Hi, I have an installation with ubuntu where I'm going to use apache as a web server.

For this I have created a folder in / var / www / html / tests Where I created a series of files for example "index.php"

The problem I have is that if I do not create the file with the command "sudo nano file.php" the editor will not let me create or edit files.

The user I use is "edu", and what I have tried has been to put the permissions of the files inside the folder tests with the permissions 777 and the user and group to www-data with this command

sudo chown www-data: www-data -R *

This is useful for the files I have created, but for those who "go" creating this, it does not work for me because I must pass this command every time.

The solution which would be to put the folder / var / www / html that belongs to the user "edu"?

Thanks

    
asked by ilernet 17.11.2017 в 17:02
source

4 answers

1

Create a new directory for your project at the Apache root (or wherever you want if you are going to create a virtual site). In my case I have created a testsite folder within apache:

sudo mkdir /var/www/html/testsite

Change the owner by www-data:

sudo chown www-data /var/www/html/testsite/

Change the user group in the directory:

sudo chgrp www-data /var/www/html/testsite/

Set the appropriate permissions (read, write and execute for user and group, read only and run for the rest):

sudo chmod ug+w /var/www/html/testsite/

Assign the "sticky bit" for the group (so that the files and directories that are created drag the property of the www-data group):

sudo chmod g+s /var/www/html/testsite/

Assign the default permissions (so that the directories that are created drag the same permissions):

sudo setfacl -d -m g::rwx /var/www/html/testsite/

Now add as many users as you need to access on your web server (in my case the user victor ):

sudo usermod -a -G www-data victor 
    
answered by 17.11.2017 в 20:14
1

For development purposes, I suggest the following commands:

cd /var/www/html
sudo chown -R tu_usuario:www-data .
sudo chmod -R 2755 .

With these commands, you are allowed to copy, create, modify and delete directories and files within '/ var / www / html' or the vhosts directory you want.

To put a server into production, it's another story.

    
answered by 20.09.2018 в 05:32
0

You could configure apache to run with your user instead of www-data however it poses a security risk and I would not recommend it.

To change the user search in this file: /etc/apache2/envvars and search export APACHE_RUN_USER=www-data export APACHE_RUN_GROUP=www-data

to replace www-data with edu

    
answered by 17.11.2017 в 19:43
0

The best thing in this case would be to use PHP-FPM that allows you to run a Apache domain under a user, making the entire folder belong to that user and eliminating errors derived from usuario:grupo .

This way you have a Pool of FPM for each configured user, so that Apache executes those files through FPM (in proxy or .lock ) and there are no problems of permissions.

You can see how it is configured here: link

You have it step by step and you will see that it is very easy and that it takes away from many problems.

    
answered by 21.11.2017 в 10:15