21

When I run cap production deploy I get cannot create directory ‘/var/www/application/repo’: Permission denied.

So far I've created deploy user like:

adduser deploy
adduser deploy sudo

and I use this user in Capistrano.

Indeed, when I log to deploy@my.vps.ip I don't have sudo permission by default, every time I need to enable it explicitly like sudo su.

I see two possible solutions:

  1. Enable sudo in Capistrano
  2. Enable sudo in Ubuntu

Unfortunately I don't know how to do neither of them.

Kamil Lelonek
  • 14,592
  • 14
  • 66
  • 90

3 Answers3

46

By default Capistrano 3 deploys to /var/www which is not writable by deploy user. You need to change the ownership of /var/www to deploy user using the following command.

sudo chown deploy:deploy /var/www/

After this, you should be able to deploy your app without permission error.

Justin
  • 4,922
  • 2
  • 27
  • 69
shankardevy
  • 4,290
  • 5
  • 32
  • 49
  • 7
    If someone is using Amazon EC2 ```sudo chown ec2-user:ec2-user /var/www/``` – marman Jun 05 '15 at 04:40
  • 3
    You most likely will need to use -R so that all subdirectories are owned by deploy user: `sudo chown -R deploy:deploy /var/www/` – Bob Roberts Apr 13 '17 at 00:55
5

Credit to Bob Roberts.

I think this should be an answer as its easy to miss your comment. I know I missed it few times.

sudo chown -R deploy:deploy /var/www/

or whatever your username is

sudo chown -R username:username /var/www/
Abdullah Aden
  • 882
  • 9
  • 13
0

Had the same error here, following the good tutorial of GoRails "Deploy Ruby on Rails To Production in 2019", where he create a user "deploy" and set to deploy the app in "home/deploy". Don't forget that you have to use the username created on the server. So deploy's directory is "home/USERNAME".

OBrooks
  • 343
  • 1
  • 3
  • 7