How to set up file permissions for Laravel?

0 votes

Does it mean that the web server needs access to the storage and vendor folders themselves too or just their current contents?

I assume that what is much better, is changing the owner instead of permissions. I changed all Laravel's files permissions recursively to _www:_www and that made the site work correctly, as if I changed chmod to 777. The problem is that now my text editor asks me for password each time I want to save any file and the same happens if I try to change anything in Finder, like for example copy a file.

What is the correct approach to solve these problems?

  1. Change chmod
  2. Change the owner of the files to match those of the web server and perhaps set the text editor (and Finder?) to skip asking for password, or make them use sudo
  3. Or something else.
Apr 20 in PHP by kartik
• 26,540 points
380 views

1 answer to this question.

+1 vote

Hello @kartik,

The permissions for the storage and vendor folders should stay at 775, for obvious security reasons.

However, both your computer and your server Apache need to be able to write in these folders. Ex: when you run commands like php artisan, your computer needs to write in the logs file in storage.

All you need to do is to give ownership of the folders to Apache :

sudo chown -R www-data:www-data /path/to/your/project/vendor
sudo chown -R www-data:www-data /path/to/your/project/storage

Then you need to add your computer (referenced by it's username) to the group to which the server Apache belongs. Like so :

sudo usermod -a -G www-data userName

NOTE: Most frequently, groupName is www-data but in your case, replace it with _www

Thank You!

answered Apr 20 by I Navin
• 220 points

Related Questions In PHP

0 votes
1 answer

How to grant remote access permissions to mysql server for user?

Hello @kartik, This grants root access with the ...READ MORE

answered Aug 26 in PHP by Niroj
• 57,260 points
43 views
0 votes
0 answers
0 votes
1 answer

How do I let PHP to create subdomain automatically for each user?

Hello @kartik, We setup wildcard DNS like they ...READ MORE

answered Apr 20 in PHP by Niroj
• 57,260 points
397 views
0 votes
1 answer

How to find the php.ini file from the command line?

Hello @kartik, You can get a full phpinfo() using : php ...READ MORE

answered May 19 in PHP by Niroj
• 57,260 points
202 views
0 votes
1 answer

Error:Cannot insert explicit value for identity column in table 'table' when IDENTITY_INSERT is set to OFF.

Hello @kartik, You're inserting values for OperationId that is an identity ...READ MORE

answered Jul 21 in PHP by Niroj
• 57,260 points
271 views
+1 vote
1 answer

How to make anchor tag with routing using Laravel?

Hey @kartik, First you have to go to ...READ MORE

answered Mar 18 in Laravel by Niroj
• 57,260 points
2,090 views
0 votes
1 answer

What is redirection in Laravel?

Named route is used to give specific ...READ MORE

answered Mar 18 in Laravel by Niroj
• 57,260 points
218 views
0 votes
1 answer

How to install Laravel via composer?

Hello, This is simple you just need to ...READ MORE

answered Mar 23 in Laravel by Niroj
• 57,260 points
181 views
+1 vote
1 answer

What are named routes in Laravel and How can specify route names for controller actions?

Hey @kartik, Named routing is another amazing feature of ...READ MORE

answered Mar 23 in Laravel by Niroj
• 57,260 points
2,490 views
0 votes
1 answer

How to resolve “must be an instance of string, string given” prior to PHP 7?

Hello, Prior to PHP 7 type hinting can only be ...READ MORE

answered Apr 20 in PHP by I Navin
• 220 points
360 views