Pages

Monday 16 November 2015

Rails Deployment on Centos/Redhat

Centos
-------

$ yum -y update

Install the bundle containing development tools by executing the following command:

$ 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.

Run the following to add the EPEL 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 ~/.profile
$ rvm reload

$ rvm requirements
(if got error "Requirements installation failed with status: 1")

$ rvm install 1.8.7

Close the connection and relogin to remove the error: RVM is not a funciton

$ rvm use 1.8.7-p374 --default

$ yum install git

---------------------------------------------------------------------------------------------

MySQL Install

To begin with, a simple MySQL install:


$ sudo yum install mysql-server mysql mysql-devel


Note that we have installed the development libs and headers with the 'mysql-devel' package. This package is required by the mysql Rubygems package which we install later in this article.
Start

We need to start the MySQL server to intiliaze the installation of the base MySQL databases.

$ sudo /etc/init.d/mysqld start

--------------------------------------------------------------------------------------------------------------


$ gem install passenger --no-ri --no-rdoc

$ yum install curl-devel httpd-devel 

The environment is now ready for the compilation. The process takes a few minutes and it’s started by the following command:

Unbale to restart the server

$ sudo chmod o+x "/home/user"

$ passenger-install-apache2-module  

$ ssh-keygen

$ cat id_rsa.pub >> ~/.ssh/authorized_keys

Note: once you've imported the public key, you can delete it from the server.

and finally set file permissions on the server:

$ chmod 700 ~/.ssh
$ chmod 600 ~/.ssh/authorized_keys 

The above permissions are required if StrictModes is set to yes in /etc/ssh/sshd_config (the default).

Ensure the correct SELinux contexts are set:

$ restorecon -Rv ~/.ssh 

Now when you login to the server you won't be prompted for a password (unless you entered a passphrase when you created your key pair). By default, ssh will first try to authenticate using keys. If no keys are found or authentication fails, then ssh will fall back to conventional password authentication.

Once you've checked you can successfully login to the server using your public/private key pair, you can disable password authentication completely by adding the following setting to your /etc/ssh/sshd_config file:

# Disable password authentication forcing use of keys

PasswordAuthentication no

# Enter home directory
cd

#Give permissions

sudo chown -R user:user /path/to/direcrtory        #directory should be application deployment folder
sudo chmod -R g+w /path/to/directory


Create a new virtual host for your application.

Open the /etc/httpd/conf/httpd.conf file and uncomment the following line

NameVirtualHost *:80
At the end of the file, add

<VirtualHost *:80>
   ServerName yourdomain.com
   ServerAlias www.yourdomain.com
   DocumentRoot /home/newUser/my_rails_app/public
   <Directory /home/newUser/my_rails_app/public>
      AllowOverride all
      Options -MultiViews
   </Directory>
  ErrorLog /var/log/httpd/my_rails_app_error.log
  CustomLog /var/log/httpd/my_rails_app_access.log common
</VirtualHost>
Restart apache for the changes to take effect

sudo /etc/init.d/httpd restart

-----------------------------------------------------------------------------------------------------------------------------

Add Gem to your Gemfile
gem 'capistrano'

$ capify .

 Unable to start the Phusion Passenger watchdog because


Permission denied on rvm folder
chcon -R -h -t httpd_sys_script_exec_t /home/user/.rvm/

Getting error:
Starting httpd: Warning: DocumentRoot [/home/user/apps/alc/current/public] does not exist
Solution
 sudo setsebool -P httpd_enable_homedirs 1

 sudo visudo

nano /etc/httpd/conf/httpd.conf
add this conf on httpd.conf
ServerName 127.0.0.1


--------------------------------------------------------------------------------------------------------------------------


Set Up on REDHAT
----------------

yum -y update

Install the bundle containing development tools by executing the following command:

yum groupinstall -y 'development tools'

yum install gcc-c++ patch readline readline-devel zlib zlib-devel
yum install libyaml-devel libffi-devel openssl-devel make
yum install bzip2 autoconf automake libtool bison iconv-devel

gpg --keyserver hkp://keys.gnupg.net --recv-keys D39DC0E3  #if got error: GPG signature verification failed for

curl -L get.rvm.io | bash -s stable

source /etc/profile.d/rvm.sh


---------------------------------------------------------------------------------------------

MySQL Install

To begin with, a simple MySQL install:


sudo yum install mysql-server mysql mysql-devel


Note that we have installed the development libs and headers with the 'mysql-devel' package. This package is required by the mysql Rubygems package which we install later in this article.
Start

We need to start the MySQL server to intiliaze the installation of the base MySQL databases.

sudo /etc/init.d/mysqld start

yum install curl-devel httpd-devel



No comments:

Post a Comment