OS X:开发和使用Apache和Passenger进行RoR的生产部署 [英] OS X: Development & Production Deployment for RoR with Apache and Passenger

查看:84
本文介绍了OS X:开发和使用Apache和Passenger进行RoR的生产部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于接下来几天尝试为Rails,Apache和Passenger设置开发环境,我的头将从混乱的混乱中爆炸.

我的问题是:

  1. 您是否需要乘客用于开发环境?我可以只使用pow.cx进行开发吗?-我有99.99%的肯定回答是不"(您不使用乘客进行开发),但是我需要确认,因为我现在很困惑.
  2. 部署时,我仅使用乘客,对吗?IE.在部署之前,我永远不会碰乘客.
  3. 我的开发环境正确吗?
  4. 在乘客与Apache VHOST结合的影响下,生产部署只是在移动Rails应用程序?

背景(建议您阅读):

网络上的所有信息似乎都在关注为已经知道自己在做什么的人们解释事情,而不是详细解释事情是如何工作的,这只是一系列安装步骤,这让我非常困惑的角色,以及如何正确设置开发环境和正确部署RoR应用程序-因此,请忍受这个漫长的问题.

在过去的三天里,我一直在尝试在Macbook Pro上设置一个开发环境,该开发环境不会因Apple对Apache安装的繁琐限制而遭到破坏.我安装了一个自定义的Apache安装程序(因为我拒绝使用Server.app,所以从bitnami使用他们的ruby堆栈),这样我就可以运行Apache并将PHP之类的东西轻松升级到5.5,并且运行良好.

我正在尝试进入RoR,但到目前为止,这一直很艰难,我准备放弃.

我知道您需要Apache来提供Rails应用程序,以便服务器可以同时处理请求,而不是一次处理请求,并且存在各种接口,例如Thin或其他.强烈推荐乘客.

我按照他们的指示安装了Passenger,并做了一些黑客操作,以将其编译为Bitnami乘客安装,而不是Mac OS X上的默认Apache-并且可以正常工作.当我启动apache并运行时: passenger-memory-stats ,我会从安装指南中得到预期的结果,从而告诉我乘客正在运行.

但是,当我尝试部署一个简单的hello world Rails应用程序时,却显示很抱歉……",或者根本没有结果,只是空白页.

我相当确定我的开发环境是正确的,除了最后一点,一切都可以正常工作.我可以想象在pow.cx服务器上进行的开发,一旦部署准备就绪,您只需复制Rails应用程序并配置Apache的VHOST使其指向您准备部署的应用程序,而乘客则负责其余的工作,对吗?

我正在通过Postgress.app使用PostgresSQL,服务器工作正常,我可以连接到它.

我的Gemfile中有 gem'pg'.

我已经阅读了以下SO问题,并尝试了所有可行的解决方案,但我要么没有结果,要么是空日志,这至少……真令人发指:

因此,我正在尝试使用以下方法部署此hello world应用程序(可在标准Rails服务器上运行):

通过以下方式调用应用程序:

  http://dmarket.local:8081/ 

VHOSTS:

 < VirtualHost *:8081>PassengerEnabled已启用RailsEnv生产错误日志/Applications/rubystack/apache2/htdocs/helloworld/project_error.logCustomLog/Applications/rubystack/apache2/htdocs/helloworld/project_error.log合并ServerName dmarket.local:8081ServerAlias www.dmarket.local:8081DocumentRoot"/Applications/ruby​​stack/apache2/htdocs/helloworld/public"PassengerPreStart http://dmarket.local:8081<目录"/Applications/ruby​​stack/apache2/htdocs/helloworld/public">全部允许选项-MultiViews</目录></VirtualHost> 

主机文件:

  127.0.0.1 dmarket.local127.0.0.1 www.dmarket.local 

DATABASE.YML(与开发,测试和生产相同):

 适配器:postgresql编码:unicode主持人:127.0.0.1端口:5432数据库:tsujp泳池:5用户名:tsujp密码: 

解决方案

不需要开发中的乘客.实际上,在开发模式下,您甚至不需要apache.您可以使用内置的Webrick服务器( $ rails服务器)来运行您的应用程序.是的.Pow是一个很好的工具,我一直都在使用它.

在生产中也有多种选择.其中之一是Apache + Passenger,是的.但是您需要将Nginx放在这之前(因为Apache不能很好地处理慢速客户端).如果您有nginx,则可以用其他东西代替apache + passenger.很长时间以来,我一直在使用Unicorn(来自github的红宝石Web服务器).现在,我目前最喜欢的是彪马.它比独角兽使用的资源更少,但是对代码的要求更高(最好是线程安全的,因为puma是线程服务器).

现在,由于开发与生产之间的差异:众所周知,开发应尽可能类似于生产,因为它可以最大程度地降低部署时的风险.因此,我的建议是:在任何地方(开发和生产)都使用独角兽.仅在生产时才将nginx放在其前面.

也是

对于实际执行的部署,请查看Capistrano.它已成为部署Rails应用程序的行业标准(但它也可以部署PHP,静态文件以及您拥有的工具).

My head is about to explode from the mangled mess as a result of the following few days trying to setup a development environment for Rails, Apache and Passenger.

The questions I have are:

  1. Do you NEED passenger for a development environment? Can I just develop with pow.cx instead? - I am 99.99% sure the answer is no (you don't use passenger for development), but I need confirmation since I am deeply confused now.
  2. When I deploy, I only use Passenger for that, correct? I.e. I don't ever touch passenger until I deploy.
  3. Is my development environment correct?
  4. Production deployment is simply moving a rails application under the effects of Passenger coupled with an Apache VHOST?

Background (I suggest you read):

It seems that all the information on the web is concerned about explaining things for people who already know what they are doing, rather than explaining in detail how things work it's just a series of installation steps and that has left me extremely confused on the role of things, and how to setup a development environment and deploy a RoR application correctly - so please bear with this long question.

For the past 3 days I have been trying to setup a development environment on my Macbook Pro that isn't destroyed by Apple's rediculous limits on Apache installations. I installed a custom Apache install (from bitnami using their ruby stack, since I refuse to use Server.app) so that I can run Apache and upgrade things like PHP to 5.5 easily, and that works fine.

I am trying to get into RoR but so far it has been a struggle, and I am about ready to give up.

I understand you need Apache to serve Rails applications so that the server can handle requests concurrently rather than one at a time, and that various interfaces for this exist like Thin or whatever; Passenger was highly recommended.

I installed Passenger via their instructions and did some hackery to compile it for the Bitnami passenger installation, rather than the default Apache on Mac OS X - and it's working. When I start apache and run: passenger-memory-stats I get results expected from the installation guide, so that tells me passenger is running.

However, when I try and deploy a simple hello world Rails application I get a slew of "We're sorry…" or no result at all and just a blank page.

I am fairly sure my development environment is correct, everything works except this last bit. I can picture development taking place on a pow.cx server, and once deployment is ready you simply copy the Rails application and configure Apache's VHOST to point to your ready-to-deploy app while Passenger handles the rest, is that correct?

I am using PostgresSQL via the Postgress.app, the server works fine and I can connect to it.

I have gem 'pg' in my Gemfile.

I have already read, and tried every conceivable solution from the following SO questions, but I either get no result or empty logs which is… infuriating to say the least:

So with all that said, I am trying to deploy this hello world application (which works on a standard rails server) using the following:

INVOKING APPLICATION VIA:

http://dmarket.local:8081/

VHOSTS:

<VirtualHost *:8081>

    PassengerEnabled on

    RailsEnv production
    ErrorLog /Applications/rubystack/apache2/htdocs/helloworld/project_error.log
    CustomLog /Applications/rubystack/apache2/htdocs/helloworld/project_error.log combined

    ServerName dmarket.local:8081
    ServerAlias www.dmarket.local:8081
    DocumentRoot "/Applications/rubystack/apache2/htdocs/helloworld/public"

    PassengerPreStart http://dmarket.local:8081

    <Directory "/Applications/rubystack/apache2/htdocs/helloworld/public">

        Allow from all
        Options -MultiViews

    </Directory>

</VirtualHost>

HOSTS FILE:

127.0.0.1   dmarket.local
127.0.0.1   www.dmarket.local

DATABASE.YML (same for development, test, and production):

  adapter: postgresql
  encoding: unicode
  host: 127.0.0.1
  port: 5432
  database: tsujp
  pool: 5
  username: tsujp
  password: 

解决方案

You don't need Passenger in development. In fact, in development mode you don't need even apache. You can use built-in Webrick server ($ rails server) to run your app. And yes. Pow is a good tool, I use it all the time.

In production there are also multiple options. One of them is Apache+Passenger, yes. But you need to put Nginx in front of those (because Apache doesn't handle slow clients very well). If you have nginx, then you can replace apache+passenger with something else. For a long time I've been using Unicorn (ruby web server from github). Now my current favourite is Puma. It uses less resources than unicorn, but has more requirements to your code (it better be thread-safe, because puma is a threaded server).

Now, to the development-production discrepancy: it is known that development should resemble production as closely as possible, because it minimizes risks when deploying. So, my suggestion is: use unicorn everywhere (both development and production). Only on production put nginx in front of it.

Also,

for actually performing deploys, look into Capistrano. It became industry standard for deploying rails apps (but it can also deploy PHP, static files and what have you).

这篇关于OS X:开发和使用Apache和Passenger进行RoR的生产部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆