WordPress needs the FTP credentials to update plugins - wordpress

I host WordPress on AWS EC2 (Ubuntu) and encounter the following error while updating plugins:
To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.
rwx permission has been granted to the user www-data. Here is what I do.
<!– language: lang-bash –>
# Add a new group
groupadd www-pub
# Add the user `www-data` to the group 'www-pub'
usermod -a -G www-pub www-data
# Change the ownership of '/var/www/' to 'ubuntu:www-pub'
chown -R ubuntu:www-pub /var/www
# Change the permissions of all the folders to 2775
find /var/www -type d -exec chmod 2775 {} +
# Change the permissions of all the files to 0664
find /var/www -type f -exec chmod 0664 {} +
As you can see, www-data has all the right permissions, but I am still required to enter the FTP credentials. What is the reason and how can I fix it?

There is a simple fix. Just edit file wp-config.php and write this code inside it.
First try this:
define('FS_METHOD', 'direct');
Note: Do not add this to the end of the file, but just below the database information on the top of the file.
define('FTP_USER', 'username'); // Your FTP username
define('FTP_PASS', 'password'); // Your FTP password
define('FTP_HOST', 'ftp.example.org:21'); // Your FTP URL:Your FTP port
Also please read this blog post.

This means that WordPress is having limited permission for making changes in the folder that it was installed.
In-order to fix this, all that you need to do is provide necessary permissions for the same.
Run the following command in your terminal, PuTTY, or command line prompt after connecting to your Server via SSH.
sudo chown -R apache:apache /var/www/html
Checkout the below article for full details (Syam | MMWYS.Online):
How to fix the infamous issue of WordPress asking for FTP Credentials for Installing Plugins / Themes?

I suspect that this answer explains why it isn't working.
Most Ubuntu web servers I have seen are set up a bit differently from what you're doing. I'm not sure what your reason is for doing it that way, but if you wanted to keep things simple you would just set the owner and group for all files to www-data:
chown -R www-data:www-data /var/www
That will grant the web server full access to all of your files in the web root. If you needed to grant any additional users access to those files, you would just add them to the www-data group.
usermod -a -G www-data someuser
The file permissions you've set up look good to me as-is.
#Change the permissions of all the folders to 2775
find /var/www -type d -exec chmod 2775 {} +
#Change the permissions of all the files to 0664
find /var/www -type f -exec chmod 0664 {} +
For reference, this answer explains what chmod 2775 (specifically the 2) means.
Essentially, it causes any new files to inherit the group of the directory. www-data in this case. This means the web server will have access to any files created by other users, without having to change the ownership or permissions of those files.

You need to assign a user to your project.
For NGINX Servers:
sudo chown www-data:www-data -R <your_wordpress_dir>
For Apache Servers:
sudo chown apache:apache -R <your_wordpress_dir>
And change directory permissions:
sudo chmod 755 -R <your_wordpress_dir>

Add this line define( 'FS_METHOD', 'direct' ); of code in your wp-config.php file after define( 'WP_DEBUG', true );.
So it should be like this:
define( 'WP_DEBUG', true );
/* Add any custom values between this line and the "stop editing" line. */
define( 'FS_METHOD', 'direct' );
/* That's all, stop editing! Happy publishing. */
Save the file and try again.

Related

Editing and Resetting Permissions for all folders, subfolders and files

I've just started to learn Linux Command Line. The setup I am on is AWS Lightsail bitnami Wordpress. I work with wordpress primarily.
I'm still confused about file permissions in Linux. Why do I have permissions denied when I sign in as the owner?
Whenever I have to ftp, overwrite, edit files and folders, I have to change the permissions settings for each affected folders and files manually via SSH.
More often than not, at the end of the day, I lost track of which folders and files' permissions I have edited and need to reset to default. I find this a chore and I believe there is a better way.
I wonder if there are lines of command that can
give me full access to all directories, folders, subfolders and files at once?
change the permissions for directories, folders, subfolders and files at once?
reset the permissions of all edited files to default/original all at once?
To check the permission of the file
sudo stat TARGETFOLDER
To change the permission of the file
sudo chmod 777 TARGETFOLDER
Bitnami Engineer here,
We configure the permissions of the WordPress' files by setting bitnami as the user owner and daemon as group owner of the files. This configuration allows you edit the files using the bitnami user and the webserver can use the daemon group to do the same. However, if you make changes to the application using the web interface (install plugins or themes), those new files are owned by daemon:daemon (the Apache and PHP-FPM services use that user and group so they generate the files using those permissions configuration) and you won't be able to edit them unless you use the command line and sudo. In that case, you can run the following commands to be able to edit those files using the bitnami user
sudo chown -R /opt/bitnami/apps/wordpress/htdocs
sudo find /opt/bitnami/apps/wordpress/htdocs -type d -exec chmod 775 {} \;
sudo find /opt/bitnami/apps/wordpress/htdocs -type f -exec chmod 664 {} \;
sudo chmod 640 /opt/bitnami/apps/wordpress/htdocs/wp-config.php
You can learn more about this here
https://www.youtube.com/watch?list=PLGgVZHi3XQNn4x0DU7Qj1r_inej3xEUda&v=nKfle7O0vN8&feature=emb_title
1 and 2, you can try chmod -R option.
3. i think it can not. you should restore it. maybe it help.

Nginx permissions with wordpress

I am trying to set up wordpress on digitalocean with nginx. I am running into permissions issues though. When I upload a file or try to install a plugin I get the cannot create in directory warning. So I came across the post Here that says I need to give nginx access to the folder. So I executed the following:
sudo chown -R www-data:www-data /path/to/folder
sudo chmod -R 755 /path/to/folder
This works except now I cannot add and delete files with filezilla. Obviously because the permissions to the folder are no longer with the me the user they are now with www-data.
So my question is what is the correct way to configure nginx to work with wordpress and still allow me to upload and delete files with ftp.
When using digital ocean droplets you will probably be using sftp access to your server.
Try the following commands in your terminal when logged in.
Add your currently logged in user to the www-data group:
sudo usermod -aG www-data $USER
Then change your vhost directory and all files and subdirectories to be owned by www-data group:
sudo chown -R www-data:www-data /var/www
Set the proper permissions so you can upload files via sftp, manage files via command-line, and upload plugins and media directly in WordPress:
sudo chmod -R 774 /var/www
Hope this helps
Saskia

correct rights linux webserver

I have installed a LAMP server (Ubuntu) on a VPS and everything seems to be running fine. After uploading and installing WordPress I ran into a couple of rights issues (not being able to upload, not being able to create/change the .htaccess file from within WordPress, the usual) so I chmod the directory so the www-data user is owner:
sudo chown -R www-data:www-data /var/www/domain.com/public_html/
Now all of the above works fine, but...
When I upload a file or directory the owner/group is set to the user I'm using to "FTP" with. This results in WordPress not being able to update the files (e.g. a plugin). The user I'm using for FTP transfer is part of the www-data group.
What should/can I do to prevent this and thus automagically add the www-data owner/group to uploaded files? And is this the way to go?
Think I found it: https://help.ubuntu.com/lts/serverguide/httpd.html
Sharing Write Permission
sudo chgrp -R www-data /var/www/domain.com
sudo find /var/www/domain.com -type d -exec chmod g=rwxs "{}" \;
sudo find /var/www/domain.com -type f -exec chmod g=rw "{}" \;

What to set permissions to when developing a wordpress site locally

I've setup a domain through apache virtual hosts and set the permissions on the public_html directory as $USER:$USER. I also have wordpress installed in public_html/wp
When trying to add a local image to the media part of the site, wordpress threw an error saying it did not have permission to create the required folder to store the image. The directories are set to 755 and files to 644 so I assumed it was the ownership that needed to change. So I ran
sudo chgrp -R www-data /var/www/virtual-host-site.dev/*
So my ownership looked like $USER:www-data however, this still didn't give wordpress rights, so I tried
sudo chown -R www-data:www-data /var/www/virtual-host-site.dev/*
which fixed the problem. But then as a user, I have no write access to the directories. I thought adding $USER to the group www-data
sudo usermod -a -G www-data $USER
would give $USER rights like www-data, but this doesn't seem to be the case.
How do I keep my folders as 755 and files as 644 while allowing both $USER and wordpress write access to the application directories?
Thanks.
So I resolved this by changing my dev directory to www-data:www-data and changing my themes folder to $USER:www-data with the command
sudo chown -R $USER:www-data wp/wp-content/themes

Update wordpress theme on ec2

I'm hosting a wordpress site on ec2 and I'm trying to update my theme through the admin screen. Its asking me for Hostname and ftp username and password. Is ec2-xxx.compute-1.amazonaws.com:22 my hostname? I tried along with ec2user and root for my ftp username but no luck. What am I doing wrong?
Skip the FTP info altogether and just change the permission of the directory structure where Wordpress is installed.
VIA SSH
sudo chown -R apache:apache path/to/wordpress
sudo makes sure you execute as the root user
chown will change the owner of the directory
-R will make it recursive, so it changes all files and directories within
apache:apache is user:group
And then the path to wordpress. Could be /var/www/html/sitename.com or if you navigate to the folder where Wordpress is installed, you can use a period (.) to tell it to change the current directory.
This will make is so that you can't copy files via sftp though, so it is good to change at least the themes directory back to the ec2-user:ec2-user user and group.
So this changes back to your ssh/sftp user:
sudo chown -R ec2-user:ec2-user path/to/wordpress
You can assign the folders to the ftp user and the apache group and then make them group writable as well. This will allow you to ftp into the directory, and allow everything to be auto updated within Wordpress.
// Set the wp-contents into the apache group and then make files group writable
sudo chgrp -R apache wp-content
sudo chmod -R g+w wp-content
// This makes new files created in wp-content and all of its sub-directories group-writable.
sudo chmod g+s wp-content
Then add this to wp-config.php to force Wordpress to update when only applying this wp-content:
define('FS_METHOD', 'direct');
You can also apply to the whole Wordpress install to auto update Wordpress and not just plugins/themes. If you do this, I would recommend putting your wp-config.php file one directory above your Wordpress install though, so you can lock it down separately.
EDIT: Whenever I am having permission troubles on EC2, I go to site root directory, and paste these lines in. I apply it to the whole Wordpress install these days:
sudo find . -type d -exec chmod 0755 {} \;
sudo find . -type f -exec chmod 0644 {} \;
sudo chown -R ec2-user:apache .
sudo chmod -R g+w .
sudo chmod g+s .
I use something similar on my Mac as well.
In your wp-config.php under directives add this line:
define('FS_METHOD', 'direct');
You can simply solve this problem by doing this via ssh:
sudo chown -R apache path/to/wordpress
then
sudo chmod -R 755 path/to/wordpress
Your hostname would be ec2-107-20-192-98.compute-1.amazonaws.com.
Your username will be the username you use to SFTP to the instance normally - ec2user for some instance types, ubuntu for Ubuntu AMIs, etc. EC2 generally doesn't use passwords, preferring SSH keys, so you'll have to set a password for your account by doing passwd on the commandline.
Try adding FTP credentials to wp-config.php: http://codex.wordpress.org/Editing_wp-config.php and http://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants
That should make WP admin stop asking for FTP details. But depending on how you've set up permissions via the command line, may have to go to the command line to edit files like wp-config.php . And you may not have sufficient permissions to upload and for WP to unzip a theme.
As per other answers, I use SFTP with a server of ec2-xx-xxx-xx-xx.compute-1.amazonaws.com username of ec2-user
ec2-107-20-192-98.compute-1.amazonaws.com:22 represents both the hostname and the ssh port. (SSH is normally on port 22, though it can run on any port.)
Try just ec2-107-20-192-98.compute-1.amazonaws.com in the hostname field.
I'm still skeptical of a webpage asking for a username and password. Seems a bit silly to me, since you should just use SFTP to directly upload whatever content you want using your SSH identity key instead of a password.
You could simply use 127.0.0.1 as hostname and check FTP in Wordpress ftp settings.
To resume what has been said:
user is the same you actually use to SSH/SFTP
password needs to be set/updated logging in via SSH and typing
sudo passwd your-user-name

Resources