顯示具有 ror 標籤的文章。 顯示所有文章
顯示具有 ror 標籤的文章。 顯示所有文章

2015/02/04

Ruby on rails on Centos 7 with apache2 and passenger

Before doing following steps, please turn off selinux

vim /etc/selinux/config
find this line SELINUX=enforcing, and change to SELINUX=disabled
and reboot

Install LAMP

yum install httpd mariadb-server mariadb php php-mbstring php-mysql php-gd mysql mysql-develStart and enable phpMyAdmin
sudo yum install epel-release
sudo yum install phpmyadmin

Install rvm

gpg –keyserver hkp://keys.gnupg.net –recv-keys D39DC0E3
\curl -sSL https://get.rvm.io | bash -s stable

Use rvm install ruby

rvm install ruby
rvm –default use 2.2.0

Install rails and bundle

gem install rails
gem install bundle

Install passenger and dependency

gem install passenger
sudo yum install libcurl-devel
sudo yum install httpd-devel
sudo yum install apr-devel
sudo yum install apr-util-devel

Install passenger with apache2

passenger-install-apache2-module
Add following lines in /etc/http/conf/httpd.conf or create file /etc/httpd/conf.d/passenger.conf

LoadModule passenger_module /home/apple/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.58/buildout/apache2/mod_passenger.so

<IfModule mod_passenger.c>

PassengerRoot /home/apple/.rvm/gems/ruby-2.2.0/gems/passenger-4.0.58

PassengerDefaultRuby /home/apple/.rvm/gems/ruby-2.2.0/wrappers/ruby

</IfModule>

Create new ror project

cd /var/www/html
rails new ror -d mysql
configure /var/www/html/ror/config/database.yml file

Add following lines to /etc/httpd/conf/httpd.conf

RailsEnv development
<VirtualHost *:80>
      ServerName localhost
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /var/www/html/ror/public
      <Directory /var/www/html/ror/public>
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
         # Uncomment this if you're on Apache >= 2.4:
         Require all granted
      </Directory>
</VirtualHost>

sudo systemctl restart httpd.service

Trouble shooting phpmyadmin not show correctly

add lines after alias

alias /phpmyadmin /usr/share/phpMyAdmin
alias /phpMyAdmin /usr/share/phpMyAdmin

<Location /phpmyadmin>
   PassengerEnabled off
</Location>
<Location /phpMyAdmin>
   PassengerEnabled off
</Location>

2014/12/19

05.Build Ruby on Rails Development Environment with Apache2 module passenger

1.Install ruby, rubygems, basic build-essential

sudo apt-get install ruby-full rubygems build-essential


2.Install apache2
sudo apt-get install apache2 apache2-mpm-prefork apache2-prefork-dev libcurl4-openssl-dev

3.Install mysql
sudo apt-get install mysql-server mysql-client 
sudo apt-get install libmysql-ruby libmysqlclient15-dev 
sudo gem install mysql
sudo apt-get install rubygems

4.Install rails use gem
sudo gem install rails

5.Install passenger use gem
sudo gem install passenger

6.build passenger module with apache2
sudo passenger-install-apache2-module
7.add following lines into /etc/apache2/apache2.conf file
LoadModule passenger_module /var/lib/gems/1.9.1/gems/passenger-4.0.56/buildout/apache2/mod_passenger.so
   <IfModule mod_passenger.c>
     PassengerRoot /var/lib/gems/1.9.1/gems/passenger-4.0.56
     PassengerRuby /usr/bin/ruby1.9.1
   </IfModule>




8.Enable the mod_rewrite
sudo a2enmod rewrite

9.start new rails project called my_project in /var/www/my_project
cd /home/your-username/
rails new my_project -d mysql


10.Create the file in /etc/apache2/sites-available/your.domain.name.com
<VirtualHost *:80>
      ServerName your.domain.name.com
      # !!! Be sure to point DocumentRoot to 'public'!
      DocumentRoot /home/your-username/my_project/public
      RailsEnv development
      <Directory /home/your-username/my_project/public >
         Allow from all
         Satisfy Any
         # This relaxes Apache security settings.
         AllowOverride all
         # MultiViews must be turned off.
         Options -MultiViews
         # Uncomment this if you're on Apache >= 2.4:
         # Require all granted
      </Directory>
</VirtualHost>

11.Enable your site, and disable the default website
sudo a2ensite your.domain.name.com
sudo service apache2 restart


12.Edit /etc/hosts
127.0.0.1 your.domain.name.com


13.Set default mysql password
service mysql stop 
mysqld_safe --skip-grant-tables 
mysql -u root 
use mysql 
update user set password=PASSWORD("NEW_ROOT_PASSWORD") where User='root';
flush privileges;
quit
service mysql restart      
14.Edit database config file in /var/www/my_project

cd /var/www/my_project/config/
vim database.yml
edit the default empty password to your new password
15.Install gemfile and database

cd /var/www/my_project/

bundle install

rake db:create db:migrate


16.Start apache2 and mysql at boot time
update-rc.d apache2 enable
update-rc.d mysql enable