Arch linux Linode Web Server(Apache ,MariaDB ,PHP ,ROR)
最近租了個VPS,把EC2停掉了,也順便體驗一下什麼是開發速度極快的ROR,
在設定上還蠻麻煩的,也參考了些網路一些大大的資料。
最後可以跑 PHP 和 ROR 在同一個伺服器。
Set local
- vim /etc/locale.gen
- locale-gen
Add user(CAKE)
- useradd CAKE -m -s /bin/bash
- passwd CAKE
Pacman Update
- pacman -Syu
- pacman-db-upgrade
- [發生無法更新時]
- pacman-key --init
- pacman-key --populate archlinux
Install
- pacman -S base base-devel
- pacman -S sudo
- pacman -S bash-completion
- pacman -S git
- pacman -S nodejs
- pacman -S ruby
Set Sudo User
- visudo
- [ADD username(CAKE) ]
- CAKE ALL=ALL (ALL)
- [SAVE & EXIT ]
- 鎖住 root : passwd root -l
- logout
防火牆
- pacman -S ufw
- sudo ufw enable
- port
- sudo ufw limit 22/tcp
- ufw allow 80/tcp
- [開機啟動]
- systemctl enable ufw.service
Mysql
- install MariaDB
- sudo systemctl start mysqld
- sudo systemctl enable mysqld
- sudo mysql_secure_installation
ROR
- gem install rails
- gem install rails --no-ri --no-rdoc
- gem update
- [Apache]
- [$] gem install passenger
- [$] passenger-install-apache2-module
- set config [apache config]
- gem install mysql2
- in your porject Gemfile file 設定套件檔案
- 增加 gem 'mysql2' #增加mysql套件
- bundl e update raiils
apache config
##### IN LoadModule(load passenger_module(ror) )
LoadModule passenger_module /home/cake/.gem/ruby/2.0.0/gems/passenger-4.0.18/buildout/apache2/mod_passenger.so
PassengerRoot /home/cake/.gem/ruby/2.0.0/gems/passenger-4.0.18
PassengerDefaultRuby /usr/bin/ruby
…
##### VirtualHost and Alias(set php alias and ror alias)
<VirtualHost *:80>
DocumentRoot /srv/http
<Directory /srv/http>
Allow from all
</Directory>
Alias /_test2013/ /home/cake/web/
<Directory "/home/cake/web/">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RailsEnv development
Alias /home /home/cake/web_ror/home/public
<Directory /home/cake/web_ror/home/public>
#PassengerAppRoot /home/cake/web_ror/home/public
PassengerAppRoot /home/cake/web_ror/home
Allow from all
Options -MultiViews
#RailsBaseURI /rails
</Directory>
</VirtualHost>
ROR create DB
- rails g model YOUR_MODEL_NAME name:string phone:integer birthday:date
- db/migrate/20130923065726_create_pbooks.rb
- 為模組設定檔
- app/models/pbook.rb
- 模組端
- rake db:migrate # (建立)模組設定檔
---- 2014 01/10 UPDATE ----
Mac ROR 設定 以及 別名設定
Apache config
<VirtualHost *:80>
DocumentRoot "/Library/WebServer/Documents"
<Directory /Library/WebServer/Documents>
Allow from all
</Directory>
Alias /_test2014/ /Users/cake/www_web/php_web/
<Directory "/Users/cake/www_web/php_web/">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory>
RailsEnv development
Alias /ruby_blog /Users/cake/www_web/ror_web/blog/public
<Directory /Users/cake/www_web/ror_web/blog/public>
PassengerAppRoot /Users/cake/www_web/ror_web/blog
SetEnv RAILS_RELATIVE_URL_ROOT /ruby_blog
Allow from all
Options -MultiViews
#RailsBaseURI /rails
</Directory>
</VirtualHost>
ROR routes your Application add
scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do # get "home/index" => "home#index" resources :home # resources :another_controller end
Myapp::Application.routes.draw do scope ENV['RAILS_RELATIVE_URL_ROOT'] || '/' do resources :controllerend endresources :another_controller match 'welcome/', :to => "welcome#index" root :to => "welcome#index"
### 2014 01 22 update
如果使用 ubuntu 設定時
1. 將 passenger 設定資料 建立檔案 放入 /etc/apache2/modes-available/ 並且建立連結到 mods-enabled
# ln -s /etc/apache2/modes-avaliable/ror.load /etc/apache2/modes-enabled/ror.load
2. 虛擬目錄設定 放入 sites-available 同樣建立捷徑至 sites-enabled
3. 也可以使用 sudo a2ensite XXXXX 建立捷徑
4. sudo apache2ctl configrtest 測試是否有誤
5. sudo apache2ctl restart
PS 如果發生 403 錯誤,則/etc/apache2/apache.conf 註解掉
<Directory />
...
</Directory>
沒有留言:
張貼留言