给大家推荐一款很不错的Ubuntu Apache系统很有学习价值,这里我主要讲解Ubuntu Apache系统的应用,包括介绍Ubuntu Apache包背景知识等方面。这里假设你的机器为干净的机器,
我使用的是 Ubuntu Apache-alternate 8.04 命令行安装模式,下面的脚本适合 debian 系的发行版,理论上不兼容 RedHat 系的发行版。为方便起见,我将安装 ROR 环境写了一个 SHELL 脚本,直接执行即可方便的安装 ROR 环境,这里使用的 RAILS 版本为 2.0.2。
请使用 sudo 前缀执行该脚本:
- install_ror.sh - Copy Code#!/bin/bash
- INSTALL_HOME=~/ror_installer
- if [ -d "$INSTALL_HOME" ]; then
- echo INSTALL_HOME directory \"~/ror_installer\" already exist.
- exit 1
- fi
- mkdir $INSTALL_HOME
- pushd $INSTALL_HOME
- # Download files
- apt-get -d -y install \
- ruby libruby-extras \
- libyaml-ruby libzlib-ruby libiconv-ruby libxml-ruby \
- libdbi-ruby \
- libmysql-ruby libdbd-mysql-ruby libdbd-sqlite3-ruby \
- libfcgi-ruby1.8
- wget -t0 -T15 http://rubyforge.org/download.php/35283/rubygems-1.1.1.tgz
- wget -t0 -T15 http://rubyforge.org/download.php/29353/actionmailer-2.0.2.gem
- wget -t0 -T15 http://rubyforge.org/download.php/29350/actionpack-2.0.2.gem
- wget -t0 -T15 http://rubyforge.org/download.php/29551/activerecord-2.0.2.gem
- wget -t0 -T15 http://rubyforge.org/download.php/29552/activeresource-2.0.2.gem
- wget -t0 -T15 http://rubyforge.org/download.php/29553/activesupport-2.0.2.gem
- wget -t0 -T15 http://rubyforge.org/download.php/29554/rails-2.0.2.gem
- wget -t0 -T15 http://rubyforge.org/download.php/29751/rake-0.8.1.gem
- # Install ruby
- apt-get -y install \
- ruby libruby-extras \
- libyaml-ruby libzlib-ruby libiconv-ruby libxml-ruby \
- libdbi-ruby \
- libmysql-ruby libdbd-mysql-ruby libdbd-sqlite3-ruby \
- libfcgi-ruby1.8
- # Install rubygems
- tar xfv rubygems-1.1.1.tgz
- pushd rubygems-1.1.1
- ruby setup.rb
- ln -s /usr/bin/gem1.8 /usr/bin/gem
- popd
- # Install Gem
- gem install rails -l --no-ri --no-rdoc
- # Clean
- popd
- rm -rf $INSTALL_HOME
2) 安装 Ubuntu Apache
同样是 SHELL 脚本安装,请使用 sudo 前缀执行该脚本:
- install_Ubuntu Apache2.sh - Copy Code#!/bin/bash
- # Download files
- apt-get -d -y install Ubuntu Apache2 libUbuntu Apache2-mod-fcgid
- # Install Ubuntu Apache
- apt-get -y install Ubuntu Apache2 libUbuntu Apache2-mod-fcgid
- ln -s /etc/Ubuntu Apache2/mods-available/rewrite.load /etc/Ubuntu Apache2/mods-enabled/rewrite.load
3) 配置 Ubuntu Apache
ROR 应用的 Ubuntu Apache 配置,在 /etc/Ubuntu Apache2/Ubuntu Apache2.conf 的末尾添加以下代码:Ubuntu Apache2.conf - Copy CodeInclude /etc/Ubuntu Apache2/httpd.conf修改 httpd.conf 为以下内容:
- httpd.conf - Copy CodeDefaultInitEnv RAILS_ENV production
- Alias "/redmine" "/var/www/redmine/public/"
- <Directory "/var/www/redmine/public/">
- Options Indexes ExecCGI FollowSymLinks
- AllowOverride all
- Order Deny,Allow
- Allow from All
- </Directory>
- <Location /redmine/>
- AddHandler fcgid-script .fcgi
- FCGIWrapper "/usr/bin/ruby /var/www/redmine/public/dispatch.fcgi" .fcgi
- RewriteEngine on
- RewriteBase /redmine
- RewriteRule ^$ index.html [QSA]
- RewriteRule ^([^.]+)$ $1.html [QSA]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteRule ^(.*)$ dispatch.fcgi?$1 [QSA,L]
- </Location>
4) 配置 ROR 应用
配置 ROR 应用,这里为方便期间,直接使用 sqlite3,ROR 程序为 redmine。请使用 sudo 前缀执行该脚本:
- install_app.sh - Copy Code#!/bin/bash
- INSTALL_HOME=~/install_redmine
- if [ -d "$INSTALL_HOME" ]; then
- echo INSTALL_HOME directory \"~/install_redmine\" already exist.
- exit 1
- fi
- mkdir $INSTALL_HOME
- # Download files
- pushd $INSTALL_HOME
- wget -t0 -T15 http://rubyforge.org/download.php/36468/redmine-0.7.1.tar.gz
- popd
- # Install redmine
- tar xfv $INSTALL_HOME/redmine-0.7.1.tar.gz -C /var/www/
- mv /var/www/redmine-0.7.1 /var/www/redmine
- cp /var/www/redmine/public/dispatch.fcgi.example /var/www/redmine/public/dispatch.fcgi
- #---- begin database.yml ----
- declare -x START_NO=$LINENO; if [ 0 -eq 1 ]; then
- production:
- adapter: sqlite3
- database: db/production.sqlite3
- timeout: 5000
- development:
- adapter: sqlite3
- database: db/development.sqlite3
- timeout: 5000
- test:
- adapter: sqlite3
- database: db/test.sqlite3
- timeout: 5000
- fi; declare -x END_NO=$LINENO
- #---- end database.yml ----
- awk '{if(NR > ENVIRON["START_NO"] && NR < ENVIRON["END_NO"]) {print}}' \
- $0 > /var/www/redmine/config/database.yml
- pushd /var/www/redmine
- rake db:create RAILS_ENV="production"
- rake db:migrate RAILS_ENV="production"
- #Load redmine's default data
- echo en > loc
- rake redmine:load_default_data RAILS_ENV="production" < loc
- rm -f log/production.log
- rm -f public/.htaccess
- popd
- # Clean
- rm -rf $INSTALL_HOME
注:如果在 Linux 下部署,并使用 SQLite3 数据库时,***次访问 redmine 无法创建匿名用户,访问时会发生 500 错误,这是属于 redmine 的问题,要解决此问题,执行以下命令:交互式命令 - Copy Codesudo apt-get install sqlite3
- cd /var/www/redmine/db
- sudo sqlite3 production.sqlite3
- > INSERT INTO users ("created_on", "status", "last_login_on",
"hashed_password", "language", "updated_on", "admin", "type", "firstname",
"lastname", "mail", "auth_source_id", "mail_notification", "login")
VALUES('2008-05-21 04:31:54', 0, NULL, '', '', '2008-05-21 04:31:54', 'f',
'AnonymousUser', '', 'Anonymous', '', NULL, 'f', '');- > .exit
- sudo Ubuntu Apache2ctl restart
- ruby script/server -e production
***,重启 Ubuntu Apache2:重启 Ubuntu Apache2 - Copy Codesudo Ubuntu Apache2ctl restart部署看似简单,写起脚本来可是非常费劲的,不过一劳永逸,以后想要部署可以直接参考使用了。
【编辑推荐】