Ubuntu 8.04 Rails Server Using Passenger - Part 2
May 13th, 2008
Introduction
Here is the, the long awaited second part of my extensive guide on setting up a rails server running on Ubuntu 8.04. Everything should be going smoothly so far and you should be at the point where we need to setup Apache and link everything together. This guide will be quite verbose and much longer than the first one. This is due mostly to all the configuration that will be required. That being said I will contemplate making a third part of this guide that will cover the version control and capistrano recipes. Your thoughts are greatly apreciated, esecially if you want me to cover any other features or topics after you finish reading this guide.
As pointed out by a reader, some people may not have read part 1 yet. Click here to read Part 1 of this guide.
Enabling GPM
Note: You are going to want to have GPM enabled for this if you are just using Ubuntu Server. GPM will allow you to copy and paste output from the terminal using your mouse.
sudo apt-get install gpm
Mod_Rails
To Start the installation of passenger after it has been installed via the gem run the following command:
sudo passenger-install-apache2-module
This will commence the user-friendly installer created by the Phusion team. My hats off to Phusion for making something so incredible sexy.
Run the following command in a new terminal (Alt-F2):
sudo vim /etc/apache2/apache2.conf
Scroll down the page the bottom of the configuration file and right about the "# Include of directories ignores editors" add the following from the output of the passenger install screen. Copy YOUR output NOT mine.
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/passenger-2.0.3
PassengerRuby /usr/bin/ruby1.8
NameVirtualHost *:80
Now that you are done with the passenger install we need to take our rails app and create a virtual host for this app. To do that run the following command.
sudo vim /etc/apache2/sites-available/test
Once the file is open for editing add the following but change the parts specific to your application.
Note: The ServerName MUST be resolvable and resolve to the host that the application is running on.
ServerName test.rails
DocumentRoot /var/rails/test/public
Now that the virtual host is created and we dont need the default page anymore we can enable the test app vhost and disable the default vhost.
sudo a2dissite default
sudo a2ensite test
Creating Test Application
First things first we want to make the directory that all the rails apps we will be using will be stored.
sudo mkdir -p /var/rails
cd /var/rails
Now we want to create the rails skeleton and hand the permissions over to the apache web server.
sudo rails test
sudo chown -R www-data:www-data test
Once this is complete we are now ready to start the customization of the application and setting up the databases.
Setting Up MySQL
We want to login to the mysql database using the root account and the password we set earlier.
sudo mysql -p
--Enter Password--
There are many parts of MySQL which I do not like, like their user management. It is a poor way to manage access to the database. That being said it still is one of the more popular databases and it has a smaller memory footprint than PostgreSQL.
Creating the Databases
mysql> CREATE DATABASE test_development;
mysql> CREATE DATABASE test_test;
mysql> CREATE DATABASE test;
Creating a User and Setting the Password for the test database
The code listed below will add a user called "testapp" with the password "testpass", I recommend that you make your passwords extremely complex. For example a 16 character password would work wonderfully because it is stored in the database.yml so you dont need to memorize it.
mysql> GRANT all privileges ON test_development.* to testapp@"localhost" IDENTIFIED by 'testpass';
mysql> GRANT all privileges ON test_test.* to testapp@"localhost" IDENTIFIED by 'testpass';
mysql> GRANT all privileges ON test.* to testapp@"localhost" IDENTIFIED by 'testpass';
This command below will flush the privileges so that the access levels we just added will take effect.
mysql> FLUSH PRIVILEGES;
Configuring Rails App To Connect To the Database
Now that the database is configured properly we need to tell the rails app we created about the database. This is all done in the database.yml file.
cd /var/rails/test/config
sudo vim database.yml
Now that we are editing the database.yml file, you want to make you file look as follows...
login: &login
adapter: mysql
username: testapp
password: testpass
socket: /var/run/mysqld/mysqld.sock
development:
<<: *login
database: test_development
test:
<<: *login
database: test_test
production:
<<: *login
database: test
Last Minute Tricks...
Passenger does not like the .htaccess file to be in the public directory of the rails app. To remove this file just run the following command.
sudo rm /var/rails/test/public/.htaccess
Testing the Test Application
Now we have setup passenger to point at our rails app and we have to just restart the webserver.
sudo /etc/init.d/apache2 restart
Edit the /etc/hosts file on your client computer if you do not have DNS setup and add the following line.
SERVER_IPADDRESS test.demo.rails
Now open a web browser and type in the URL specified in the hosts file.
You should see the default "Welcome to Rails" screen
Status Checklist
Should Be Completed
Installed All Packages/Gems
Installed Passenger
Setup Apache 2.2.8 to use Passenger
Created Test Rails App
Created Databases
Configure Test Rails App To Use MySQL Database
Test Rails App is Functioning
Left To Do
SSH Goodies
Reader Suggestions
SSH Goodies
This section pertains to ssh security and best practices. SSH is a very important service that is run on any server and must be configured properly in order to be secure. By the end of this section you should have a "more secure" server that can securely be accessed via your computer using RSA encrypted SSH keys instead of passwords.
Creating Keys on your Client
This is a very simple process, all you need to do is run one command.
ssh-keygen
Now that this is running you will want to accept the default location to save your keys and type a password when prompted. This will password protect your keys for added security. You output should look as follows.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/rvalente/.ssh/id_rsa):
Created directory '/home/rvalente/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/rvalente/.ssh/id_rsa.
Your public key has been saved in /home/rvalente/.ssh/id_rsa.pub.
The key fingerprint is:
60:8e:b1:4c:cd:df:4d:82:b2:c4:05:97:0b:1b:56:fd rvalente@ubuntu
Now all you need to do is copy this key from your client machine to you server as follows. Make sure you use the account on your server instead of the account I list below.
scp .ssh/id_rsa.pub SERVER_IPADDRESS:.ssh/authorized_keys
Once that process completes then turn off password authentication on your ssh server. You do that but opening your /etc/ssh/sshd_config and changing this line.
#PasswordAuthentication yes
PasswordAuthentication no
That is it, now your server will use keys for authentication only.
Last but Not Least
I will be writing a part three of this guide for the capistrano/git version control and automation of a rails server. Since there are not many complete guides and they stop before the actual system administration occurs. Before I do this part three I want reader input for anything that you would like to see on top of the capistrano recipes and version control topics. Any input is greatly appreciated.
Thanks for reading!
上海基方太阳能
-Ron
May 13th, 2008
Introduction
Here is the, the long awaited second part of my extensive guide on setting up a rails server running on Ubuntu 8.04. Everything should be going smoothly so far and you should be at the point where we need to setup Apache and link everything together. This guide will be quite verbose and much longer than the first one. This is due mostly to all the configuration that will be required. That being said I will contemplate making a third part of this guide that will cover the version control and capistrano recipes. Your thoughts are greatly apreciated, esecially if you want me to cover any other features or topics after you finish reading this guide.
As pointed out by a reader, some people may not have read part 1 yet. Click here to read Part 1 of this guide.
Enabling GPM
Note: You are going to want to have GPM enabled for this if you are just using Ubuntu Server. GPM will allow you to copy and paste output from the terminal using your mouse.
sudo apt-get install gpm
Mod_Rails
To Start the installation of passenger after it has been installed via the gem run the following command:
sudo passenger-install-apache2-module
This will commence the user-friendly installer created by the Phusion team. My hats off to Phusion for making something so incredible sexy.
Run the following command in a new terminal (Alt-F2):
sudo vim /etc/apache2/apache2.conf
Scroll down the page the bottom of the configuration file and right about the "# Include of directories ignores editors" add the following from the output of the passenger install screen. Copy YOUR output NOT mine.
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.0.3/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/passenger-2.0.3
PassengerRuby /usr/bin/ruby1.8
NameVirtualHost *:80
Now that you are done with the passenger install we need to take our rails app and create a virtual host for this app. To do that run the following command.
sudo vim /etc/apache2/sites-available/test
Once the file is open for editing add the following but change the parts specific to your application.
Note: The ServerName MUST be resolvable and resolve to the host that the application is running on.
ServerName test.rails
DocumentRoot /var/rails/test/public
Now that the virtual host is created and we dont need the default page anymore we can enable the test app vhost and disable the default vhost.
sudo a2dissite default
sudo a2ensite test
Creating Test Application
First things first we want to make the directory that all the rails apps we will be using will be stored.
sudo mkdir -p /var/rails
cd /var/rails
Now we want to create the rails skeleton and hand the permissions over to the apache web server.
sudo rails test
sudo chown -R www-data:www-data test
Once this is complete we are now ready to start the customization of the application and setting up the databases.
Setting Up MySQL
We want to login to the mysql database using the root account and the password we set earlier.
sudo mysql -p
--Enter Password--
There are many parts of MySQL which I do not like, like their user management. It is a poor way to manage access to the database. That being said it still is one of the more popular databases and it has a smaller memory footprint than PostgreSQL.
Creating the Databases
mysql> CREATE DATABASE test_development;
mysql> CREATE DATABASE test_test;
mysql> CREATE DATABASE test;
Creating a User and Setting the Password for the test database
The code listed below will add a user called "testapp" with the password "testpass", I recommend that you make your passwords extremely complex. For example a 16 character password would work wonderfully because it is stored in the database.yml so you dont need to memorize it.
mysql> GRANT all privileges ON test_development.* to testapp@"localhost" IDENTIFIED by 'testpass';
mysql> GRANT all privileges ON test_test.* to testapp@"localhost" IDENTIFIED by 'testpass';
mysql> GRANT all privileges ON test.* to testapp@"localhost" IDENTIFIED by 'testpass';
This command below will flush the privileges so that the access levels we just added will take effect.
mysql> FLUSH PRIVILEGES;
Configuring Rails App To Connect To the Database
Now that the database is configured properly we need to tell the rails app we created about the database. This is all done in the database.yml file.
cd /var/rails/test/config
sudo vim database.yml
Now that we are editing the database.yml file, you want to make you file look as follows...
login: &login
adapter: mysql
username: testapp
password: testpass
socket: /var/run/mysqld/mysqld.sock
development:
<<: *login
database: test_development
test:
<<: *login
database: test_test
production:
<<: *login
database: test
Last Minute Tricks...
Passenger does not like the .htaccess file to be in the public directory of the rails app. To remove this file just run the following command.
sudo rm /var/rails/test/public/.htaccess
Testing the Test Application
Now we have setup passenger to point at our rails app and we have to just restart the webserver.
sudo /etc/init.d/apache2 restart
Edit the /etc/hosts file on your client computer if you do not have DNS setup and add the following line.
SERVER_IPADDRESS test.demo.rails
Now open a web browser and type in the URL specified in the hosts file.
You should see the default "Welcome to Rails" screen
Status Checklist
Should Be Completed
Installed All Packages/Gems
Installed Passenger
Setup Apache 2.2.8 to use Passenger
Created Test Rails App
Created Databases
Configure Test Rails App To Use MySQL Database
Test Rails App is Functioning
Left To Do
SSH Goodies
Reader Suggestions
SSH Goodies
This section pertains to ssh security and best practices. SSH is a very important service that is run on any server and must be configured properly in order to be secure. By the end of this section you should have a "more secure" server that can securely be accessed via your computer using RSA encrypted SSH keys instead of passwords.
Creating Keys on your Client
This is a very simple process, all you need to do is run one command.
ssh-keygen
Now that this is running you will want to accept the default location to save your keys and type a password when prompted. This will password protect your keys for added security. You output should look as follows.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/rvalente/.ssh/id_rsa):
Created directory '/home/rvalente/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/rvalente/.ssh/id_rsa.
Your public key has been saved in /home/rvalente/.ssh/id_rsa.pub.
The key fingerprint is:
60:8e:b1:4c:cd:df:4d:82:b2:c4:05:97:0b:1b:56:fd rvalente@ubuntu
Now all you need to do is copy this key from your client machine to you server as follows. Make sure you use the account on your server instead of the account I list below.
scp .ssh/id_rsa.pub SERVER_IPADDRESS:.ssh/authorized_keys
Once that process completes then turn off password authentication on your ssh server. You do that but opening your /etc/ssh/sshd_config and changing this line.
#PasswordAuthentication yes
PasswordAuthentication no
That is it, now your server will use keys for authentication only.
Last but Not Least
I will be writing a part three of this guide for the capistrano/git version control and automation of a rails server. Since there are not many complete guides and they stop before the actual system administration occurs. Before I do this part three I want reader input for anything that you would like to see on top of the capistrano recipes and version control topics. Any input is greatly appreciated.
Thanks for reading!
上海基方太阳能
-Ron
发表评论
文章已被作者锁定,不允许评论。
相关推荐
rails-nginx-passenger-ubuntu, 关于如何在 Nginx 8.04服务器上启动和运行和乘客的说明 rails-nginx-passenger-ubuntu我关于用 ubuntu 。Nginx 。乘客和mysql建立 Rails的简单制作服务器的笔记。别名echo"alias ll='...
### VirtualBox中安装Ubuntu 8.04 Server 在虚拟化技术越来越被广泛使用的今天,通过虚拟机软件如VirtualBox来模拟不同的操作系统环境已经成为一种非常常见的做法。本篇内容将详细介绍如何在VirtualBox中安装Ubuntu...
$ sudo mount –t iso9660 –o loop /home/xiaoyun/ubuntu-8.04-desktop-i386.iso /cdrom 然后,添加镜像到软件源: $ sudo apt-cdrom –m add 这将添加 Ubuntu 8.04 的镜像到软件源中。现在可以安装 build-...
Ubuntu 8.04 Server版安装图解 很完整
ubuntu8.04默认的源ubuntu8.04默认的源ubuntu8.04默认的源ubuntu8.04默认的源ubuntu8.04默认的源ubuntu8.04默认的源ubuntu8.04默认的源ubuntu8.04默认的源
Ubuntu 8.04,代号“Hardy Heron”(苍鹭),是Ubuntu Linux操作系统的一个重要版本,发布于2008年。这个版本带来了许多改进和新特性,为用户提供了更稳定、安全和易用的操作环境。下面将详细介绍Ubuntu 8.04的安装...
### Ubuntu 8.04优化指南详解 #### 一、引言 Ubuntu 8.04 Hardy Heron 是一款备受瞩目的 Linux 发行版,它不仅提供了丰富的功能和优秀的用户体验,还特别注重系统的稳定性和安全性。然而,随着系统功能的增强,对...
ubuntu8.04使用手册,ubuntu8.04使用手册ubuntu8.04使用手册,ubuntu8.04使用手册,ubuntu8.04使用手册,
【标题】"79905-Ubuntu 8.04 GDM-LIST.tar.gz"揭示了这个压缩包文件是专门为Ubuntu 8.04操作系统设计的一个图形桌面管理器(GDM)主题集合。GDM,全称Gnome Display Manager,是GNOME桌面环境下的默认登录管理器,...
Vmware虚拟机下Ubuntu 8.04安装 Vmware虚拟机下Ubuntu 8.04安装可以分为两个部分:Vmware虚拟环境的安装和Ubuntu系统的安装。在Vmware虚拟环境的安装中,我们需要首先安装Vmware Workstation,然后创建一个新的...
### Ubuntu 8.04 安装与配置详解 #### 一、系统初始化 系统初始化是确保Ubuntu系统正常运行的基础步骤。此阶段涉及到的操作主要包括硬盘分区、安装过程中的选择(如语言、时区等),以及安装后的基础设置,如更新...
【Ubuntu 8.04 Server 安装 Oracle 10g 知识点详解】 在 Ubuntu 8.04 Server 上安装 Oracle 10g 是一项技术性较强的任务,需要遵循一系列详细的步骤。以下是安装过程中的关键知识点: 1. **环境准备**: - Ubuntu...
2. **Unity桌面环境**:Ubuntu 8.04采用了Unity界面,这是一个简洁且直观的桌面环境。手册将教你如何使用Launcher(启动器)快速启动应用,调整面板,以及使用Dash(搜索功能)查找文件和应用程序。 3. **软件管理*...
同时,由于我们将安装的是ubuntu-8.04-desktop-i386.iso,因此建议你的内存至少为512MB。 安装前,你需要下载并安装虚拟光驱软件来加载ubuntu-8.04-desktop-i386.iso镜像。挂载ISO后,系统会自动弹出Ubuntu的安装...
Ubuntu 8.04,代号Hardy Heron,是Ubuntu Linux发行版的一个重要版本,于2008年4月24日正式发布。这个版本为桌面用户提供了长达3年的安全更新支持,对于服务器用户则提供了5年的支持期,因此它对广泛的用户群体都...
在Ubuntu 8.04中配置Java、Tomcat与Eclipse MyEclipse开发环境是一项针对Web应用程序开发者的专业技能。本文将深入解析如何在Ubuntu 8.04系统上搭建这套开发环境,涵盖Java环境的配置、Tomcat服务器的安装与启动、...
《Ubuntu 8.04速成手册1.0》是一份专为初学者设计的指南,旨在帮助用户快速掌握Ubuntu 8.04的操作系统安装、配置和日常使用技巧。Ubuntu 8.04,代号“Hardy Heron”,是Ubuntu Linux发行版的一个重要版本,发布于...
《Ubuntu 8.04 速成手册》是一本针对初学者和中级用户的指南,旨在帮助读者快速掌握Ubuntu 8.04(Hardy Heron)操作系统的基本操作和高级技巧。Ubuntu是基于Debian的开源Linux发行版,以其用户友好、稳定性和安全性...