Ruby on rails, Passenger and Nginx environment construction under Ubuntu14.04

WBOY
Release: 2016-08-08 09:32:16
Original
998 people have browsed it

I’ve always heard thatrubyonrailsis very efficient, so I tried it a while ago, and now I’m reviewing itrailsEnvironment Building process. I am usingubuntu14.04LTS. After reading various posts and some tutorials on the Internet, it seems that it is not recommended to do it underwindowsrailsdevelopment, generallylinuxandmacos.

  1. preliminary work

during installationrailsBefore the environment, there are some necessary The package needs to be installed to avoid various missing library problems in subsequent installations (seehttp://ihower.tw/rails3/). Execute the following instructions:

$sudo apt-get install build-essential bison openssl libreadline6libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-devlibyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-devlibxslt-dev autoconf libc6-dev

When installed usingapt-getSometimes you encounterunableto The problem of locatecan generally be solved by updating:

$sudo apt-get update

Ifupdatecannot be executed either, "isthe" appears Internet authenticated?"and other prompts, it is likely that the network is limited. I discovered this problem when using the hotel's network...

  1. RVMInstallation

RVMis a command line tool that provides A convenient multi-versionrubyenvironment management and switching, which can bring great convenience to you learningruby/railsOf course, you don’t have to use it.rvm, but I personally prefer to uservm.

To installrvmyou need to usecurl, which has already been installed. Then followrvmOfficial website instructions for installation , very simple, just execute two commands:

$ gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3

$ curl -sSL https:/ /get.rvm.io | bash -sstable

After installation is complete, run:$source ~/.rvm/scripts/rvm

This completes the installation ofrvm. It can be run by running$ rvm -vto check ifrvmis installed successfully.

  1. Install withrvmruby

Run$rvm install 2.0.0to installruby2.0.0version. You can install the corresponding version according to your needs. IfErrorrunning occurs 'requirements_debian...'error, you can run$rvm autolibs disablefirst and then install it. If all the packages have been installed in step1, then the installation should be successful here, otherwise the errormissingxxxwill appear.

  1. Rubyversion settings

RVMcan be used to install multiple versionsruby, so if the same If there are multiple versions ofrubyinstalled on a computer, you need to specify which version ofrubyto use. Available$rvm 2.0.0 --defaultcommand to specify the default version (here is the2.0.0version).

Attention, forubuntuitsterminalrealgnome-terminal, so it will appearRVMis not a functionerror, you need to open theterminalEdit->profile->preferences->Titleand Command,selectRun command as a loginshell. Close theterminaland reopen theterminalto run therubyversion setting command. For details, please see:https://rvm.io/integration/gnome-terminal

  1. Installation

    rails

In view of the domestic network environment, in Before installing

rails, you can install theRVMRubyto the domesticTaobao Mirror Like serverhttp://ruby .taobao.org/, otherwise it will not respond for a long time and cannot be installed:

$

gemsources --remove https://rubygems.org/

$

gemsources -a https://ruby.taobao.org/

$

gemsource s -l

***CURRENT SOURCES ***


https://ruby.taobao.org

Use

rvmSet accordinglyruby/railsofgemset. If we want to use the2.0.0version ofrubyand the4.1.8version ofrailscarried out combination, you can set agemsetenvironment for it. The specific operations are as follows:$rvm use 2.0.0

(using2.0.0version ofruby)

$rvm gemset create rails418(Create anamedrails418gemset, the name can be arbitrary)

$gem install rails [--version=' 4.1.8'](Installrails, the followingversionparameter is optional, if not filled in, the latest version ofwill be installedrails. If it appears during installationunableto. For errors such as convert "/x89" from ASCII to UTF8, you can run$gem install rdocand$gem rdoc --all --overwriteto solve)

$rvm use 2.0.0@rails418 –default(willruby2.0.0andrails4.1.8combinedgemsetas the defaultgemset)

can be used$rvm gemset listto see whichgemsetenvironments you have set, the same,$rvm listcan check which versions ofrubyare installed.

We may ask, if I have multiplerailsprojects, each project requires a different environment, then I need to switch manually every time I switch projectsgemsetenvironment? In fact, we can create a.rvmrcfile in the root directory of each project, and write in it for examplervmuse 2.0.0 @rails418command to specify thegemsetenvironment used. In this way, every time we enter this directory, we will switch to this environment. Deployment of

  1. Rails

    deployment method.

passengeris awebapp server,nginxis a high-performanceHTTPand reverse proxy server. There are actually several software available for deployment, and you can choose by yourself.First installpassenger:

$gem After install passenger, use thervmsudocommand to install the

module withpassengernginx:$ rvmsudopassenger-install-nginx-moduleThis waynginx

The default installation path is

/opt/nginx, modify/opt/ nginx/conf/nginx.conffile to specify the root directory as therailsproject'spublicdirectory. Then startnginx:$ sudo /opt/nginx/sbin/nginxThis way you can use your ownrails

Project .

Using this method to installpassengeris very convenient.Nginxis not likeapache,apacheWhen a module is needed, you only need to add the module to the configuration file and restart. However,nginxcan only be compiled and installed after configuring the required modules. Once the installation is completed, no more modules can be added. So if you want to install it separately, you need to go online to check how to configurenginxandpassenger. For separate installation, how to configurenginxso that it can supportpassenger, here is the official reference document address ofpassenger:https://www.phusionpassenger.com/documentation/UsersguideNginx.htmlAs for how to addnginxto the service and start it up, the following is givenhttp:// Ascript on www.nginx.cn/204.html:#!/bin/shDESC="nginxdaemon"

NAME=nginx

DAEMON=/opt/nginx/sbin/$NAME

CONFIGFILE=/opt/nginx/conf/$NAME.conf

PIDFILE=/opt/nginx/ logs/$NAME.pid

SCRIPTNAME=/etc/init.d/$NAME

set -e

[-x "$DAEMON" ] || exit 0

do_start(){

$DAEMON -c $CONFIGFILE || echo-n "nginx already running"

}

do_stop(){

kill -INT `cat $PIDFILE` ||echo -n "nginx not running"

}

do_reload(){

kill -HUP `cat $PIDFILE` ||echo -n "nginx can't reload"

}

case "$1" in

start)

echo -n "Starting $DESC:$NAME"

do_start

echo "."

;;

stop)

echo -n "Stopping $DESC:$NAME"

do_stop

echo "."

;;

reload|graceful)

echo -n "Reloading $DESCconfiguration..."

do_reload

echo "."

;;

restart)

echo -n "Restarting$DESC: $NAME"

do_stop

do_start

echo "."

;;

*)

echo "Usage: $SCRIPTNAME{start|stop|reload|restart}" >&2

exit 3

;;

esac

exit0

Save this script as a new file

/etc/init.d/nginx

and you can use it latersudoservice nginx start/stop/restartto operatenginxservice.Given below is how to uninstall

rvm

ruby,Instructions forgemset:Uninstall aruby

Version:$rvm remove 2.0.0Clear agemset

of the usedgem, and want to reinstall allgem:$rvm gemset empty 2.0.0 @rails418Delete a

gemset

:$rvm gemset delete rails418

The above introduces the environment construction of Ruby on rails, Passenger and Nginx under Ubuntu 14.04, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!