search
HomeBackend DevelopmentPHP Tutorialnginx+unicorn deploy ruby ​​web environment


I recently took over a ruby ​​web project. Since I have never been exposed to ruby ​​and related web development before, and the documentation in the project is missing, I took some detours when deploying the project. Finally, I successfully deployed the project by referring to multiple ruby ​​on rails development environment deployments and learning the relationship between gems/bundlers in ruby. Write it down here, it is a small summary, and it can also provide a reference for the deployment environment when you are just getting started with ruby ​​web development.
Our project is based on padrino. If it is a rails-based project, the deployment should be similar.

1. Install ruby ​​

Since there may be multiple ruby-related projects in the system, and different projects may need to be developed or tested for different ruby ​​versions, multiple ruby ​​versions may need to be installed in the system . This requires corresponding tools to manage existing versions and install new versions. I choose rbenv here, but you can also use the old rvm.
Install rbenv
git clone git://github.com/sstephenson/rbenv.git  ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
Add ruby-build component
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
echo 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrc
exec $SHELL
Add gem-rehash component
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
Install ruby ​​(take ruby2.1.5 as an example)
Since the default installation of ruby ​​will be slower, so download the corresponding one from ruby.taobao.org first file, and then use local installation to install
wget -O ~/.rbenv/versions/ruby-2.1.5.tar.gz http://ruby.taobao.org/mirrors/ruby/2.1/ruby-2.1.5.tar.gz
env RUBY_BUILD_MIRROR_URL=file:///home/ziven/.rbenv/versions/ruby-2.1.5.tar.gz# ~/.rbenv/bin/rbenv install 2.1.5
where wget is to download the corresponding ruby ​​file, here is ruby-2.1.5.tar.gz
RUBY_BUILD_MIRROR_URL
is used to specify the installed ruby ​​image path, here the local path is used directly. Note that the local path should be ended with #. The version following the rbenv install command should correspond to the ruby ​​version to be installed. For example, the installed version may have a corresponding patch number (for example: 1.9.3-p223). This should also be written.

2. Install necessary components

Because we generally use bundler to manage the gems needed for the project, bundler needs to be installed here.

Considering the speed of connecting ruby ​​mirrors in China, we changed the gem source to taobao source.
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
After executing gem sources -l, there should be only one source: https://ruby.taobao.org/
Install bundler
gem install bundler


3. Application deployment

a. Clone web source code to the appropriate location

Here we assume that after cloning Place the source code to /opt/projectA


b. Install dependent gems

Execute in the root directory of the project:

bundle install
It should be noted here that the commands executed may be slightly different depending on the situation. For example, when deploying in a production environment, you may need to execute
bundle install --deployment --without development test
. When deploying like this, the relevant dependent gems are installed under projectA/vendor/bundle. It is especially suitable for use when different projects depend on different versions of the same gem.

c. Database related migration

Since this project is based on padrino, it needs to be executed:

padrino rake --envir db:migrate
It should be noted that depending on the situation, you may need to use bundle to execute this command:
bundle exec padrino rake --envir db:migrate
After the database migration is successful, you need to create an amdin account. Padrino completes the creation of the admin account in db/seeds.rb by default. So execute here:
bundle exec padrino rake --envir seed
will prompt you to enter the email address and password of the admin account during the execution process

d.unicorn deployment

You may need the corresponding unicorn startup script here, which can be written by referring to ruby-china's unicorn.rb. Omitted here.

Start unicorn server:
bundle exec unicorn -E production -c unicorn.rb -D
so padrino server has started normally. If unicorn.rb is listening on the tcp port, then you should be able to access the corresponding URL at this time. If you use the method of monitoring unix socket, you should also use nginx (or apache) as a reverse proxy.

4. nginx installation configuration

a. nginx installation

nginx can be installed in the same way as general Linux software. It is recommended to use the source code installation method. For the sake of simplicity here, we will temporarily install it using the package manager installation method:

sudo apt-get install nginx-full


b. nginx configuration

	upstream myserver {
	  server unix:/tmp/projectA.sock fail_timeout=0;
	}
	
	server {
	    listen       7788;
	    server_name  localhost;
	
	    client_max_body_size 10M;
	
	    error_page   500 502 503 504  /50x.html;
	    location = /50x.html {
	        root   /usr/share/nginx/html;
	    }
	
	    root /opt/projectA/web/public;
	
	    try_files $uri $uri.html @app;
	
	    location @app {
	        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	        proxy_set_header Host $http_host;
	        proxy_redirect off;
	        proxy_pass http://myserver;
	    }
	}
Here, the request for port 7788 is forwarded to
unix:/tmp/projectA.sock
for processing. That is, it is forwarded to our web server just now for processing.
At this point, the server is running normally. Other auxiliary functions can be added as needed. For example, nginx may require an SSL certificate for authentication.
The deployment of ruby ​​on rails projects is similar. During the deployment process, you may need to make corresponding adjustments according to the situation when executing the corresponding commands. However, as long as you are familiar with the deployment method of ruby ​​web, it is relatively easy to deploy other documents that can be referred to related frameworks.

The above introduces nginx+unicorn deployment of ruby ​​web environment, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
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
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools