After two days of research I have discovered how to give permissions and I leave here the tutorial for those who are newbies like me and cannot find a way out.
- Just to state the obvious for anyone viewing this discussion… if you give any of your folders 777 permissions, you are allowing ANYONE to read, write and execute any file in that directory… what this means is you have given ANYONE (any hacker or malicious person in the entire world) permission to upload ANY file, virus or any other file, and THEN execute that file…
IF YOU ARE SETTING YOUR FOLDER PERMISSIONS TO 777 YOU HAVE OPENED YOUR SERVER TO ANYONE THAT CAN FIND THAT DIRECTORY. Clear enough???
There are basically two ways to setup your ownership and permissions. Either you give yourself ownership or you make the webserver the owner of all files.
1- First way
Webserver as owner (the way most people do it, and the Laravel doc’s way):
assuming www-data (it could be something else) is your webserver user.
sudo chown -R www-data:www-data /home/ *your_username* /web/ *your_domain* /public_html
if you do that, the webserver owns all the files, and is also the group, and you will have some problems uploading files or working with files via FTP, because your FTP client will be logged in as you, not your webserver, so add your user to the webserver user group:
sudo usermod -a -G www-data ubuntu
Of course, this assumes your webserver is running as www-data (the Homestead default), and your user is ubuntu (it’s vagrant if you are using Homestead).
Then you set all your directories to 755 and your files to 644… SET file permissions
sudo find /home/ *your_username* /web/ *your_domain* /public_html -type f -exec chmod 644 {} \;
SET directory permissions
sudo find /home/ *your_username* /web/ *your_domain* /public_html -type d -exec chmod 755 {} \;
then in panel hestia settings, restart server with that everything will be resolved
2- Second way
this is the one I preferred to use
Your user as owner
I prefer to own all the directories and files (it makes working with everything much easier), so I do:
sudo chown -R my-user:www-data /home/ *your_username* /web/ *your_domain* /public_html
Then I give both myself and the webserver permissions:
sudo find /home/ *your_username* /web/ *your_domain* /public_html -type f -exec chmod 664 {} \;
sudo find /home/ *your_username* /web/ *your_domain* /public_html -type d -exec chmod 775 {} \;
then in panel hestia settings, restart server with that everything will be resolved
With this we say goodbye to the permission problem that frustrates us so much and takes away our sleep