wordpress restored from backup asking for ftp

While developing a WordPress site, giving www-data write access to your files can make your life a lot easier.

The reason is that the admin panel of WordPress allows you to change lots of configurations easily, creates the .htaccess file for you with the correct rewrite rules (depending on how you want your permalinks), installs and configures plug-ins. You even have access to an editor which allows you to edit your CSS and PHP files.

Although, the editor is not that important. When you have access to the files, an IDE would be a much better choice. As for the other functionalities, they can prove to be useful sometimes.

So to summarize, the best configuration would be to give user ownership to root and group ownership to www-data.

sudo chown -R root:www-data /var/www/wordpress

Then give write access to www-data during development:

sudo chmod -R g+w /var/www/wordpress

Once you are done with the development, you should revoke the write access from your files to www-data and only give that user write access on the uploads folder (This is where files uploaded from the admin end up).

sudo chmod -R g-w /var/www/wordpress
sudo chmod -R g+w /var/www/wordpress/wp-content/uploads

And finally, it is best to revoke all permissions from other (You can even do this during development):

sudo chmod -R o-rwx /var/www/wordpress