{"id":669,"date":"2011-03-23T22:53:17","date_gmt":"2011-03-23T14:53:17","guid":{"rendered":"http:\/\/www.strongd.net\/?p=669"},"modified":"2011-03-23T22:53:17","modified_gmt":"2011-03-23T14:53:17","slug":"ruby-on-rails-with-nginx-on-centos-5","status":"publish","type":"post","link":"https:\/\/www.strongd.net\/?p=669","title":{"rendered":"Ruby on Rails with Nginx on CentOS 5"},"content":{"rendered":"<p>Ruby on Rails is a popular rapid development web framework that allows web designers and developers to implement fully featured dynamic web applications using the Ruby programming language. This guide describes the required process for deploying Ruby on Rails with Passenger and the nginx web server on CentOS 5.<\/p>\n<p>&nbsp;<\/p>\n<p>These instructions work with the Linode platform. If you don&#8217;t have a Linode yet, sign up for a\u00a0<a title=\"Linode Linux VPS\" href=\"http:\/\/www.linode.com\/?r=f4ac5ae5f59e43a8b31de8077ceab27bd1e60c80\">Linux VPS<\/a> and get started today.<\/p>\n<div>\n<div>Contents<\/div>\n<div>Install Required Packages<\/div>\n<div>Install Passenger and Nginx<\/div>\n<div>Set up an Init Script for Nginx<\/div>\n<div>Install MySQL Support (optional)<\/div>\n<div>More Information<\/div>\n<div>License<\/div>\n<\/div>\n<div id=\"install-required-packages\"><a name=\"install_required_packages\" href=\"http:\/\/library.linode.com\/ebFWEE\"><\/a><\/p>\n<h2>Install Required Packages<\/h2>\n<p>Make sure your system is up to date by issuing the following command:<\/p>\n<pre>yum update<\/pre>\n<p>Issue the following series of commands to install packages required for Ruby on Rails.<\/p>\n<pre>yum groupinstall \"Development Tools\"\r\nyum install zlib-devel wget openssl-devel pcre pcre-devel make gcc gcc-c++ curl-devel<\/pre>\n<p>The version of Ruby in the CentOS repositories is fairly old; we&#8217;ll need to download and compile it ourselves. Check the\u00a0<a href=\"http:\/\/www.ruby-lang.org\/en\/downloads\/\">Ruby language site<\/a><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/> for a link to the newest stable version and substitute it for the link shown below. Execute the following sequence of commands to get Ruby installed.<\/p>\n<pre>cd \/opt\r\nwget ftp:\/\/ftp.ruby-lang.org\/pub\/ruby\/1.9\/ruby-1.9.1-p376.tar.gz\r\ntar -zxvf ruby-1.9.1-p376.tar.gz\r\ncd ruby-1.9.1-p376\r\n.\/configure --bindir=\/usr\/bin --sbindir=\/usr\/sbin\/\r\nmake -j3\r\nmake install<\/pre>\n<p>Now we&#8217;ll need to install gems. Issue the following series of commands to download and install a fresh version. You may wish to check the\u00a0<a href=\"http:\/\/rubyforge.org\/frs\/?group_id=126\">RubyForge files page<\/a><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/> for the most recent version.<\/p>\n<pre>cd \/opt\r\nwget http:\/\/production.cf.rubygems.org\/rubygems\/rubygems-1.5.1.tgz\r\ntar -zxvf rubygems-1.5.1.tgz\r\ncd \/opt\/rubygems-1.5.1\/\r\nruby setup.rb<\/pre>\n<p>Update rubygems:<\/p>\n<pre>gem update --system<\/pre>\n<p>Install the\u00a0<tt>rake<\/tt>,\u00a0<tt>rack<\/tt>, and\u00a0<tt>fastthread<\/tt> gems:<\/p>\n<pre>gem install rake rack\r\ngem install fastthread --no-rdoc --no-ri<\/pre>\n<\/div>\n<div id=\"install-passenger-and-nginx\"><a name=\"install_passenger_and_nginx\" href=\"http:\/\/library.linode.com\/wSogiC\"><\/a><\/p>\n<h2>Install Passenger and Nginx<\/h2>\n<p>Proceed to the\u00a0<a href=\"http:\/\/www.modrails.com\/install.html\">Phusion Passenger<\/a><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/> site and locate the link for the current source code tarball. Download it as follows (substitute the link for the current version):<\/p>\n<pre>cd \/opt\r\nwget http:\/\/rubyforge.org\/frs\/download.php\/73563\/passenger-3.0.1.tar.gz\r\ntar xzvf passenger-3.0.1.tar.gz<\/pre>\n<p>Run the Phusion Passenger installer for Nginx:<\/p>\n<pre>cd \/opt\/passenger-3.0.1\/bin\r\n.\/passenger-install-nginx-module<\/pre>\n<p>You&#8217;ll be greeted by the Phusion Passenger Nginx installer program. Press &#8220;Enter&#8221; to continue with the installation.<\/p>\n<p><a href=\"http:\/\/library.linode.com\/frameworks\/ruby-on-rails-nginx\/images\/01-passenger-nginx-installer.png\"><img decoding=\"async\" src=\"http:\/\/library.linode.com\/frameworks\/ruby-on-rails-nginx\/images\/01-passenger-nginx-installer.png\" alt=\"Phusion Passenger Nginx installer program running on CentOS 5.\" \/><\/a>When prompted for the Nginx installation method, we recommend you choose &#8220;1&#8221; to allow the installer to automatically download, compile, and install Nginx for you. Unless you have specific needs that would necessitate passing custom options to Nginx at compile time, this is the safest way to proceed.<\/p>\n<p>Please do\u00a0<strong>not<\/strong> remove the Passenger files from\u00a0<tt>opt<\/tt> after the install. They need to stay in place or your install will not function correctly.<\/p>\n<\/div>\n<div id=\"set-up-an-init-script-for-nginx\"><a name=\"set_up_an_init_script_for_nginx\" href=\"http:\/\/library.linode.com\/kVXCjK\"><\/a><\/p>\n<h2>Set up an Init Script for Nginx<\/h2>\n<p>Nginx is now installed in\u00a0<tt>\/opt\/nginx<\/tt>, but there are no &#8220;init&#8221; scripts to control this process. Issue the following sequence of commands to download a script, move it to the proper directory, set the proper permissions and set system startup links:<\/p>\n<pre>cd \/opt\r\nwget https:\/\/library.linode.com\/frameworks\/ruby-on-rails-nginx\/reference\/init-rpm.sh\r\nmv \/opt\/init-deb.sh \/etc\/rc.d\/init.d\/nginx\r\nchmod +x \/etc\/rc.d\/init.d\/nginx\r\nchkconfig --add nginx\r\nchkconfig nginx on<\/pre>\n<p>You can now start, stop, and restart Nginx just like any other server daemon. For example, to start the server, issue the following command:<\/p>\n<pre>\/etc\/init.d\/nginx start<\/pre>\n<p>You can now start, stop, and restart Nginx just like any other server daemon. For example, to start the server, issue the following command:<\/p>\n<pre>\/etc\/rc.d\/init.d\/nginx start<\/pre>\n<p>If you haven&#8217;t already configured your firewall to allow inbound HTTP connections, run the following command to do so now:<\/p>\n<pre>system-config-securitylevel-tui<\/pre>\n<p>The configuration file for Nginx is located at\u00a0<tt>\/opt\/nginx\/conf\/nginx.conf<\/tt>. This is the file you&#8217;ll need to edit to add support for your Rails applications. A default server is already configured in this file, and it also contains examples for alternate virtual host and SSL configurations.<\/p>\n<\/div>\n<div id=\"install-mysql-support-optional\"><a name=\"install_mysql_support__optional_\" href=\"http:\/\/library.linode.com\/SwORLg\"><\/a><\/p>\n<h2>Install MySQL Support (optional)<\/h2>\n<p>If your application uses MySQL, install the database server by following our\u00a0<a href=\"http:\/\/library.linode.com\/databases\/mysql\/centos-5\">MySQL on CentOS 5 guide<\/a>. Once it&#8217;s installed and configured properly, issue the following commands:<\/p>\n<pre>yum install mysql-devel\r\ngem install mysql --no-rdoc --no-ri -- --with-mysql-dir=\/usr\/bin --with-mysql-lib=\/usr\/lib\/mysql --with-mysql-include=\/usr\/include\/mysql<\/pre>\n<p>&nbsp;<\/p>\n<\/div>\n<div id=\"more-information\"><a name=\"more_information\" href=\"http:\/\/library.linode.com\/JVgMwy\"><\/a><\/p>\n<h2>More Information<\/h2>\n<p>You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.<\/p>\n<ul>\n<li><a href=\"http:\/\/rubyonrails.org\/\">Ruby on Rails Home Page<\/a><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/><\/li>\n<li><a href=\"http:\/\/rubyonrails.org\/documentation\">Ruby on Rails Documentation<\/a><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/><\/li>\n<li><a href=\"http:\/\/nginx.org\/\">Nginx Home Page<\/a><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/><\/li>\n<li><a href=\"http:\/\/nginx.org\/en\/docs\/\">Nginx Documentation<\/a><img decoding=\"async\" src=\"http:\/\/library.linode.com\/images\/external-link-icon.png\" alt=\"External Link\" \/><\/li>\n<li><a href=\"http:\/\/library.linode.com\/web-servers\/nginx\/configuration\/basic\">Nginx Configuration<\/a><\/li>\n<\/ul>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ruby on Rails is a popular rapid development web framework that allows web designers and developers to implement fully featured dynamic web applications using the Ruby programming language. This guide describes the required process for deploying Ruby on Rails with Passenger and the nginx web server on CentOS 5. &nbsp; These instructions work with the &hellip; <a href=\"https:\/\/www.strongd.net\/?p=669\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Ruby on Rails with Nginx on CentOS 5<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,29,30,20],"tags":[206,207],"class_list":["post-669","post","type-post","status-publish","format-standard","hentry","category-linux","category-rails","category-ruby","category-20","tag-rails","tag-ruby"],"_links":{"self":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/669","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=669"}],"version-history":[{"count":2,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/669\/revisions"}],"predecessor-version":[{"id":671,"href":"https:\/\/www.strongd.net\/index.php?rest_route=\/wp\/v2\/posts\/669\/revisions\/671"}],"wp:attachment":[{"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=669"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=669"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.strongd.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=669"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}