on
Italy
- Get link
- X
- Other Apps
config/deploy.rb Inside The Project Directoryconfig/deploy/production.rb Inside The Project Directoryyum -y update
yum groupinstall -y 'development tools'
Some of the packages we need for this tutorial (e.g. libyaml-devel, nginx etc.) are not found within the official CentOS repository.sudo su -c 'rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm'
yum -y update
Finally, in order to install some additional libraries and tools, run the following command:yum install -y curl-devel nano sqlite-devel libyaml-devel
curl -L get.rvm.io | bash -s stable
source /etc/profile.d/rvm.sh
rvm reload
rvm install 2.1.0
Since Rails needs a JavaScript interpreter, we will also need to set up Node.js.yum:yum install -y nodejs
gem to download and install rails:gem install bundler rails
# Create a 1024 MB SWAP space
sudo dd if=/dev/zero of=/swap bs=1M count=1024
sudo mkswap /swap
sudo swapon /swap
.rpm
files. Unfortunately, in Passenger's case, they are quite outdated.
Therefore, we will be using RubyGem, once again, to download and install
the latest available version of Passenger -- version 4.gem install passenger
yum. However, to get Nginx work with Passenger, its source must be compiled with the necessary modules.passenger-install-nginx-module
Once you run the command, press Enter and confirm your choice of
language(s) (i.e. Ruby, in our case). You can use arrow keys and the
space bar to select Ruby alone, if you wish.Use to select.
If the menu doesn't display correctly, ensure that your terminal supports UTF-8.
‣ ⬢ Ruby
⬢ Python
⬢ Node.js
⬡ Meteor
In the next step, choose Item 1:1. Yes: download, compile and install Nginx for me. (recommended)
The easiest way to get started. A stock Nginx 1.4.4 with Passenger
support, but with no other additional third party modules, will be
installed for you to a directory of your choice.
And press Enter to continue.nano /etc/rc.d/init.d/nginx
Copy and paste the below contents:#!/bin/sh
. /etc/rc.d/init.d/functions
. /etc/sysconfig/network
[ "$NETWORKING" = "no" ] && exit 0
nginx="/opt/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $”Reloading $prog: ”
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
Press CTRL+X and confirm with Y to save and exit.chmod +x /etc/rc.d/init.d/nginx
nginx.conf. By default, unless you states otherwise, this file can be found under /opt/nginx/conf/nginx.conf.nano /opt/nginx/conf/nginx.conf
As the first step, find the http { node and append the following right after the passenger_root and passenger_ruby directives:# Only for development purposes.
# Remove this line when you upload an actual application.
# For * TESTING * purposes only.
passenger_app_env development;
Scroll down the file and find server { ... Comment out the default location, i.e.:..
# location / {
# root html;
# index index.html index.htm;
# }
..
And define your default application root:# Set the folder where you will be deploying your application.
# We are using: /home/deployer/apps/my_app
root /home/deployer/apps/my_app/public;
passenger_enabled on;
Press CTRL+X and confirm with Y to save and exit.# !! Remember to create an Nginx management script
# by following the main Rails deployment article for CentOS
# linked at the beginning of this section.
/etc/init.d/nginx restart
To check the status of Nginx, you can use:/etc/init.d/nginx status
Note: To learn more about Nginx, please refer to How to Configure Nginx Web Server on a VPS.gem install capistrano
deployer user with necessary privileges. For a more complete set up, consider using the groups example from the Capistrano introduction tutorial.deployer:adduser deployer
Set up deployer's password:passwd deployer
# Enter a password
# Confirm the password
Edit /etc/sudoers using the text editor nano:nano /etc/sudoers
Scroll down the file and find where root is defined:..
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
..
Append the following right after root ALL=(ALL) ALL:deployer ALL=(ALL) ALL
This section of the /etc/sudoers file should now look like this:..
## The COMMANDS section may have other options added to it.
##
## Allow root to run any commands anywhere
root ALL=(ALL) ALL
deployer ALL=(ALL) ALL
..
Press CTRL+X and confirm with Y to save and exit.# Create a sample Rails application
rails new my_app
# Enter the application directory
cd my_app
# Create a sample resource
rails generate scaffold Task title:string note:text
# Create a sample database
RAILS_ENV=development rake db:migrate
To test that your application is set correctly and everything is
working fine, enter the app directory and run a simple server via rails s:# Enter the application directory
cd my_app
# Run a simple server
rails s
# You should now be able to access it by
# visiting: http://[your droplet's IP]:3000
# In order to terminate the server process,
# Press CTRL+C
my_app directory to initiate a repository:# !! These commands are to be executed on
# your development machine, from where you will
# deploy to your server.
# Instructions might vary slightly depending on
# your choice of operating system.
#
# Make sure to set correct paths for application
# Otherwise Nginx might not be able to locate it.
# Initiate the repository
git init
# Add all the files to the repository
git add .
# Commit the changes
git commit -m "first commit"
# Add your Github repository link
# Example: git remote add origin git@github.com:[user name]/[proj. name].git
git remote add origin git@github.com:user123/my_app.git
# Create an RSA/SSH key
# Follow the on-screen instructions
ssh-keygen -t rsa
# View the contents of the key and add it to your Github
# by copy-and-pasting from the current remote session by
# visiting: https://github.com/settings/ssh
# To learn more about the process,
# visit: https://help.github.com/articles/generating-ssh-keys
cat /root/.ssh/id_rsa.pub
# Set your Github information
# Username:
# Usage: git config --global user.name "[your username]"
git config --global user.name "user123"
# Email:
# Usage: git config --global user.email "[your email]"
git config --global user.email "user123@domain.tld"
# Push the project's source code to your Github account
git push -u origin master
cap install
# mkdir -p config/deploy
# create config/deploy.rb
# create config/deploy/staging.rb
# create config/deploy/production.rb
# mkdir -p lib/capistrano/tasks
# Capified
deploy.rb contains arguments and settings
relevant to the deployment server(s). Here, we will tell Capistrano to
which server(s) we would like to connect and deploy and how.nano text editor:nano config/deploy.rb
Add the below block of code, modifying it to suit your own settings:# Define the name of the application
set :application, 'my_app'
# Define where can Capistrano access the source repository
# set :repo_url, 'https://github.com/[user name]/[application name].git'
set :scm, :git
set :repo_url, 'https://github.com/user123/my_app.git'
# Define where to put your application code
set :deploy_to, "/home/deployer/apps/my_app"
set :pty, true
set :format, :pretty
# Set the post-deployment instructions here.
# Once the deployment is complete, Capistrano
# will begin performing them as described.
# To learn more about creating tasks,
# check out:
# http://capistranorb.com/
# namespace: deploy do
# desc 'Restart application'
# task :restart do
# on roles(:app), in: :sequence, wait: 5 do
# # Your restart mechanism here, for example:
# execute :touch, release_path.join('tmp/restart.txt')
# end
# end
# after :publishing, :restart
# after :restart, :clear_cache do
# on roles(:web), in: :groups, limit: 3, wait: 10 do
# # Here we can do anything such as:
# # within release_path do
# # execute :rake, 'cache:clear'
# # end
# end
# end
# end
Press CTRL+X and confirm with Y to save and exit.deploy.rb, you will need to make some amendments to the production.rb file. You are better modifying the code instead of appending the below block.nano text editor:nano config/deploy/production.rb
Enter your server's settings, similar to below:# Define roles, user and IP address of deployment server
# role :name, %{[user]@[IP adde.]}
role :app, %w{deployer@162.243.74.190}
role :web, %w{deployer@162.243.74.190}
role :db, %w{deployer@162.243.74.190}
# Define server(s)
server '162.243.74.190', user: 'deployer', roles: %w{web}
# SSH Options
# See the example commented out section in the file
# for more options.
set :ssh_options, {
forward_agent: false,
auth_methods: %w(password),
password: 'user_deployers_password',
user: 'deployer',
}
Press CTRL+X and confirm with Y to save and exit.cap production deploy
Comments
Post a Comment