Search code examples
ruby-on-railsruby-on-rails-4

Ruby-on-rails development and production on same server


Is it possible (or normal) to have Ruby on Rails development and production on the same server? And is it OK to have sqlite for development and postgresql for production?


Solution

  • It is not normal, but it is possible - and occasionally needed - to debug problems that are only showing up in production. A couple of examples are assets (javascripts, images, etc) that are served up differently in development as opposed to production due to the asset pipeline. Another area is caching which tends to be different in production and is frequently disabled in development.

    In ruby on rails there are usually (at least) three modes that the server can run in.
    These are referred to as 'environments'.

    • development. This is your local machine and is what you normally use locally during development

    • tests. This is used when you run tests and test suites.

    • production. This is the mode used for actual production servers which are usually on a remote server.

    Sometimes you do want/need to run a local development server in 'production mode' and in these cases you do this inline with

    RAILS_ENV=production rails server
    

    or

    rails server -e production
    

    or

    rails server -e production -p 3001 
    # Specify the port (e.g. **-p 3001**) if you want to run on a different port (the default port is 3000),
    # e.g. to run in development mode in one window and production mode in another.
    

    When you run your local server in another mode, such as production, you'll need to be aware that this also affects your database connection. config/database.yml has your database connection and also uses the RAILS_ENV settings.
    You may want/need to run your server in production mode - but use your local database. You can do this by temporarily using the actual setting from the development block in the production block of config/database.yml. Just be sure to save the original settings / restore afterwards (before you do your next push).

    It's also totally ok and indeed common to have sqlite locally and mysql/postgres/oracle in production.