Integrating Ruby on Windows WAMP server so I can run Ruby and PHP at same time? - ruby

I've been searching on this but haven't found anything decisive so far.. I already have a windows WAMP server up and running and am using it for my PHP apps, I want to be able to run some small ruby scripts (to interact with a library that is not available in PHP), I don't even need Rails at this point, I just want to run ruby scripts and be able to run them from within a web browser type environment (like PHP) but I can't figure out how to do this since the "instant rails" takes the same resources of php and apache so it can't run at the same time unless I change the port but I'd rather just make it so it runs off the same apache as my PHP apps ( I don't even need a database at this point as thats all handled in my php apps).. any advice is appreciated

Seeing that you have accepted the answer from your other question: you won't be able to run a ruby TCP server on port X and Apache on the same port.
On the other hand if you decide to use Rails: Install InstantRails but don't start it. Copy the portion of Apache config (in InstantRails directory) that binds rails to Apache and edit it to handle everything under (for eample) /rails then paste it into your Apache config that runs PHP. You may have to fiddle with paths (PATH variable). This way you'll have Apache running on port X, all *.php will go to your PHP interpreter and everything under (for example) /rails will go to Rails/Ruby

Related

Create stand-alone system services in Ruby

I want to build application which servers as a stand-alone system service, always run on the backend and servers a front-end with a web interface.
Like we do in Linux /etc/init.d/apache2 start , Same as I want to server my application /etc/init.d/myapp start.
My major target is to deliver on Linux specially Ubuntu, whole app would be in plain Ruby and front-end would be in Sinatra.
I want to make it install with simple, gem install my_app and command line features get available to start the service. The application would be doing heavily processing and database insertion. And I want that its configurations must be set as in pure linux fashion, like /etc/apache2/apache2.conf
Can any one guide me in it? Also if possible, i want to secure the code, is there any possibilities for it?
I am using the Daemon-Kit gem for the same requirements. Works very well in production. The only thing it does not include is the configuration with a .conf file, but it's easy to do it yourself with Ruby code. You can deploy with Capistrano, no need to install.

Rails app + caching and environment modes

I just finished setting up a Rackspace Cloud Server to host a website I'm going to build using Ruby on Rails. I've installed the latest versions of Apache, Rails, and Passenger (although to be honest, I'm not quite sure what Passenger gets me) - (I just checked, and Passenger doesn't come up in a gem list, but it is present in mods-enabled).
I've got everything set up, and I can get simple routes working with the appropriate controllers and views.
The problem I'm having is that it I can only see changes to a view after restarting Apache, so I assume some sort of caching is going on. I've followed several tips on SO for how to make sure I'm running in development mode, but nothing seems to work. I've placed a statement in my Apache config file, as well as in my Rails app's environment.rb file.
1) How can I see which mode I'm currently in?
2) How do I change it to whatever I need it to be?
Also, a lot of answers I'm finding are presuming that you're running your app in script/console mode. I'm working directly on the server via ssh, and I haven't ever had to turn my rails app on using script/console. It's just there and running.
Thanks
Update: If I print out Rails.env in a view, it lists production. If I fire up rails console on the command line, and print out Rails.env, it lists development.
Without seeing how you set the environment, this is the best advice I can give you.
<VirtualHost *>
ServerName example.com
DocumentRoot /home/yourname/htdocs/example.com/public
RailsEnv development
//Plus whatever else you might have in your standard Virtual Host
</VirtualHost>
After you edit this file you must restart Apache.

Using Phusion/mod_rails

I've been looking into using mod_rails (Phusion), but I just wanted to verify this: Once it's installed, I can still serve regular, non-rails apps from the same server without making any changes. Is this correct?
It is correct. I'm using Passenger in a project with other PHP projects and it works fine (even some PHP files in your public folder).
You can also set the passenger to start standalone (passenger start -d in your rails root folder) and use the mod_proxy and mod_rewrite from Apache to handle it (redirecting the rails requests to the rails app).
Yes, you can still serve non-rails applications using the same server.
mod_rails automatically detects which DocumentRoots are Rails applications by looking for public, for example.

How do I deploy a Rails 3 applications on Windows?

I've been searching for a way to reliably deploy a Rails 3 application on Windows. I'm quite shocked that it seems like there isn't currently any way to do this. The Apache + few Mongrel services solution don't work currently because Mongrel cannot run in daemon mode therefore I can't install it as a mongrel_service.
The requirements I guess should be:
A web server compatible with Rails 3.
Must be able to run as a Windows service, daemonized.
Must be able to restart automatically in case something goes wrong.
Must be production quality: no memory leaks, etc.
Should be able to scale, and accept multiple requests concurrently.
Less hacks possible.
I found out these things:
Mongrel is not production ready for Rails 3 (1.2.0pre), I experience memory leaks quite fast from a console window. The app just exits.
Mongrel doesn't run in daemon mode (-d) with Rails 3.
Therefore Mongrel cannot be installed as a service.
Phusion Passenger is not available on Windows (would be the best solution).
These are the possible solutions I came up with:
Get a Linux box, install Apache + Phusion Passenger and roll.
Using thin, however, the author says the thin process is not 'guarded'.
Using Ngnix, however, the author says he just ran a default app, not a full run app.
Using Ngnix. I think this solution suffers the same problem as above.
Using a virtualization of Linux, but I must solve problems like auto-start, etc.
Run on JRuby within Tomcat.
This might be a handy tool: http://projectkenai.com/projects/winsw
I hope we can find a real solution to this issue.
Update:
I agree that JRuby + a j2ee container is the best bet. Some problems must be resolved like gems with extensions, etc. There are lots of valuable ideas here: http://rails-nutshell.labs.oreilly.com/ch14.html#production_r259035_id35801805
This is the setup I currently have running:
Windows server 2008
Apache 2.2
Thin Server
Ruby 1.9.2
Rails 3.0.9
Installation of these aspects is covered by this great tutorial "How to install and configure Ruby on Rails with Windows Server 2008 EE". I ignored the LDAP and ActiveDirectory bit, but there is a nice workaround discussed there for installing Thin server since gem 'thin' will normally break on Windows.
For production I set up MySQL Server 5.5 to host my database. The mysql2 adapter is required for Rails 3 but is not yet supported in my Windows environment. The mysql adapter will also throw an error on Rails 3, but as a workaround you can get it to work by installing an older version of libmysql.dll. You just need to drop it into your Ruby192/bin directory.
Once the proper mysql adapter and server is installed you'll need to create the database:
>> mysql -u root -p
[enter root pw]
create database production;
quit;
(You may need to add your MySQL installation to your path if 'mysql' cannot be found.)
Finally, set the database config found at your_rails_app/config/database:
# MySQL Production Database
production:
adapter: mysql
database: production
pool: 5
timeout: 5000
encoding: utf8
password: [your_root_password]
host: localhost
The rest, including the proxy setup and running as a Windows service, is covered at "How to install and configure Ruby on Rails with Windows Server 2008 EE". To make sure your basic Thin setup is running correctly:
thin start -p 3000 -e production
This should start your server on port 3000 in production mode using the MySQL database. The only thing missing here is load balancing, which I'm hoping to find an answer to soon!
Personally, I think the JRuby + Tomcat avenue is going to be your best bet, just because Tomcat is vetted on Windows and it along with JRuby are pretty stable. My first thought was Passenger as well, and it's sad that it's still not ported.
EngineYard is easy enough to deploy a rails app from a windows enviornment just install ey gem and change one or two things in your gemfile.lock a good link is https://support.cloud.engineyard.com/entries/20996706-Deploy-from-Windows
they give you 500 free hours as well when getting started

Running gem server in passenger

I'm running a few rails/rake apps in Apache/passenger and I want to add the documentation app served by gem server to these apps, so I can easily give it a special (sub)domain, like docs.example.org, so it's easily available for all members of our team and nobody has to start the server himself or remember port numbers (like 8808, the default gem server port).
I would recommend looking into bdoc instead of gem server, it allows the user to access all their gem docs without a server running at all. It would also be trivial to modify bdoc to output to a specific directory then you could easily add a step to regenerate the docs.
The nice thing about having them in static files would be the apache config is dead simple.
If you do want to make bdoc output to a specific dir look at this line.
Edit:
I actually went ahead and branched this on github and made the change. Now you can supply the output directory on the command line and it will generate the static rdoc pages for you.
I'm running http://gems.local on my machine in case I want to do some Ruby cracking offline. (Plain journey, trains, etc).
This is really easy, you can actually run passenger with all the Ruby gems' documentation locally without having to access the net.
I was following Jason's tips and got everything working. See the following article and you should be ready to go:
http://jasonseifer.com/2009/02/22/offline-gem-server-rdocs
Attila
I wrote a blog post on how I have my gems, ruby, rails and jquery docs locally using the yard server and nginx for proxing in mac os x. Steps for linux are almost the same, only thing that changes is the way to configure the daemons.
https://makarius.posterous.com/offline-rails-ruby-jquery-and-gems-docs-with

Resources