Undoing erroneous chmod - linux

Am working in Django and was trying to serve media files and was encountering an error with accessing the system folder serving media files. Being (much) less familiar with terminal-related commands, I searched SO for a solution. I ended up executing the "good" code in this SO answer. This part, specifically:
sudo groupadd varwwwusers
sudo adduser www-data varwwwusers
sudo chgrp -R varwwwusers /var/www/
sudo chmod -R 770 /var/www/
This somehow messed up my whole system. I can't even start gunicorn now, I'm getting OSError: [Errno 13] Permission denied: '/apps/djangoProjectFolder' in my terminal output when I try to do so.
I'm basically clueless at this point. Would like to learn what I did wrong, and how I can undo this situation.

Thanks for the comment. I ended up doing a clean reinstall of Unbuntu. All fixed now! Just that it was really laborious to manually transfer all my existing files since wholesale copy+pasting didn't work (seemed like the erroneous permissions got copied over too).

Related

Change ownership of linux directory

Hi I'm very new to Linux..
Once I have changed ownership of /usr my sudo command failed working ..
Once I changed ownership of /var some other things broke ..
1: I just want to know which are folders where one should never change it's default ownership..
2: what if someone gets permission_denied for /var during installing some packages .. chmod or chown should be used ...
I would never change the ownership in folders unlike /home/* /opt/. Sometimes you have to change the owner if you put your own stuff to /etc/, but you should now what to do.
To install software, even in Ubuntu use the provided tools, 'apt' and 'dpkg' for example. Often the installation needs root rights. Give them with the usage of and additional 'sudo'.
# f.e. installation of a command line browser
sudo apt install w3m

Laravel folder permission for not-yet made cache folders

I'm having an issue with directory permissions with Laravel when it comes to caching. Whenever it tries to upload a cache file to /var/www/laravel/storage/framework/cache/data/ it tells me that file_put_contents has no permissions.
To fix this I always do something like chmod -R 755 /var/www/laravel/storage/framework/cache/ but the problem here is that when it creates a new directory inside cache it does not inherit these chmod settings, thus giving me permission denied error again.
How can this be fixed permanently?
Edit:
Been thinking about letting it run as a cronjob regularly, but I'm not so sure that's a good way to deal with it.
You need to run chmod command with -R:
sudo chmod -R 755 storage
After installing Laravel, you may need to configure some permissions. Directories within the storage and the bootstrap/cache directories should be writable by your web server or Laravel will not run. If you are using the Homestead virtual machine, these permissions should already be set.
https://laravel.com/docs/5.5#installation

Symfony permission denied

Can anyone help me fix the below error message I'm getting? I've finally got Symfony installed on a VM and it seems to be working ok except for the fact that I'm getting occasional messages for things like this:
[1/2] ContextErrorException: Warning: SessionHandler::read(): open(/var/lib/php5/sess_d8qgvn11jdu8rfuo1f0njokc67, O_RDWR) failed: Permission denied (13)
From what I've picked up from reading around, I'm thinking it's because I have a mismatch between the owner/permissions between linux and the webserver but I don't know how this would happen (I'm just taking this as fact and I don't really understand how/why to prevent making the same mistakes in the future).
Each time I've been getting one of these errors I'm submitting a mix of the below commands to try and fix the problem but I'm guessing it's not the right way to go about it (text in brackets is my understanding/guessing of what they do):
sudo chmod a+x <path>
Modifies the permissions of the directory
sudo chmod -R 775 <path>
Similar to previous except that it SETS the permissions -R applies it recursively
sudo chown -R <usr>:www-data <path>
Changes the owner/group of the directory/file
You can take a look at http://symfony.com/doc/current/book/installation.html on "Setting up Permissions" section. It talks about app/logs and app/cache, but you can do the same on any other folder you need
In Symfony3, I had this error after installing symfony in a new fresh VPS, I resolved it using the already noted : chmod -R 775 for the LOG and CACHE but now for the SESSIONS folder.
chmod -R 775 var/sessions
Similar symfony permissions issue this worked for me:
sudo chown <yourcliusername> /var/lib/php5
Source: https://stackoverflow.com/a/33991320/1438029
Duplicated answer from https://stackoverflow.com/a/39346877/4276533
You can set path for sessions manually. See Symfony doc on sessions directory.
# app/config/config.yml
framework:
session:
handler_id: session.handler.native_file
save_path: '%kernel.root_dir%/sessions'

Linux Mint make Kohana's logs and cache writable

I can't properly install kohana on my mint distro, because the cache and logs aren't writable. I've tried chmod 777 cache and same for logs, but it just won't change. chmod a+w didn't help either.
Any solutions?
It might be possible that you already had some logs which permissions did not change with chmod. I would recommend that you try a recursive chmod with chmod -R 777 cache. Also, though I am certain that you already checked those things, make sure that these directories truly exist and that they were not misplaced.

Fixing permissions after FTPing ASP.NET code to a Linux system

First off, I'm running Mono to run ASP.NET on Linux, but that's not the question.
It appears that, every time I clear out my application directory and upload, I have to go back in and fix the permissions. What I'm doing is
chmod -R -c 755 /var/www/*
...and there are two questions.
What's the deal with having to do this every time I FTP? Feels flaky.
Is there a better permissions set than 755? Do I want different permissions for the /bin directory? Or can I fix this all with one fell swoop of chown?
It could depend on your FTP server and configuration. I always used this and it worked:
chmod 777 /path/...

Resources