Rails on freeBSD

Posted by charles Sun, 26 Feb 2006 23:08:00 GMT

The rewrite project has us needing to support three different databases: Oracle, postgresql and SQLServer. Rather than take the approach of using MySQL as seen in “Agile Web Development with Rails” I decided to setup rails to use postgreSQL on my freebsd desktop and laptop. Installing this FLPR environment (freebsd, lighttpd, postgreSQL and rails) turned out to be straightforward despite some sketchy documentation. Those of you using freebsd may want to give this a try. As always it is important to become root to update the ports collection, then checking to see if any currently installed ports need to be upgraded before beginning.

Having done that, then as root cd to

/usr/ports/databases/postgresql81-server/

and do

make all && make install && make clean

This will install both the postgres server and client ports, and it will also have created a pgsql user along with a /usr/local/pgsql directory. This user will own all the data files and must also own the server process. Now the databse files and inital tablespaces need to be created. So, su to the pgsql user and then do

/usr/local/bin/initdb

If you want postgreSQL to start at boot, then make sure that postgresql_enable=”YES” appears in /etc/rc.conf. Don’t start an instance of the databse just yet, but rather exit back to being root and install the rails port. Just cd to /usr/ports/www/rubygem-rails and do the usual

make all && make install && make clean

Then cd to /usr/ports/www/rubygem-redcloth and do the same make sequence.

Next the C source code adapter needs to be installed. Unfortunately, neither the rails install nor the postgreSQL install will correctly set the lib path for building the adapter, so you need to set an environment variable otherwise the build will fail. So, as root do

setenv POSTGRES_INCLUDE /usr/local/include/

follwed by

gem install postgres

Now, a database instance can be started, so, su to the pgsql user and do

/usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start

You will need to create yourself as a database user (actually, as a superuser). Here is how I did myself

/usr/local/bin/createuser charles
Shall the new user be allowed to create databases? (y/n) y
Shall the new user be allowed to create more new users? (y/n) y
CREATE USER

If you feel more comfortable with a gui-interface for database administration, consider installing the pgadmin3 port.

Lastly, when you create your rails app, you will need to modify the config/database.yml file by commenting out all the lines except the postgreSQL entries and then modify those using the names of the three databases you need (ehr_* in my case):

development:
 adapter: postgresql
 database: ehr_development
 username: charles
 password:
 host: 127.0.0.1
 port: 5432
test:
 adapter: postgresql
 database: ehr_test
 username: charles
 password: 
 host: 127.0.0.1
 port: 5432
production:
 adapter: postgresql
 database: ehr_production
 username: charles
 password: 
 host: 127.0.0.1
 port: 5432

Using postgreSQL in a tiered environment is only slightly more complicated, and I’ll do a post about that sometime in the future.

Posted in  | Tags , , , ,

Site upgrade

Posted by rick Sun, 20 Nov 2005 17:10:00 GMT

This site is now running on lighttpd & fcgi, fronted by Apache running mod_proxy. I had been running a number of sites on this server using simple Apache/FCGI, but I’ve found stability with that combination to be far from ideal. The Apache FCGI linkage seems fairly fragile. Sometimes the Rails controller doesn’t get a chance to fire properly, resulting in HTTP 500 errors; sometimes an FCGI process gets seemingly disconnected and goes into a tailspin, sucking CPU like crazy; and overall Apache/FastCGI really isn’t (“fast”, that is).

Since we’re using Apache 1.3.33 on this FreeBSD server, however, I can’t (without digging around for a patch I’ve yet to actually find, and then risking the rebuild of Apache) have Apache pass the hostname properly back to lighttpd (this is an Apache2 feature). So I’m running a separate lighttpd intance for each Rails site (there are 5 on this server), each on a different port. Less than ideal, but it seems to be working, and fast.

Our CenterNet milestone sites and nightly build sites are using a similar configuration—a subdomain per site. But there we’re fronting with Apache2, and hence only need 1 lighttpd process for the whole enchilada.

If anyone knows how to easily work around this Apache1 + multiple lighttpd on different ports setup issue I’d be pleased to hear it for my personal sites.

Posted in  | Tags , , ,