Wordpress is one of the easiest Content Management Systems to install, but when you manage your own server, occasionally you forget configuring permissions. Do not be discouraged if you have not tried configured permissions before.
When I started using Linux seriously, I remember configuring file permissions was one of the hardest things for me to do. Because I did not bother to sit down and take the time to understand how it worked. In my defense though, Linux is not amazingly user friendly. I hope this is one area that will improve in the future.
After installing Wordpress, and trying to install your first plugin, you may run into this strange message:
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.
The above message is misleading, because Wordpress does not need FTP access to install plugins!
The message is a result of not configuring permissions of the install directory, after having extracting the latest version of Wordpress from the .zip file (Usually latest.zip).
If you know what you are doing, take this as a reminder:
sudo chown -R www-data:www-data /var/www sudo chmod -R 775 /var/www
One problem with Linux that has always annoyed me, is that you often have to configure permission settings manually. It took me a very long time to understand how it works, and sometimes I still have to look in the reference to remember how chown and chmod are used. It is amazing that we still do not have better tools at managing permissions. Something less cryptic and more readable would be cool!
In my case, I have things configured so the web server has read and write access to the www directory. Everyone else can only enter (execute), and view the files in the directory.
1. First you should change the ownership of www so that it will belong to the www-data group and www-data user.
sudo chown -R www-data:www-data /var/www
There is both a user and a group called www-data. Depending on your operating system, and how Apache was installed, the names may be different on your own system. I installed Apache on Ubuntu using apt install.
2. Change the permissions so that the user and group is allowed read, write and execute access to the directory. Depending on your security requirements, you may want to do this differently. But, I have found this seem to work best for my own needs.
sudo chmod -R 775 /var/www
Using the -R flag runs the command recursively, also changing permissions of subdirectories and files.
Also, the below table might be useful:
To only give read and write permissions, you would simply add 4+2, which equals "6".
The number itself represents User, Group and Other, hence 775 (or 665 without execute permissions). Other represents everyone not in the group that owns the directory.