I''m not sure if there''s interest in this approach to development, but I''ve put together the changes necessary to make your Rails application in to a "product". My use of that term needs some explanation: At MyTechSupport, we often have clients who pay a few thousand dollars for a web site, but in order to make a profit, we need to re-sell our work to other (potential) clients with similar business needs. For example, we are currently working on an adoption site. Adoption sites, in general, have some generic needs (e.g. a "Birth Mother" login and a "Waiting Family" login), but our client has some particular needs as well. Using the following code, you can create a single generic application which uses a separate database for each client. In addition, you will have a hierarchical application structure wherein add-ons and tweaks for specific customers are possible without affecting the core "generic" site code base (neither will you have to copy that code base for each application). In this way, you can maintain a core application code base that every client uses, while still providing flexibility for paid add-ons or site-specific needs. The directory structure of the Generic application is just like a normal Rails application, with one additional directory: the "sites" directory. So it looks something like this: RAILS_ROOT/ app/ controllers/ views/ (etc.) public/ sites/ best_ever_adoptions_co_inc/ app/ controllers/ views/ public/ yet_another_adoption_co/ app/ controllers/ views/ public/ If you put a file called, for example, welcome_controller.rb in RAILS_ROOT/app/controllers, then all of your sites will access that controller as normal unless you put a file with the same name in the site-specific controllers folder. In that case, the RAILS_ROOT welcome_controller.rb will be loaded, and then the WelcomeController class will be reopened (yay for Ruby!) by the site-specific welcome_controller.rb (say, for example, in RAILS_ROOT/sites/ yet_another_adoption_co/app/controllers/) and modified as needed. For example, you could override the "index" method to do a redirect, or you could add a before_filter to make the controller require a login, just for that one client. Views, layouts and partials act similarly--however, they simply override their generic counterparts. For example, if you have an index.rhtml and a _title.rhtml in RAILS_ROOT/app/views/welcome/ and supposing this index.rhtml has a <%= render :partial => "title" %> in its code, then the _title partial will be rendered in place. Now, however, let''s say that we put a _title.rhtml partial in RAILS_ROOT/ sites/yet_another_adoption_co/app/views/welcome/. In that case, our generic index.rhtml will load the site-specific _title partial in place. Hierarchical customizations in a jiffy. To accomplish this feat, the following (remarkably few) changes will be necessary: 1. Create the RAILS_ROOT/sites folder and any client directory structures within it. 2. Modify your environment.rb file as follows: a. Find the section where most of the core rails libraries are ''require''d, e.g.: require ''active_support'' require ''active_record'' require ''action_controller'' require ''action_mailer'' require ''action_web_service'' ... and add this to the end (note that it is important that this require occurs after the core rails libraries are required but before the next ActiveRecord::Base.configurations): require ''productize'' b. Replace the following line ActiveRecord::Base.configurations File.open("#{RAILS_ROOT}/config/database.yml") { |f| YAML::load(f) } with: ActiveRecord::Base.configurations YAML::load(ERB.new((IO.read("#{RAILS_ROOT}/config/ database.yml"))).result) 3. Create the following ''productize.rb'' file in your RAILS_ROOT/lib folder (you may want to copy this email as documentation in the header as I did): # productize.rb SITE = ENV[''site''] || ''yet_another_adoption_co'' SITE_ROOT = File.join(RAILS_ROOT, ''sites'', SITE) module Dependencies def require_or_load(file_name) file_name = "#{file_name}.rb" unless ! load? || file_name [-3..-1] == ''.rb'' load? ? load(file_name) : require(file_name) if file_name.include? ''controller'' file_name = File.join(SITE_ROOT, ''app'', ''controllers'', File.basename(file_name)) if File.exist? file_name load? ? load(file_name) : require(file_name) end end end end module ActionView class Base private def full_template_path(template_path, extension) # Check to see if the partial exists in our ''sites'' folder first site_specific_path = File.join(SITE_ROOT, ''app'', ''views'', template_path + ''.'' + extension) if File.exist?(site_specific_path) site_specific_path else "#{@base_path}/#{template_path}.#{extension}" end end end end 4. Modify your database.yml like so: development: adapter: mysql database: <%= SITE %>_dev host: localhost username: root password: test: adapter: mysql database: <%= SITE %>_test host: localhost username: root password: production: adapter: mysql database: <%= SITE %> host: localhost username: root password: 5. In your Apache or Lighttpd config, create a FastCgiServer for each client application that will be using your generic application (i.e. each directory in the RAILS_ROOT/sites/ directory needs to have a VirtualHost set up to use the public/ folder in each site). The dispatcher for your FastCGI server should be set to the generic RAILS_ROOT/public/dispatcher.fcgi script. And finally, use the appropriate set-env directive on the FastCgiServer configuration to make the environment variable "site" equal to the client name (i.e. the client''s name is used both as the prefix for your database names (e.g. yet_another_adoption_site becomes yet_another_adoption_site_dev) and as the directory name in the sites/ directory). This little bit of set-up can give you a lot of pay back! NOTE: I haven''t done step 5 yet, so I don''t have the same level of detail in the instructions. I''ll post that later if there is interest. Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Great post, thanks for writing this up. Very interesting. Chris On 7/12/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''m not sure if there''s interest in this approach to development, but I''ve > put together the changes necessary to make your Rails application in to a > "product".-- snip --> Duane Johnson > (canadaduane) > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >
Really good post. Will archive it for reference. Thanks! -- caffo :: http://caffo.info/ :: caffeine-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Nothing is true, everything is permitted. On 7/12/05, Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''m not sure if there''s interest in this approach to development, but I''ve > put together the changes necessary to make your Rails application in to a > "product". > > My use of that term needs some explanation: At MyTechSupport, we often > have clients who pay a few thousand dollars for a web site, but in order to > make a profit, we need to re-sell our work to other (potential) clients with > similar business needs. For example, we are currently working on an adoption > site. Adoption sites, in general, have some generic needs (e.g. a "Birth > Mother" login and a "Waiting Family" login), but our client has some > particular needs as well. > > Using the following code, you can create a single generic application > which uses a separate database for each client. In addition, you will have a > hierarchical application structure wherein add-ons and tweaks for specific > customers are possible without affecting the core "generic" site code base > (neither will you have to copy that code base for each application). In this > way, you can maintain a core application code base that every client uses, > while still providing flexibility for paid add-ons or site-specific needs. > > The directory structure of the Generic application is just like a normal > Rails application, with one additional directory: the "sites" directory. So > it looks something like this: > > RAILS_ROOT/ > app/ > controllers/ > views/ > (etc.) > public/ > sites/ > best_ever_adoptions_co_inc/ > app/ > controllers/ > views/ > public/ > yet_another_adoption_co/ > app/ > controllers/ > views/ > public/ > > If you put a file called, for example, welcome_controller.rb in > RAILS_ROOT/app/controllers, then *all* of your sites will access that > controller as normal *unless* you put a file with the same name in the > site-specific controllers folder. In that case, the RAILS_ROOT > welcome_controller.rb will be loaded, and then the WelcomeController class > will be *reopened* (yay for Ruby!) by the site-specific > welcome_controller.rb (say, for example, in > RAILS_ROOT/sites/yet_another_adoption_co/app/controllers/) and modified as > needed. For example, you could override the "index" method to do a redirect, > or you could add a before_filter to make the controller require a login, > just for that one client. > > Views, layouts and partials act similarly--however, they simply override > their generic counterparts. For example, if you have an index.rhtml and a > _title.rhtml in RAILS_ROOT/app/views/welcome/ and supposing this > index.rhtml has a <%= render :partial => "title" %> in its code, then the > _title partial will be rendered in place. Now, however, let''s say that we > put a _title.rhtml partial in > RAILS_ROOT/sites/yet_another_adoption_co/app/views/welcome/. In that case, > our generic index.rhtml will load the site-specific _title partial in > place. Hierarchical customizations in a jiffy. > > To accomplish this feat, the following (remarkably few) changes will be > necessary: > 1. Create the RAILS_ROOT/sites folder and any client directory structures > within it. > 2. Modify your environment.rb file as follows: > a. Find the section where most of the core rails libraries are ''require''d, > e.g.: > require ''active_support'' > require ''active_record'' > require ''action_controller'' > require ''action_mailer'' > require ''action_web_service'' > > ... and add this to the end (note that it is important that this require > occurs after the core rails libraries are required but before the next > ActiveRecord::Base.configurations): > > require ''productize'' > > b. Replace the following line > ActiveRecord::Base.configurations > File.open("#{RAILS_ROOT}/config/database.yml") { |f| YAML::load(f) } > with: > ActiveRecord::Base.configurations = > YAML::load(ERB.new((IO.read("#{RAILS_ROOT}/config/database.yml"))).result) > > 3. Create the following ''productize.rb'' file in your RAILS_ROOT/lib folder > (you may want to copy this email as documentation in the header as I did): > > # productize.rb > > SITE = ENV[''site''] || ''yet_another_adoption_co'' > SITE_ROOT = File.join(RAILS_ROOT, ''sites'', SITE) > module Dependencies > def require_or_load(file_name) > file_name = "#{file_name}.rb" unless ! load? || file_name[-3..-1] == ''.rb'' > load? ? load(file_name) : require(file_name) > if file_name.include? ''controller'' > file_name = File.join(SITE_ROOT, ''app'', ''controllers'', File.basename > (file_name)) > if File.exist? file_name > load? ? load(file_name) : require(file_name) > end > end > end > end > > module ActionView > class Base > private > def full_template_path(template_path, extension) > # Check to see if the partial exists in our ''sites'' folder first > site_specific_path = File.join(SITE_ROOT, ''app'', ''views'', template_path + > ''.'' + extension) > > if File.exist?(site_specific_path) > site_specific_path > else > "#{@base_path}/#{template_path}.#{extension}" > end > end > end > end > > 4. Modify your database.yml like so: > development: > adapter: mysql > database: <%= SITE %>_dev > host: localhost > username: root > password: > > test: > adapter: mysql > database: <%= SITE %>_test > host: localhost > username: root > password: > > production: > adapter: mysql > database: <%= SITE %> > host: localhost > username: root > password: > > 5. In your Apache or Lighttpd config, create a FastCgiServer for each > client application that will be using your generic application (i.e. each > directory in the RAILS_ROOT/sites/ directory needs to have a VirtualHost set > up to use the public/ folder in each site). The dispatcher for your FastCGI > server should be set to the generic RAILS_ROOT/public/dispatcher.fcgi > script. And finally, use the appropriate set-env directive on the > FastCgiServer configuration to make the environment variable "site" equal to > the client name (i.e. the client''s name is used both as the prefix for > your database names (e.g. yet_another_adoption_site becomes > yet_another_adoption_site_dev) and as the directory name in the sites/ > directory). > > This little bit of set-up can give you a lot of pay back! > NOTE: I haven''t done step 5 yet, so I don''t have the same level of detail > in the instructions. I''ll post that later if there is interest. > > Duane Johnson > (canadaduane) > > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > > >_______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
On Jul 12, 2005, at 11:36 AM, Duane Johnson wrote:> I''m not sure if there''s interest in this approach to development, > but I''ve put together the changes necessary to make your Rails > application in to a "product".<snip a bunch of cool stuff> Hey Duane- Thanks for this tutorial it''s just hat I need. Also thank you for the raildock site, you''ve increased my productivity on multiple levels so yay for you!! Thanks- -Ezra Zygmuntowicz Yakima Herald-Republic WebMaster 509-577-7732 ezra-gdxLOakOTQ9oetBuM9ipNAC/G2K4zDHf@public.gmane.org
Very nice writeup. I have done something similiar for my day to day PHP work. Whenever I add another feature in the base system, *puuff*, and every client site can use it immediately. Thx Sascha
Duane, you''re my hero. I had a need for _exactly_ this functionality and was about to have a go at implementing it. Who knew it was going to be so simple. :) Thanks! -Mark
On 13/07/2005, at 4:36 AM, Duane Johnson wrote:> I''m not sure if there''s interest in this approach to development, but > I''ve put together the changes necessary to make your Rails application > in to a "product".Very nice. With a bunch of custom rake tasks to help manage things this could be a very sweet setup. One handy rake task would be for running AR migrations from the base app across all site dbs. Also, the nice thing about using an environment variable is that all the scripts probably still work -- just set your shell env variable to whatever the site name is before running them. - tim lucas
On Jul 12, 2005, at 8:00 PM, Tim Lucas wrote:> With a bunch of custom rake tasks to help manage things this could > be a very sweet setup. > > One handy rake task would be for running AR migrations from the > base app across all site dbs. > > Also, the nice thing about using an environment variable is that > all the scripts probably still work -- just set your shell env > variable to whatever the site name is before running them. > > - tim lucasThese are some excellent ideas. I hadn''t even considered using the environment variable in the shell. I was just considering how to tackle the migrations issues, and this very well may be the best choice. I''m also thinking that it would be nice to separate the generic migrations from the site-specific migrations--maybe by putting a ''db'' and ''db/migrations'' folder in each SITE_ROOT folder so that ''rake migrate'' if called from RAILS_ROOT would run the migration scripts for all databases (as you suggest) or if run from SITE_ROOT, would run only the site-specific migration scripts and affect only that specific site. There would be some version numbering problems to figure out in that case, however. Perhaps adding another field in the schema_info table would be all that is required (e.g. ''version'' and ''site_version''). Another potential feature (for unix systems, at least) is the use of symbolic links in the site-specific controllers and views directories. A "superadmin" application could be built along side the productized application in which you (the superadmin) would be able to turn on and off certain features simply by adding or removing symlinks. Lastly, I was also thinking about how nice a generator would be for this... $ rails_product adoptions create create app/apis create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create site etc. Any volunteers? :) Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Mark Imbriaco <mark.imbriaco@...> writes:> Duane, you''re my hero. I had a need for _exactly_ this functionality and was > about to have a go at implementing it. Who knew it was going to be so simple.Actually, I lied. My requirement is slightly different, but it should be simple for me to adapt your approach. Basically, we have an application that has about 90% of the functionality in common across each of the "products", and shares a single database, but is skinned differently for each product and has some minor differences in the business logic. I want to adapt your approach to determine the site name automatically based on the hostname that it was called with (or the Host header). It should be a fairly straighforward change, and if there is interest in this approach I''ll be happy to share the code back. Thanks again for the head start. -Mark
Mark, this is similar to what I need to do down the road in a month. Please share the code back if you can. Duane, awesome write-up and development. Thanks Cheers, Brett On Jul 13, 2005, at 10:24 AM, Mark Imbriaco wrote:> Mark Imbriaco <mark.imbriaco@...> writes: > >> Duane, you''re my hero. I had a need for _exactly_ this >> functionality and was >> about to have a go at implementing it. Who knew it was going to >> be so simple. >> > > Actually, I lied. My requirement is slightly different, but it > should be simple > for me to adapt your approach. Basically, we have an application > that has about > 90% of the functionality in common across each of the "products", > and shares a > single database, but is skinned differently for each product and > has some minor > differences in the business logic. I want to adapt your approach > to determine > the site name automatically based on the hostname that it was > called with (or > the Host header). It should be a fairly straighforward change, and > if there is > interest in this approach I''ll be happy to share the code back. > > Thanks again for the head start. > > -Mark > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Congratulations Duane, It is really very good and util. I not understand how can I access the public folder of each site, like: "/sites/<%= SITE %>/public/myimage.jpg" Someone do the step 5 with success and can detail it please? Thank you!!!! -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035> > Assunto: > [Rails] [REUSE] Productize your application > De: > Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Data: > Tue, 12 Jul 2005 12:36:38 -0600 > Para: > rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > Para: > rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > > ...> 5. In your Apache or Lighttpd config, create a FastCgiServer for each > client application that will be using your generic application (i.e. > each directory in the RAILS_ROOT/sites/ directory needs to have a > VirtualHost set up to use the public/ folder in each site). The > dispatcher for your FastCGI server should be set to the generic > RAILS_ROOT/public/dispatcher.fcgi script. And finally, use the > appropriate set-env directive on the FastCgiServer configuration to > make the environment variable "site" equal to the client name (i.e. > the client''s name is used both as the prefix for your database names > (e.g. yet_another_adoption_site becomes yet_another_adoption_site_dev) > and as the directory name in the sites/ directory). > > This little bit of set-up can give you a lot of pay back! > > NOTE: I haven''t done step 5 yet, so I don''t have the same level of > detail in the instructions. I''ll post that later if there is interest. > > Duane Johnson > (canadaduane)
Pedro, The rails_product and site_generator gems are now available, and much more complete than my original instructions. I suggest downloading that--you''ll find some sample apache config files and also a modified webrick which *should* let you access your public folder, both the shared (base application) public folder and the second-tier (sites) public folders. On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote:> Congratulations Duane, > It is really very good and util. > > I not understand how can I access the public folder of each site, > like: "/sites/<%= SITE %>/public/myimage.jpg" > Someone do the step 5 with success and can detail it please? > > Thank you!!!! > > -- > > Pedro C. Valentini > pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > +55 (21) 8708-8035 > > >> >> Assunto: >> [Rails] [REUSE] Productize your application >> De: >> Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> Data: >> Tue, 12 Jul 2005 12:36:38 -0600 >> Para: >> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> >> Para: >> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> >> >> ... >> > > >> 5. In your Apache or Lighttpd config, create a FastCgiServer for >> each client application that will be using your generic >> application (i.e. each directory in the RAILS_ROOT/sites/ >> directory needs to have a VirtualHost set up to use the public/ >> folder in each site). The dispatcher for your FastCGI server >> should be set to the generic RAILS_ROOT/public/dispatcher.fcgi >> script. And finally, use the appropriate set-env directive on the >> FastCgiServer configuration to make the environment variable >> "site" equal to the client name (i.e. the client''s name is used >> both as the prefix for your database names (e.g. >> yet_another_adoption_site becomes yet_another_adoption_site_dev) >> and as the directory name in the sites/ directory). >> >> This little bit of set-up can give you a lot of pay back! >> >> NOTE: I haven''t done step 5 yet, so I don''t have the same level of >> detail in the instructions. I''ll post that later if there is >> interest. >> >> Duane Johnson >> (canadaduane) >> > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Duane Johnson (canadaduane)
Is it just me, or does the site-specific app/views/layouts/ application.rhtml get ignored? I tried using the new gems today, and I found that I could only get the _site_ default layout by specifying "layout ''application''" in application.rb. Is this a bug, intended behavior, or user error? :) Other than that, this code is quite nice. Thanks, Duane! On Aug 9, 2005, at 8:10 PM, Duane Johnson wrote:> Pedro, > > The rails_product and site_generator gems are now available, and > much more complete than my original instructions. I suggest > downloading that--you''ll find some sample apache config files and > also a modified webrick which *should* let you access your public > folder, both the shared (base application) public folder and the > second-tier (sites) public folders. > > On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: > > >> Congratulations Duane, >> It is really very good and util. >> >> I not understand how can I access the public folder of each site, >> like: "/sites/<%= SITE %>/public/myimage.jpg" >> Someone do the step 5 with success and can detail it please? >> >> Thank you!!!! >> >> -- >> >> Pedro C. Valentini >> pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >> +55 (21) 8708-8035 >> >> >> >>> >>> Assunto: >>> [Rails] [REUSE] Productize your application >>> De: >>> Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> Data: >>> Tue, 12 Jul 2005 12:36:38 -0600 >>> Para: >>> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> >>> Para: >>> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> >>> >>> ... >>> >>> >> >> >> >>> 5. In your Apache or Lighttpd config, create a FastCgiServer for >>> each client application that will be using your generic >>> application (i.e. each directory in the RAILS_ROOT/sites/ >>> directory needs to have a VirtualHost set up to use the public/ >>> folder in each site). The dispatcher for your FastCGI server >>> should be set to the generic RAILS_ROOT/public/dispatcher.fcgi >>> script. And finally, use the appropriate set-env directive on >>> the FastCgiServer configuration to make the environment variable >>> "site" equal to the client name (i.e. the client''s name is used >>> both as the prefix for your database names (e.g. >>> yet_another_adoption_site becomes yet_another_adoption_site_dev) >>> and as the directory name in the sites/ directory). >>> >>> This little bit of set-up can give you a lot of pay back! >>> >>> NOTE: I haven''t done step 5 yet, so I don''t have the same level >>> of detail in the instructions. I''ll post that later if there is >>> interest. >>> >>> Duane Johnson >>> (canadaduane) >>> >>> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > > Duane Johnson > (canadaduane) > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi Duane, The example files make sense. One issue I have with the gem: the database configuration is coupled to the SITE variable, which will cause problems for us. Here''s the scenario: I have a shared host. My username is bobsdiscountauto. I have one database on a shared server for all my domains and my username is necessary as a prefix. What happens when I want to put bobsexpensiveporches.com up? I''ll have to change the database config and end up repeating myself each time I build a new productized application. What I''d like is the ability to name each product with the domain name (an unlikely invariant) and configure a map from names to database prefixes. What do you think? Ben On Aug 10, 2005, at 12:10 AM, Duane Johnson wrote:> Pedro, > > The rails_product and site_generator gems are now available, and much > more complete than my original instructions. I suggest downloading > that--you''ll find some sample apache config files and also a modified > webrick which *should* let you access your public folder, both the > shared (base application) public folder and the second-tier (sites) > public folders. > > On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: > >> Congratulations Duane, >> It is really very good and util. >> >> I not understand how can I access the public folder of each site, >> like: "/sites/<%= SITE %>/public/myimage.jpg" >> Someone do the step 5 with success and can detail it please? >> >> Thank you!!!! >> >> -- >> >> Pedro C. Valentini >> pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >> +55 (21) 8708-8035 >> >> >>> >>> Assunto: >>> [Rails] [REUSE] Productize your application >>> De: >>> Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>> Data: >>> Tue, 12 Jul 2005 12:36:38 -0600 >>> Para: >>> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> >>> Para: >>> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> >>> >>> ... >>> >> >> >>> 5. In your Apache or Lighttpd config, create a FastCgiServer for >>> each client application that will be using your generic application >>> (i.e. each directory in the RAILS_ROOT/sites/ directory needs to >>> have a VirtualHost set up to use the public/ folder in each site). >>> The dispatcher for your FastCGI server should be set to the generic >>> RAILS_ROOT/public/dispatcher.fcgi script. And finally, use the >>> appropriate set-env directive on the FastCgiServer configuration to >>> make the environment variable "site" equal to the client name (i.e. >>> the client''s name is used both as the prefix for your database names >>> (e.g. yet_another_adoption_site becomes >>> yet_another_adoption_site_dev) and as the directory name in the >>> sites/ directory). >>> >>> This little bit of set-up can give you a lot of pay back! >>> >>> NOTE: I haven''t done step 5 yet, so I don''t have the same level of >>> detail in the instructions. I''ll post that later if there is >>> interest. >>> >>> Duane Johnson >>> (canadaduane) >>> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > Duane Johnson > (canadaduane) > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >___________________ Ben Jackson Diretor de Desenvolvimento +55 (21) 9997-0593 ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org http://www.incomumdesign.com
On Aug 10, 2005, at 12:22 PM, Benjamin Jackson wrote:> Hi Duane, > > The example files make sense. One issue I have with the gem: the > database configuration is coupled to the SITE variable, which will > cause problems for us. Here''s the scenario: > > I have a shared host. My username is bobsdiscountauto. I have one > database on a shared server for all my domains and my username is > necessary as a prefix. What happens when I want to put > bobsexpensiveporches.com up? I''ll have to change the database > config and end up repeating myself each time I build a new > productized application.> What I''d like is the ability to name each product with the domain > name (an unlikely invariant) and configure a map from names to > database prefixes. What do you think? >So you have only one database--does that mean you''re trying to prefix the *tables* within that database? I''m a little confused about what needs to be prefixed. If it''s the tables that need to be prefixed, then I suggest making a module that you can mixin to each of your ActiveRecord model classes-- when the module is mixed in, use the append_features method to set the table_name according to the SITE environment variable. Then just take out the references to SITE in your database.yml file since they are no longer relevant. How does that sound in your situation? Duane Johnson (canadaduane)
> So you have only one database--does that mean you''re trying to prefix > the *tables* within that database? I''m a little confused about what > needs to be prefixed. >Sorry, didn''t make that clear enough. No, but all database names must start with myusername_ prefix to prevent name clashes on the shared server.> > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >___________________ Ben Jackson Diretor de Desenvolvimento +55 (21) 9997-0593 ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org http://www.incomumdesign.com
Benjamin Jackson wrote:> >> So you have only one database--does that mean you''re trying to prefix >> the *tables* within that database? I''m a little confused about what >> needs to be prefixed. >> > > Sorry, didn''t make that clear enough. No, but all database names must > start with myusername_ prefix to prevent name clashes on the shared server.Why can''t you just do: # config/database.yml development: adapter: mysql host: db.somehostingcompany.com database: myusername_<%= SITE %> username: myusername password: mypassword For that matter, you can do more complex mappings from within database.yml, e.g. <% DBMAP = { ''bobsdiscountauto'' => ["dbhost", "benjackson_bobsdiscountauto", "benjackson", "password1"], ''bobsexpensiveporches'' => ["dbhost", "benjackson_bobsexpensiveporches", "benjackson", "password1"], ''crazyjohnsusedautos'' => ["dbx", "bj_crazyjohn", "bjackson", "password4"], ''crazyautosusedjohns'' => ["dby", "bj_crazyauto", "bj", "password3"], } raise "Unknown site \"#{SITE}\"" if DBMAP[SITE].nil? host, database, username, password = DBMAP[SITE] %> development: host: <%= host %> database: <%= database %> username: <%= username %> password: <%= pasword %> -- Steve
Thank you, I install the rails_product and site_generator. But I have my application and many modifications include files like environment.rb The question is: What files the rails_product change of an normal rails generator? There is an documentation? I didn''t find it. Thank you Duane Johnson escreveu:> > On Aug 10, 2005, at 12:22 PM, Benjamin Jackson wrote: > >> Hi Duane, >> >> The example files make sense. One issue I have with the gem: the >> database configuration is coupled to the SITE variable, which will >> cause problems for us. Here''s the scenario: >> >> I have a shared host. My username is bobsdiscountauto. I have one >> database on a shared server for all my domains and my username is >> necessary as a prefix. What happens when I want to put >> bobsexpensiveporches.com up? I''ll have to change the database config >> and end up repeating myself each time I build a new productized >> application. > > >> What I''d like is the ability to name each product with the domain >> name (an unlikely invariant) and configure a map from names to >> database prefixes. What do you think? >> > So you have only one database--does that mean you''re trying to prefix > the *tables* within that database? I''m a little confused about what > needs to be prefixed. > > If it''s the tables that need to be prefixed, then I suggest making a > module that you can mixin to each of your ActiveRecord model classes-- > when the module is mixed in, use the append_features method to set > the table_name according to the SITE environment variable. Then just > take out the references to SITE in your database.yml file since they > are no longer relevant. > > How does that sound in your situation? > > Duane Johnson > (canadaduane) > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
On Aug 9, 2005, at 9:23 PM, Benjamin Curtis wrote:> Is it just me, or does the site-specific app/views/layouts/ > application.rhtml get ignored? I tried using the new gems today, > and I found that I could only get the _site_ default layout by > specifying "layout ''application''" in application.rb. Is this a > bug, intended behavior, or user error? :) >It appears you''ve found a bug :) As it is right now, it looks like the render code is checking to see if an ''application.rhtml'' file exists within the base application''s public folder. If it doesn''t find it there, then no further checking is performed. As a work-around, create an empty ''application.rhtml'' file in your base application app/views/layouts. If things work out as they did for me, you''ll then be able to add second-tier application.rhtml files (to your individual sites). The second-tier layout files will then be able to override their base application counterparts.> Other than that, this code is quite nice. Thanks, Duane! >Thanks, and especially thank-you for your help. I''ll be releasing a new version soon with the bug fixes and helpful hints that you and others have provided. Duane Johnson (canadaduane)
> Why can''t you just do: > > # config/database.yml > development: > adapter: mysql > host: db.somehostingcompany.com > database: myusername_<%= SITE %> > username: myusername > password: mypassword >That would work fine. My point was more concerned with the underlying assumptions of the script than the feasibility of a workaround. After all, if I have to change the DB config every time I productize an app, I''ll be repeating myself ;) ___________________ Ben Jackson Diretor de Desenvolvimento +55 (21) 9997-0593 ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org http://www.incomumdesign.com
> Pedro, > > The rails_product and site_generator gems are now available, and much > more complete than my original instructions. I suggest downloading > that--you''ll find some sample apache config files and also a modified > webrick which *should* let you access your public folder, both the > shared (base application) public folder and the second-tier (sites) > public folders. > > On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: >Configuring with lighttpd: $HTTP["host"] =~ "cms" { server.document-root = "/var/www/sites/cms/sites/incomumdesign.com/public" server.error-handler-404 = "/var/www/sites/cms/public/dispatch.fcgi" fastcgi.server = ( ".fcgi" => ("cms" => ( "socket" => "/var/www/sites/cms/sites/incomumdesign.com/public/lighttpd- fcgi.socket", "bin-path" => "/var/www/sites/cms/public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "development", "SITE" => "incomumdesign.com" ), ) ) ) } And getting a 404 on entering the site. Any ideas? Ben ___________________ Ben Jackson Diretor de Desenvolvimento +55 (21) 9997-0593 ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org http://www.incomumdesign.com
On Aug 10, 2005, at 4:16 PM, Benjamin Jackson wrote:>> Pedro, >> >> The rails_product and site_generator gems are now available, and >> much more complete than my original instructions. I suggest >> downloading that--you''ll find some sample apache config files and >> also a modified webrick which *should* let you access your public >> folder, both the shared (base application) public folder and the >> second-tier (sites) public folders. >> >> On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: >> >> > > Configuring with lighttpd: > > $HTTP["host"] =~ "cms" { > server.document-root = "/var/www/sites/cms/sites/ > incomumdesign.com/public" > server.error-handler-404 = "/var/www/sites/cms/public/ > dispatch.fcgi" > fastcgi.server = ( ".fcgi" => > ("cms" => > ( "socket" => "/var/www/sites/cms/ > sites/incomumdesign.com/public/lighttpd-fcgi.socket", > "bin-path" => "/var/www/sites/ > cms/public/dispatch.fcgi", > "bin-environment" => ( > "RAILS_ENV" => "development", > "SITE" => "incomumdesign.com" > ), > ) > ) > ) > } > > And getting a 404 on entering the site. Any ideas? >I''m not a Lighttpd guru; however, doesn''t the HTTP["host"] regular expression match that you do at the beginning require that the host (e.g. "incomumdesign.com") match the regexp "cms"? It seems to me that it will never match... maybe that''s it?> Ben > > ___________________ > Ben Jackson > Diretor de Desenvolvimento > > +55 (21) 9997-0593 > ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > http://www.incomumdesign.com > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >Duane Johnson (canadaduane)
Duane Johnson wrote:> > On Aug 10, 2005, at 4:16 PM, Benjamin Jackson wrote: > >>> Pedro, >>> >>> The rails_product and site_generator gems are now available, and >>> much more complete than my original instructions. I suggest >>> downloading that--you''ll find some sample apache config files and >>> also a modified webrick which *should* let you access your public >>> folder, both the shared (base application) public folder and the >>> second-tier (sites) public folders. >>> >>> On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: >>> >>> >> >> Configuring with lighttpd: >> >> $HTTP["host"] =~ "cms" { >> server.document-root = "/var/www/sites/cms/sites/ >> incomumdesign.com/public" >> server.error-handler-404 = "/var/www/sites/cms/public/ >> dispatch.fcgi" >> fastcgi.server = ( ".fcgi" => >> ("cms" => >> ( "socket" => "/var/www/sites/cms/ >> sites/incomumdesign.com/public/lighttpd-fcgi.socket", >> "bin-path" => "/var/www/sites/ >> cms/public/dispatch.fcgi", >> "bin-environment" => ( >> "RAILS_ENV" => "development", >> "SITE" => "incomumdesign.com" >> ), >> ) >> ) >> ) >> } >> >> And getting a 404 on entering the site. Any ideas? >> > I''m not a Lighttpd guru; however, doesn''t the HTTP["host"] regular > expression match that you do at the beginning require that the host > (e.g. "incomumdesign.com") match the regexp "cms"? It seems to me > that it will never match... maybe that''s it?Not exactly :-) It will match any host that contains "cms". I think this should be better, to match any host that starts w/ "cms" (cms.incomumdesign.com[.br]), but not "www.mycmsproduct.com" ;-) $HTTP["host"] =~ "^(cms\.)" If the only possible host is "cms.incomumdesign.com", the best solution (to me) is: $HTTP["host"] =~ "^(cms\.incomumdesign\.com)$" hth juraci krohling costa juca at jkcosta dot info http://jkcosta.info>> Ben >> >> ___________________ >> Ben Jackson >> Diretor de Desenvolvimento >> >> +55 (21) 9997-0593 >> ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >> http://www.incomumdesign.com >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > Duane Johnson > (canadaduane) > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
or simple: $HTTP["host"] = "cms.incomumdesign.com" and leave the regex out of it. dont beat up the processor to much ;) On 8/10/05, Juraci Krohling Costa <juca-+BZ7G6WzYWuZuzBka8ofvg@public.gmane.org> wrote:> > > Duane Johnson wrote: > > > > > On Aug 10, 2005, at 4:16 PM, Benjamin Jackson wrote: > > > >>> Pedro, > >>> > >>> The rails_product and site_generator gems are now available, and > >>> much more complete than my original instructions. I suggest > >>> downloading that--you''ll find some sample apache config files and > >>> also a modified webrick which *should* let you access your public > >>> folder, both the shared (base application) public folder and the > >>> second-tier (sites) public folders. > >>> > >>> On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: > >>> > >>> > >> > >> Configuring with lighttpd: > >> > >> $HTTP["host"] =~ "cms" { > >> server.document-root = "/var/www/sites/cms/sites/ > >> incomumdesign.com/public" > >> server.error-handler-404 = "/var/www/sites/cms/public/ > >> dispatch.fcgi" > >> fastcgi.server = ( ".fcgi" => > >> ("cms" => > >> ( "socket" => "/var/www/sites/cms/ > >> sites/incomumdesign.com/public/lighttpd-fcgi.socket", > >> "bin-path" => "/var/www/sites/ > >> cms/public/dispatch.fcgi", > >> "bin-environment" => ( > >> "RAILS_ENV" => "development", > >> "SITE" => "incomumdesign.com" > >> ), > >> ) > >> ) > >> ) > >> } > >> > >> And getting a 404 on entering the site. Any ideas? > >> > > I''m not a Lighttpd guru; however, doesn''t the HTTP["host"] regular > > expression match that you do at the beginning require that the host > > (e.g. "incomumdesign.com") match the regexp "cms"? It seems to me > > that it will never match... maybe that''s it? > > > Not exactly :-) It will match any host that contains "cms". I think this > should be better, to match any host that starts w/ "cms" > (cms.incomumdesign.com[.br]), but not "www.mycmsproduct.com" ;-) > $HTTP["host"] =~ "^(cms\.)" > > If the only possible host is "cms.incomumdesign.com", the best solution > (to me) is: > $HTTP["host"] =~ "^(cms\.incomumdesign\.com)$" > > hth > juraci krohling costa > juca at jkcosta dot info > http://jkcosta.info > > >> Ben > >> > >> ___________________ > >> Ben Jackson > >> Diretor de Desenvolvimento > >> > >> +55 (21) 9997-0593 > >> ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > >> http://www.incomumdesign.com > >> > >> _______________________________________________ > >> Rails mailing list > >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > >> http://lists.rubyonrails.org/mailman/listinfo/rails > >> > > > > Duane Johnson > > (canadaduane) > > > > > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- Zachery Hostens <zacheryph-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
> I''m not a Lighttpd guru; however, doesn''t the HTTP["host"] regular > expression match that you do at the beginning require that the host > (e.g. "incomumdesign.com") match the regexp "cms"? It seems to me > that it will never match... maybe that''s it?This is on my local box using names specified in /etc/hosts ___________________ Ben Jackson Diretor de Desenvolvimento +55 (21) 9997-0593 ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org http://www.incomumdesign.com
Pedro Valentini
2005-Aug-11 18:36 UTC
[REUSE] Productize your application - Lighttpd and TD Config
Hi, Someone have an exemple of lighttpd configuration to use rails_product? I''m trying to configure it in textdrive. Pedro -- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Rick Olson
2005-Aug-11 19:26 UTC
Re: [REUSE] Productize your application - Lighttpd and TD Config
On 8/11/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote:> Hi, > > Someone have an exemple of lighttpd configuration to use rails_product? > I''m trying to configure it in textdrive. > > PedroTry this, it was loads of help: http://manuals.textdrive.com/read/book/9 -- rick http://techno-weenie.net
Pedro Valentini
2005-Aug-15 22:55 UTC
Re: [REUSE] Productize your application - Lighttpd and TD Config
Hi, It is really very good but don''t sad nothing about rails_product and how to setup 2 public folders using lighttpd. No body have configured rails_product in textdrive with lighttpd?? If yes can send one exemple of configuration, I''m trying but don''t understand how can I have 2 public folders and find one file in myapp/public and if not found find in /myapp/sites/mysite/public Thank''s Pedro Rick Olson escreveu:>On 8/11/05, Pedro Valentini <pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org> wrote: > > >>Hi, >> >>Someone have an exemple of lighttpd configuration to use rails_product? >>I''m trying to configure it in textdrive. >> >>Pedro >> >> > >Try this, it was loads of help: http://manuals.textdrive.com/read/book/9 > > > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Hi, Can you help me to translate the httpd.conf to lighttpd.conf ??? The apache config it: <Directory "/Products/generic_cart/sites/client_co/public/"> AllowOverride All </Directory> <VirtualHost *:80> ServerName www.example.com DocumentRoot /Products/generic_cart/sites/client_co/public/ Alias /generic /Products/generic_cart/public/ </VirtualHost> How I make the same configuration in lighttpd ??? When someone acess an image for exemple the rails_product will find it in /Products/generic_cart/sites/client_co/public/ and if not found it will find the image in /Products/generic_cart/public/ automaticaly?? Thank you Duane Johnson escreveu:> > On Aug 10, 2005, at 4:16 PM, Benjamin Jackson wrote: > >>> Pedro, >>> >>> The rails_product and site_generator gems are now available, and >>> much more complete than my original instructions. I suggest >>> downloading that--you''ll find some sample apache config files and >>> also a modified webrick which *should* let you access your public >>> folder, both the shared (base application) public folder and the >>> second-tier (sites) public folders. >>> >>> On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: >>> >>> >> >> Configuring with lighttpd: >> >> $HTTP["host"] =~ "cms" { >> server.document-root = "/var/www/sites/cms/sites/ >> incomumdesign.com/public" >> server.error-handler-404 = "/var/www/sites/cms/public/ >> dispatch.fcgi" >> fastcgi.server = ( ".fcgi" => >> ("cms" => >> ( "socket" => "/var/www/sites/cms/ >> sites/incomumdesign.com/public/lighttpd-fcgi.socket", >> "bin-path" => "/var/www/sites/ >> cms/public/dispatch.fcgi", >> "bin-environment" => ( >> "RAILS_ENV" => "development", >> "SITE" => "incomumdesign.com" >> ), >> ) >> ) >> ) >> } >> >> And getting a 404 on entering the site. Any ideas? >> > I''m not a Lighttpd guru; however, doesn''t the HTTP["host"] regular > expression match that you do at the beginning require that the host > (e.g. "incomumdesign.com") match the regexp "cms"? It seems to me > that it will never match... maybe that''s it? > >> Ben >> >> ___________________ >> Ben Jackson >> Diretor de Desenvolvimento >> >> +55 (21) 9997-0593 >> ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >> http://www.incomumdesign.com >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> > > Duane Johnson > (canadaduane) > > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >-- Pedro C. Valentini pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org +55 (21) 8708-8035
Duane Johnson
2005-Aug-22 22:33 UTC
Lighttpd config for rails_product (was Re: [REUSE] Productize your application)
On Aug 16, 2005, at 12:25 PM, Pedro Valentini wrote:> Hi, > Can you help me to translate the httpd.conf to lighttpd.conf ??? > > The apache config it: > <Directory "/Products/generic_cart/sites/client_co/public/"> > AllowOverride All > </Directory> > > <VirtualHost *:80> > ServerName www.example.com > DocumentRoot /Products/generic_cart/sites/client_co/public/ > Alias /generic /Products/generic_cart/public/ > </VirtualHost> > > How I make the same configuration in lighttpd ??? > When someone acess an image for exemple the rails_product will find > it in /Products/generic_cart/sites/client_co/public/ and if not > found it will find the image in /Products/generic_cart/public/ > automaticaly?? > > Thank you >Hi Pedro, I''m sending what I have right now for the Lighttpd config file, however it''s missing the mod_rewrite rules which would allow the automatic proxying of your resources (e.g. image files etc.). $HTTP["host"] == "client_co.com" { server.document-root = "/Products/generic_cart/public/" server.errorlog = "/Products/generic_cart/log/lighttpd- error.log" accesslog.filename = "/Products/generic_cart/log/lighttpd- access.log" url.rewrite = ( "^/$" => "index.html", "^([^.]+)$" => "$1.html" ) server.error-handler-404 = "/dispatch.fcgi" fastcgi.server = ( ".fcgi" => ( "client_co" => ( "socket" => "/tmp/client_co.socket", "bin-path" => "/Products/generic_cart/sites/client_co/ public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "production", "SITE" => "client_co" ), "min-procs" => 2, "max-procs" => 5, "idle-timeout" => 60 ) ) ) } This is untested at this point, but it should give you a starting point. Also note that it assumes all of the public resources (images etc.) reside in RAILS_ROOT/public. It does not do any fancy mod_rewrite stuff (as mentioned above). Duane Johnson (canadaduane) _______________________________________________ Rails mailing list Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Ben, I am about to do something similar. Here''s my case: * All my sites are to run using the exact same code. I don''t need the base app to change at all depending on what site is being used. * I want them all to be available via a vhost c-name. Like this: - site01.myhost.com - site02.myhost.com - site03.myhost.com * The only thing that differentiates them are that they run on separate databases, named as follows (according to the example above): - myhost_site01 - myhost_site01 - myhost_site01 So. To solve this I thought about the following procedure: 1: I need to get hold of the cname from apache. All hosts in *.myhost.com are to be triggered in the same vhost-section in the httpd.conf (apache). Set up that cname to be an environment-variable. (I am unsure how to do this though, especially since I am running fastcgi on apache, not only apache. If anyone knows I''m listening :) ) 2: Change environment.rb, line 58 like this: ActiveRecord::Base.configurations File.open("#{RAILS_ROOT}/config/database." + ENV[''MYHOST_SITE''] + ".yml") { |f| YAML::load(f) } This is to make sure that it reads the right database-definition file. In that file the real reference to the database is given. 3: In addition I need the logs to be prefixed too, so I''ll use the same technique as above to make sure I get different logs for different sites. ------------------------------------------------------------------------ /*Ronny Hanssen*/ Benjamin Jackson wrote:> Hi Duane, > > The example files make sense. One issue I have with the gem: the > database configuration is coupled to the SITE variable, which will cause > problems for us. Here''s the scenario: > > I have a shared host. My username is bobsdiscountauto. I have one > database on a shared server for all my domains and my username is > necessary as a prefix. What happens when I want to put > bobsexpensiveporches.com up? I''ll have to change the database config and > end up repeating myself each time I build a new productized application. > > What I''d like is the ability to name each product with the domain name > (an unlikely invariant) and configure a map from names to database > prefixes. What do you think? > > Ben > > On Aug 10, 2005, at 12:10 AM, Duane Johnson wrote: > >> Pedro, >> >> The rails_product and site_generator gems are now available, and much >> more complete than my original instructions. I suggest downloading >> that--you''ll find some sample apache config files and also a modified >> webrick which *should* let you access your public folder, both the >> shared (base application) public folder and the second-tier (sites) >> public folders. >> >> On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: >> >>> Congratulations Duane, >>> It is really very good and util. >>> >>> I not understand how can I access the public folder of each site, >>> like: "/sites/<%= SITE %>/public/myimage.jpg" >>> Someone do the step 5 with success and can detail it please? >>> >>> Thank you!!!! >>> >>> -- >>> >>> Pedro C. Valentini >>> pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>> +55 (21) 8708-8035 >>> >>> >>>> >>>> Assunto: >>>> [Rails] [REUSE] Productize your application >>>> De: >>>> Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>>> Data: >>>> Tue, 12 Jul 2005 12:36:38 -0600 >>>> Para: >>>> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> >>>> Para: >>>> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> >>>> >>>> ... >>>> >>> >>> >>>> 5. In your Apache or Lighttpd config, create a FastCgiServer for >>>> each client application that will be using your generic application >>>> (i.e. each directory in the RAILS_ROOT/sites/ directory needs to >>>> have a VirtualHost set up to use the public/ folder in each site). >>>> The dispatcher for your FastCGI server should be set to the generic >>>> RAILS_ROOT/public/dispatcher.fcgi script. And finally, use the >>>> appropriate set-env directive on the FastCgiServer configuration to >>>> make the environment variable "site" equal to the client name (i.e. >>>> the client''s name is used both as the prefix for your database names >>>> (e.g. yet_another_adoption_site becomes >>>> yet_another_adoption_site_dev) and as the directory name in the >>>> sites/ directory). >>>> >>>> This little bit of set-up can give you a lot of pay back! >>>> >>>> NOTE: I haven''t done step 5 yet, so I don''t have the same level of >>>> detail in the instructions. I''ll post that later if there is interest. >>>> >>>> Duane Johnson >>>> (canadaduane) >>>> >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >> >> Duane Johnson >> (canadaduane) >> >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails >> >> > ___________________ > Ben Jackson > Diretor de Desenvolvimento > > +55 (21) 9997-0593 > ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org > http://www.incomumdesign.com > > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hi Ronny, +2 for that one. Thanks :) - Ben On Aug 24, 2005, at 9:03 PM, Ronny Hanssen wrote:> Hi Ben, > > I am about to do something similar. Here''s my case: > > * All my sites are to run using the exact same code. I don''t need the > base app to change at all depending on what site is being used. > > * I want them all to be available via a vhost c-name. Like this: > - site01.myhost.com > - site02.myhost.com > - site03.myhost.com > > * The only thing that differentiates them are that they run on separate > databases, named as follows (according to the example above): > - myhost_site01 > - myhost_site01 > - myhost_site01 > > So. To solve this I thought about the following procedure: > > 1: I need to get hold of the cname from apache. All hosts in > *.myhost.com are to be triggered in the same vhost-section in the > httpd.conf (apache). Set up that cname to be an environment-variable. > (I > am unsure how to do this though, especially since I am running fastcgi > on apache, not only apache. If anyone knows I''m listening :) ) > > 2: Change environment.rb, line 58 like this: > ActiveRecord::Base.configurations > File.open("#{RAILS_ROOT}/config/database." + ENV[''MYHOST_SITE''] + > ".yml") { |f| YAML::load(f) } > > This is to make sure that it reads the right database-definition file. > In that file the real reference to the database is given. > > 3: In addition I need the logs to be prefixed too, so I''ll use the same > technique as above to make sure I get different logs for different > sites. > > ----------------------------------------------------------------------- > - > /*Ronny Hanssen*/ > > > Benjamin Jackson wrote: >> Hi Duane, >> >> The example files make sense. One issue I have with the gem: the >> database configuration is coupled to the SITE variable, which will >> cause >> problems for us. Here''s the scenario: >> >> I have a shared host. My username is bobsdiscountauto. I have one >> database on a shared server for all my domains and my username is >> necessary as a prefix. What happens when I want to put >> bobsexpensiveporches.com up? I''ll have to change the database config >> and >> end up repeating myself each time I build a new productized >> application. >> >> What I''d like is the ability to name each product with the domain name >> (an unlikely invariant) and configure a map from names to database >> prefixes. What do you think? >> >> Ben >> >> On Aug 10, 2005, at 12:10 AM, Duane Johnson wrote: >> >>> Pedro, >>> >>> The rails_product and site_generator gems are now available, and much >>> more complete than my original instructions. I suggest downloading >>> that--you''ll find some sample apache config files and also a modified >>> webrick which *should* let you access your public folder, both the >>> shared (base application) public folder and the second-tier (sites) >>> public folders. >>> >>> On Aug 9, 2005, at 3:47 PM, Pedro Valentini wrote: >>> >>>> Congratulations Duane, >>>> It is really very good and util. >>>> >>>> I not understand how can I access the public folder of each site, >>>> like: "/sites/<%= SITE %>/public/myimage.jpg" >>>> Someone do the step 5 with success and can detail it please? >>>> >>>> Thank you!!!! >>>> >>>> -- >>>> >>>> Pedro C. Valentini >>>> pedro-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >>>> +55 (21) 8708-8035 >>>> >>>> >>>>> >>>>> Assunto: >>>>> [Rails] [REUSE] Productize your application >>>>> De: >>>>> Duane Johnson <duane.johnson-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >>>>> Data: >>>>> Tue, 12 Jul 2005 12:36:38 -0600 >>>>> Para: >>>>> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>>> >>>>> Para: >>>>> rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>>> >>>>> >>>>> ... >>>>> >>>> >>>> >>>>> 5. In your Apache or Lighttpd config, create a FastCgiServer for >>>>> each client application that will be using your generic application >>>>> (i.e. each directory in the RAILS_ROOT/sites/ directory needs to >>>>> have a VirtualHost set up to use the public/ folder in each site). >>>>> The dispatcher for your FastCGI server should be set to the generic >>>>> RAILS_ROOT/public/dispatcher.fcgi script. And finally, use the >>>>> appropriate set-env directive on the FastCgiServer configuration to >>>>> make the environment variable "site" equal to the client name (i.e. >>>>> the client''s name is used both as the prefix for your database >>>>> names >>>>> (e.g. yet_another_adoption_site becomes >>>>> yet_another_adoption_site_dev) and as the directory name in the >>>>> sites/ directory). >>>>> >>>>> This little bit of set-up can give you a lot of pay back! >>>>> >>>>> NOTE: I haven''t done step 5 yet, so I don''t have the same level of >>>>> detail in the instructions. I''ll post that later if there is >>>>> interest. >>>>> >>>>> Duane Johnson >>>>> (canadaduane) >>>>> >>>> >>>> _______________________________________________ >>>> Rails mailing list >>>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>>> http://lists.rubyonrails.org/mailman/listinfo/rails >>>> >>> >>> Duane Johnson >>> (canadaduane) >>> >>> >>> _______________________________________________ >>> Rails mailing list >>> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >>> http://lists.rubyonrails.org/mailman/listinfo/rails >>> >>> >> ___________________ >> Ben Jackson >> Diretor de Desenvolvimento >> >> +55 (21) 9997-0593 >> ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org >> http://www.incomumdesign.com >> >> _______________________________________________ >> Rails mailing list >> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails > >___________________ Ben Jackson Diretor de Desenvolvimento +55 (21) 9997-0593 ben-p14LI7ZcAE/pVLaUnt/cCQC/G2K4zDHf@public.gmane.org http://www.incomumdesign.com