https://www.digitalocean.com/community/questions/can-t-install-wordpress-themes-ftp-error
I also added this define('FSMETHOD', 'direct'); in wp-config.php file:
define('FSMETHOD', 'direct');
Then I did this in terminal:
chown -R www-data:www-data /var/www
find /var/www/ -type d -exec chmod 755 {} \;
find /var/www/ -type f -exec chmod 644 {} \;