Issue in drupal the directory sites/default/files is not writable - drupal

To solve these issues display in process of installing Drupal as:
Go to your "drupal" folder and make permission 777
Then open "sites" folder and make it 777
Choose "default" folder and make it 777
Open "files" and choose "setting.php" to change permission to 777

You are giving public right to execute read and write files in your directories. Clearly not a good idea.
Check this link for more infos on what to do in production environnement (it also explains basic chmod values wich you seem to not be understanding) : https://www.drupal.org/node/244924

Some normal permissions would be 0644 for files and 0755 for directories. Then i.e. settings.php since there is no need for it to be writable you should fully forbid writing.
If only 0777 "solves" your issue, maybe problem are not permission values but file owner. It happens that you upload files with one (FTP) account Apache is running website with some other, which is not allowed to write over first one. So changing file owner could solve the issue.

Related

Setting permissions to WordPress to install plugins is preventing access through SSH

I have read several ways to solve the problem of permissions in WordPress to install themes and plugins from the WordPress administration.
As I understand the problem is that the owner of the folder where WordPress is installed must be the user who manages the web server (read postdata). In my case with Apache and AWS, www-data.
However, by changing the owner to www-data (even just changing the group to this user), I lose SSH access to the server. In this case I had to ask the administrator of the entire server to access from its user and restore the owner and permissions of the folder.
I am using Amazon Web Services with Ubuntu 16.0.4 LTS where I have access to a main user and the installation of WordPress is located at the root of the user, i.e. /home/myuser/
I am accessing via SSH with a .pem key and with myuser#publicdns
What can I do?
Thank you so much.
PD: WordPress in this guide says that the owner always has to be the ftp web server owner (i.e. myuser) and never the webserver, I agree.
I hate having to answer my own question but maybe I can help others solve problems easily and fast. This is what worked for me:
BEFORE DOING ALL OF THIS YOU SHOULD TAKE NOTE OF ALL PERMISSIONS, OWNERS AND GROUPS OF ALL THE FOLDERS & FILES WE ARE CHANGING HERE BECAUSE YOUR WEBSITE MAY FAIL AFTER CHANGING THESE SETTINGS. ALL HOSTS HAVE DIFFERENT CONFIGURATIONS.
As long as you don't exit the session, you may be able to return all the changes you have made with sudo privileges.
If your WordPress installation is in the root folder of the user, eg: /home/myuser/
Take note of permissions, owners and groups:
With ls command and the -a -l flags you can see all files using long listing format. Do this being in /home and /home/youruser/ paths.
cd /home
ls -al
cd /home/youruser
ls -al
Copy the output and save it in some text file.
Prevent losing SSH access:
The owner of the folder must be the user you are accessing with.
sudo chown youruser /home/youruser/
I also have set the group of the folder myuser.
sudo chgrp youruser /home/youruser/
Set the permissions of this folder with 751 (I think the important thing here is that the owner has full access)
sudo chmod 751 /home/youruser/
The permissions for the hidden folder .ssh must be 700 for top folder, 600 for files inside the folder and the owner & group must be youruser
sudo chmod 700 ~/.ssh/
sudo chmod 600 ~/.ssh/*
sudo chown -R youruser ~/.ssh/
sudo chgrp -R youruser ~/.ssh/
Solve Plugins & Theme installation problems:
I'm still unsure if this solution is right for site security. However, I think you can apply this fix and then return the changes. The website should run smoothly in both cases.
I have changed permissions for folders and files via sftp in Nautilus. If you are using .pem key remember to add the key using ssh-add path/to/your/key.pem
then connect to the server sftp://youruser#yourpublicdns
Make multiple click in folders wp-content, wp-admin, wp-includes and do Right click -> Properties (or Ctrl + I), change to permission tab and click in the "Apply permissions to Enclosed files" button on the bottom of the window, set:
Files
Owner: Read and Write
Group: Read only
Others: Read only
Folders
Owner: Create and delete files.
Access to files.
Access to files.
This will apply the changes to files and folders inside these three folders selected. Depending on the speed of your internet and how much files do you have, this may take some minutes to finish.
Make multiple click in remaining files and do Right click -> Properties (or Ctrl + I), change to permission tab and set
Owner: Read and Write
Group: Read and Write
Others: Only Read
AND LAST
Change the owner and the group of all the WordPress installation files, i.e. all the files inside /home/youruser
sudo chown -R www-data wp*
sudo chgrp -R www-data wp*
This make changes for all the files that start with the "wp" word recursively. To remaining files, I have made the changes manually. There are better ways like find command but that changed hidden folders too so I decided to do manually.
Apply the corresponding changes to files to the .htaccess as well.
NOTE: Test your website. Access to it, access to your WordPress admin, try installing plugins and themes, open another terminal (DON'T CLOSE the one you were writing the commands) and try to SSH into your webserver. If you have problems use the backup and revert the process.
Hope this helps.

Drupal 8.2.6 /tmp

Drupal 8.2.6
Media Entity 8.x-1.0-alpha4
Ctools 8.x-3.0-alpha27
So after turn on CSS/JS aggregation I noticed that I can not upload images anymore. When I try to upload an image it gave me an error. So I changed my tmp directory to
sites/default/files/tmp
but that didn't help and gave me an error of
The file could not be saved. An unknown error has occurred.
File upload error. Could not move uploaded file.
This value should not be null.
I checked the permissions. default folder is 755. files folder is 755. tmp folder is 755. This also started affecting my Drupal 7 website after I enabled aggregation, so I am certain this is what is affecting my site.
Any information or leads would be very helpful, as I've been stuck.
After a long 2 days struggling to find the answer, I finally found a temporary solution. I used the command chmod -R 1777 /tmp . Then in admin/config/media/file-system I set directory to /tmp . Might have security vulnerabilities, but it works for me.

Permission denied error in wordpress 3.3.1

I once moved my wordpress directory one level up on my server (its now in the root). Everything seems to work fine for a while but niow i'am starting to have troubles with uploading images.
When i try to include an image by uploading it from my computer wordpress throws an "Permission denied" error:
copy(/home/bram/domains/dutchmountaineer.com/public_html/wp-content/uploads/2012/05/Costa-Rican-Frog.jpg)
[function.copy]: failed to open stream: Permission denied in
/home/bram/domains/dutchmountaineer.com/public_html/wp-admin/includes/file.php on line 348
618
I tried setting the uploads and includes folder to 777 which had no effect. I have set them back to 755.
Any help please!
Jorrit
EDIT:
I tried changing the full path (in media settings) but it was of now help. I think it since i moved the wp installation from /wp/ to the root of my server
Check who owns the directory. It may be possible that you need to add www-data to the group. Weird, yes, but I sometimes encounter scenarios where even files and directories with 777 are denying me access if I don't add my user to the owner group.
It means you are getting error near this code
// Copy the temporary file into its destination
$new_file = $uploads['path'] . "/$filename";
copy( $tmp_file, $new_file );
unlink($tmp_file);
check your settings under settings->Media tab in admin panel and check you have the appropriate permissions for the folder, you can change the upload path as well. Let me know if problem still persists.
You have to allow uploads directory 777 rights and check your folder user and ftp user are same or not.

Symfony2 and Ubuntu 11.10 permission folder and file

When i open some files(Symfony2.0) with netbeans, this say me:Cannot Lock read Only
i must click right mouse and set every folder the permission to "read and write"
this is big problem because i must set every folder and file.....
how i can fix this my problem permission?
you need add write permissions to the whole folder/subfolders and files.
For example:
chmod -R u+w foldername
-R is to do it for sub-folders and all files (recursive)
u - is for the owner (your user)
+w - is to add write permissions
Perhaps you created symfony2 files using root where netbeans uses user permissions which is currently logged in. Make sure your files/folders belong to user not to the root
If your user is different from the user the server is running as (apache, httpd, www-data for instance), then you must either add yourself to the server group and chmod all the files so group permissions are set to read and write, or chown all the files to you (chown -R user:user) and add your server user to your group.
Also, dont forget to set proper permissions on the cache/ and log/ folders
(they must be writable by the command line user when you do a cache:clear and also writable by the server user)
For more info you can check the "setting up permissions" paragraph on the Installing Symfony Chapter of the Symfony book here:
http://symfony.com/doc/current/book/installation.html

Problem with file permissions in Drupal 7

So, I've copied the install tree of a site I'm developing to another machine. After updating settings.php to the proper db and base_path, and making sure that the file permissions for /sites/default/files/ are set to 755 (chmod -R 755 files), the file settings page (Configuration -> Media -> File System) insist that "The directory sites/default/files exists but is not writable and could not be made writable." I've experimented with 777 permissions to no avail. Any thoughts?
Change ownership of the files directory to apache, or whatever your web user is.
chown -R apache.apache files
If you don't have access to change ownership for some reason, then making all files recursively writable should work.
chmod -R a+w files

Resources