


Ruby on rails, Passenger and Nginx environment construction under Ubuntu14.04
I’ve always heard that rubyonrails is very efficient, so I tried it a while ago, and now I’m reviewing it rails Environment Building process. I am using ubuntu14.04LTS. After reading various posts and some tutorials on the Internet, it seems that it is not recommended to do it under windows rails development, generally linux and macos .
preliminary work
during installation railsBefore the environment, there are some necessary The package needs to be installed to avoid various missing library problems in subsequent installations (see http://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 using apt-get Sometimes you encounter unableto The problem of locate can generally be solved by updating:
$sudo apt-get update
If update cannot 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...
RVMInstallation
RVM is a command line tool that provides A convenient multi-version rubyenvironment management and switching, which can bring great convenience to you learning ruby/rails Of course, you don’t have to use it . rvm, but I personally prefer to use rvm.
To install rvm you need to use curl, which has already been installed. Then follow rvm Official 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 of rvm. It can be run by running $ rvm -v to check if rvm is installed successfully.
Install with rvmruby
Run $rvm install 2.0.0 to install ruby2.0.0 version. You can install the corresponding version according to your needs. If Errorrunning occurs 'requirements_debian...' error, you can run $rvm autolibs disable first and then install it. If all the packages have been installed in step 1, then the installation should be successful here, otherwise the error missingxxx will appear.
Ruby version settings
RVM can be used to install multiple versions ruby, so if the same If there are multiple versions of ruby installed on a computer, you need to specify which version of ruby to use. Available$rvm 2.0.0 --default command to specify the default version (here is the 2.0.0 version).
Attention, for ubuntuitsterminalreal gnome-terminal, so it will appear RVMis not a function error, you need to open the terminalEdit->profile->preferences->Titleand Command,selectRun command as a loginshell. Close the terminal and reopen the terminal to run the rubyversion setting command. For details, please see: https://rvm.io/integration/gnome-terminal
- Installation
rails
rails, you can install the RVMRuby to the domestic Taobao 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 ***
Use
rvm Set accordingly ruby/rails of gemset. If we want to use the 2.0.0 version of ruby and the 4.1.8 version of rails carried out combination, you can set a gemset environment for it. The specific operations are as follows: $rvm use 2.0.0
(using 2.0.0 version of ruby) $rvm gemset create rails418
(Create a named rails418 gemset, the name can be arbitrary) $gem install rails [--version=' 4.1.8'] (Install rails, the following version parameter is optional, if not filled in, the latest version of will be installed rails. If it appears during installationunableto.
For errors such as convert "/x89" from ASCII to UTF8, you can run $gem install rdoc and $gem
rdoc --all --overwrite to solve) $rvm use 2.0.0@rails418 –default(will ruby2.0.0 and rails4.1.8 combined gemset as the default gemset) can be used$rvm gemset list to see which gemsetenvironments you have set, the same, $rvm
list can check which versions of ruby are installed. We may ask, if I have multiple rails projects, each project requires a different environment, then I need to switch manually every time I switch projects gemsetenvironment? In fact, we can create a .rvmrc file in the root directory of each project, and write in it for example rvmuse
2.0.0 @rails418 command to specify the gemset environment used. In this way, every time we enter this directory, we will switch to this environment. Deployment of Rails passenger is a webapp
server, nginx is a high-performance HTTP and reverse proxy server. There are actually several software available for deployment, and you can choose by yourself. First install passenger: $gem
After install passenger, use the rvmsudo command to install the module with passenger nginx: $ rvmsudopassenger-install-nginx-moduleThis waynginx The default installation path is /opt/nginx , modify /opt/ nginx/conf/nginx.conf file to specify the root directory as the rails project's public directory. Then start nginx:$ sudo /opt/nginx/sbin/nginxThis way you can use your own rails Project . Using this method to install passenger is very convenient. Nginx is not like apache, apacheWhen a module is needed, you only need to add the module to the configuration file and restart. However, nginx can 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 configure nginx and passenger. For separate installation, how to configure nginx so that it can support passenger, here is the official reference document address of passenger: https://www.phusionpassenger.com/documentation/UsersguideNginx.htmlAs for how to add nginx to the service and start it up, the following is givenhttp:// A script on www.nginx.cn/204.html: #!/bin/sh
DESC="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 later sudoservice
nginx start/stop/restart to operatenginx service. Given below is how to uninstall ruby, Instructions for gemset: Uninstall a ruby Version: $rvm
remove 2.0.0 Clear a gemset of the used gem, and want to reinstall all gem: $rvm gemset empty 2.0.0 @rails418 Delete 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.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to configure Nginx in Windows? Install Nginx and create a virtual host configuration. Modify the main configuration file and include the virtual host configuration. Start or reload Nginx. Test the configuration and view the website. Selectively enable SSL and configure SSL certificates. Selectively set the firewall to allow port 80 and 443 traffic.

Docker container startup steps: Pull the container image: Run "docker pull [mirror name]". Create a container: Use "docker create [options] [mirror name] [commands and parameters]". Start the container: Execute "docker start [Container name or ID]". Check container status: Verify that the container is running with "docker ps".

You can query the Docker container name by following the steps: List all containers (docker ps). Filter the container list (using the grep command). Gets the container name (located in the "NAMES" column).

How to confirm whether Nginx is started: 1. Use the command line: systemctl status nginx (Linux/Unix), netstat -ano | findstr 80 (Windows); 2. Check whether port 80 is open; 3. Check the Nginx startup message in the system log; 4. Use third-party tools, such as Nagios, Zabbix, and Icinga.

Create a container in Docker: 1. Pull the image: docker pull [mirror name] 2. Create a container: docker run [Options] [mirror name] [Command] 3. Start the container: docker start [Container name]

The methods that can query the Nginx version are: use the nginx -v command; view the version directive in the nginx.conf file; open the Nginx error page and view the page title.

How to configure an Nginx domain name on a cloud server: Create an A record pointing to the public IP address of the cloud server. Add virtual host blocks in the Nginx configuration file, specifying the listening port, domain name, and website root directory. Restart Nginx to apply the changes. Access the domain name test configuration. Other notes: Install the SSL certificate to enable HTTPS, ensure that the firewall allows port 80 traffic, and wait for DNS resolution to take effect.

When the Nginx server goes down, you can perform the following troubleshooting steps: Check that the nginx process is running. View the error log for error messages. Check the syntax of nginx configuration. Make sure nginx has the permissions you need to access the file. Check file descriptor to open limits. Confirm that nginx is listening on the correct port. Add firewall rules to allow nginx traffic. Check reverse proxy settings, including backend server availability. For further assistance, please contact technical support.
