Give your capistrano script some EngineYard config love

I was attempting to deploy the latest changes to the server for the very first time on my machine and got a wonderful little message from capistrano telling me:

`mongrel:restart' is only run for servers matching {:only=>{:mongrel=>true}, :roles=>:app}, but no servers matched

The fix? From what I understand is that you need to tell capistrano that your web and app roles are running mongrel like so:

role :web, '42.69.187.666', :mongrel => true
role :app, '42.69.187.666', :mongrel => true


That should do it for you, should you have this issue.

RubyJax pairing fun

Tonight's RubyJax meeting rocked out! Getting everyone to pair up and work on something interesting was exciting. I myself was able to work with Russ, really nice guy that wanted to learn more about Rails to kick his ColdFUSION habit!

Also, thanks to the Jacksonville Developer's UserGroup headed up by Jonathan Bates and crew. They sent out a reminder as well as their posting that helped bring in some new faces tonight, thanks guys!

specialized collections using has_many

Here's the following scenario:

You have a ticketing system. You have a User that can create tickets. That same User can be assigned tickets. So how can you specify a has_many for both cases for the User?

Table Schema:

CREATE TABLE User
(
id INT,
title VARCHAR(42),
created_by INT,
assigned_to INT,
)




The answer:

class User
has_many :assigned_tickets, :foreign_key => 'assigned_to', :class => 'Ticket'
has_many :created_tickets, :foreign_key => 'created_by', :class => 'Ticket'
end



In action:
u = User.find(:first)

render :partial => 'tickets/assigned_tickets', :collection => u.assigned_tickets
render :partial => 'tickets/created_tickets', :collection => u.created_tickets

NGinx + PHP5 + MySQL

Had a bitch ass time getting NGinx + PHP5 + MySQL working on Fedora 8. There's very little documentation and what little documentation there is, is in Russian.

At anyrate -- Nginx is the webserver. It serves up content that's it. Because it does it's 1 job really well, that means you have to hook-in all the other shit that you want to use. In my case, I want to serve up PHP pages. Nginx isn't like Apache where you can compile PHP into. You have to host the PHP-FastCGI in a wrapper (lighttpd) that will be accessed by Nginx.

When a request comes in for a .php file, nginx connects to the localhost usually on a port you specify to LightTPD. LightTPD is just sitting there twiddling it's thumbs waiting for shit like this to be requested. At that point, everything should work as planned -- your .php is served. See below for a list of steps that I think is close to being true.
  • user_connects_to_your_page
  • nginx sees request for .php page
  • nginx contacts lightTpd and passes php page to be parsed
  • lightTpd passes page onto PHP-FastCGI being hosted
  • PHP-FastCGI handles .php page/request
  • page returned to nginx
  • user_is_happy
The install instructions below are Fedora 8 specific, so I'm sorry if you aren't running it. You should be able to follow the process flow regardless of your flavor.

Install the following:
  • Nginx - the vanilla install will work
    • yum install nginx -y
  • Lighttpd - vanilla install will work yet again
    • yum install lighttpd -y
  • Php5 - here's the bitch.
    • download the source
    • untar it somewhere
    • ./configure --prefix=/opt/php --enable-fastcgi --with-mysql
    • (If you are running on the 64-bit version of Fedora you'll pull your hair out if you don't add the switch --with-libdir=lib64 at the end of the previous line)
  • cross your fingers that everything got installed properly and will "Just-work" the first time

Now the fun starts. I'm not going to go into crazy detailed configurations, I'm just going to tell you which files you'll probably want to look at and some options since alot of that information is out there already. (do a find for the files if they aren't in the same spot as mine)

  • nginx.conf - this acts like apache's httpd.conf, pay attention to the server directories and port # in red.
    • The port number, corresponds to the port that light-tpd is running on that you launch
    • the directory is obviously the root of where all your php scripts will be running from


server {
listen 80;
server_name myspace.com;
access_log logs/myspace.access.log main;
location / {
root /sites/myspace.com;
index index.html index.php;
}
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME /sites/myspace.com/$fastcgi_script_name;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass 127.0.0.1:10004;
fastcgi_index index.php;
}
}

  • start-fastcgi.php - a script I made to just get the thing working

/usr/bin/spawn-fcgi -a 127.0.0.1 -p 10004 -u lighttpd -g lighttpd -f /opt/php/bin/php-cgi