Hacker News new | past | comments | ask | show | jobs | submit login
Capistrano help for PHP deployment
2 points by halbertn on Dec 24, 2007 | hide | past | favorite | 4 comments
Hey All, I'm asking for help w/ capistrano. I've installed the latest version which I believe to be 2.1.0. First, I have zero experience w/ rails so please bear w/ me. I'm using capastrino cuz I've read in blogs that you can use it to deploy php applications, which is what I'm trying to do.

After struggling w/ it all weekend, I have it working and its deploying my app from subversion which is on my own linux box, to another server that I'm paying for.

Here are my questions:

1. In order to modify the deployment process (ie. symlink different file paths), I ended up directly editing the deploy.rb file located in the recipes directory under the capastrino install. Is this the only way to modify the deployment process? I do have another deploy.rb file located in the config directory of my app. But it is my understanding that this file is to setup your subversion server, the production server, username, etc...

2. This is more of a linux question, which I'm also new to...The way I have it deploying now requires me to keep entering in my password. I do have my servers setup w/ ssh keys, so I'm not sure if I've done something wrong there or if the current process is what I should expect. Anyways, below is a transcript of the deployment:

 [halbertn@linux config]$ cap deploy:update
 You are running Ruby 1.8.6, which has a bug in its  threading implementation.
 You are liable to encounter deadlocks running Capistrano,  unless you install
 the fastthread library, which is available as a gem: gem install fastthread
  * executing `deploy:update'
 ** transaction: start
  * executing `deploy:update_code'
 Enter passphrase for key '/home/halbertn/.ssh/id_dsa':
 halbertn@my.linuxbox.net's password:
  * executing "svn checkout -q  -r121  svn+ssh://my.linuxbox.net/var/svn/ah/trunk  /var/ah/releases/20071224212935 && (echo 121 >  /var/ah/releases/20071224212935/REVISION)"
    servers: ["xx.xxx.xx.xxx"]
 Password:
    [xx.xxx.xx.xxx] executing command
 ** [out] Enter passphrase for key  '/home/halbertn/.ssh/id_dsa':
 ** [out]
 ** [out] halbertn@my.linuxbox.net's password:
 ** [out]
 ** [out] Enter passphrase for key  '/home/halbertn/.ssh/id_dsa':
 ** [out]
 ** [out] halbertn@my.linuxbox.net's password:
 ** [out]
    command finished
  * executing `deploy:finalize_update'
  * executing "chmod -R g+w /var/ah/releases/20071224212935"
    servers: ["xx.xxx.xx.xxx"]
    [xx.xxx.xx.xxx] executing command
    command finished
  * executing "rm -rf /var/ah/releases/20071224212935/log  /var/ah/releases/20071224212935/public/system  /var/ah/releases/20071224212935/tmp/pids &&\n      mkdir -p /var/ah/releases/20071224212935/public &&\n      mkdir -p /var/ah/releases/20071224212935/tmp &&\n      ln -s  /var/ah/shared/log /var/ah/releases/20071224212935/log &&\n       ln -s /var/ah/shared/system /var/ah/releases/20071224212935/public/system &&\n      ln -s /var/ah/shared/pids  /var/ah/releases/20071224212935/tmp/pids"
    servers: ["xx.xxx.xx.xxx"]
    [xx.xxx.xx.xxx] executing command
    command finished
  * executing "find /var/ah/releases/20071224212935/public/images /var/ah/releases/20071224212935/public/stylesheets /var/ah/releases/20071224212935/public/javascripts -exec  touch -t 200712242130.47 {} ';'; true"
    servers: ["xx.xxx.xx.xxx"]
    [xx.xxx.xx.xxx] executing command
 ** [out :: xx.xxx.xx.xxx] find: /var/ah/releases/20071224212935/public/images: No such file or directory
 ** [out :: xx.xxx.xx.xxx] find: /var/ah/releases/20071224212935/public/stylesheets: No such file or directory
 ** [out :: xx.xxx.xx.xxx] find: /var/ah/releases/20071224212935/public/javascripts: No such  file or directory
    command finished
  * executing `deploy:symlink'
  * executing "rm -f /var/ah/current && ln -s /var/ah/releases/20071224212935 /var/ah/current"
    servers: ["xx.xxx.xx.xxx"]
    [xx.xxx.xx.xxx] executing command
    command finished
  * executing `deploy:symlink_photos'
  * executing "rm -r -f /var/ah/current/public/photos && ln -nfs /var/ah/shared/photos /var/ah/releases/20071224212935/public/photos"
    servers: ["xx.xxx.xx.xxx"]
    [xx.xxx.xx.xxx] executing command
    command finished
 ** transaction: commit

Any help would be much appreciated.

Thanks!




1) I highly suggest NOT changing the deploy.rb file in the Cap gem. You can override any task in your own deploy.rb file. For instance:

namespace :deploy do

  desc "Custom stop task"

  task :stop, :roles => :web do

    #My custom "stop" command

  end
end

(as a side note, does anyone know how to do code formatting on here?)

2) I think from what you're saying- it is deploying correctly, but you're confused as to why it is asking for your password three times? This is common, and I think it is a bug with Subversion. I deploy using svn+ssh as well and get the same thing. If I remember correctly, you only have to enter in your password correctly for the first one, and can just hit enter through the other 2. Alternatively, you can make sure you have your SSH keys set up correctly.


Thanks for the response guys!

I followed carpal's suggestion and all modifications to my deployment are done in my own deploy.rb script. I guess I have no choice but to deal w/ the numerous password requests.

My only question now is what 'user:group' should I assign to my app? My app is a website that I want publicly accessible so my first inclination is to set the app directory as 'root:root'. However, if I do this, then the deployment script must be run under the root user. Is this a good idea? I was under the impression that deployment should be handled by a separate user other than root.

For example, I want my app to be deployed to the following directory:

/var/www/app

Then, I would set the document_root in my appache setting to:

/var/www/app/current/

It is my understanding that if I want to be completely secure, than that whole directory should be set to the 'root:root' user:group ownership property.

Jd, I look forward to your write up!

Thanks!


I'm writing the chapter on Capistrano deployment on non-Rails framework for capify.org. If you can wait for a week or so maybe I can help you. Or maybe also post to a more readable copy of your error and comments off-site?


sorry...i didnt know that my formatting wouldn't stick. if you do look at the transcript, you'll notice it asking for my ssh key and password a couple of times.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: