Sexy Errors - Passenger by Phusion 3
Just to show what value add really means, we have a company that is dedicated to making good products. They pay attention to detail and it shows by error screens that look like this. Job well done Phusion.

Ubuntu 8.04 Rails Server Using Passenger - Part 2 26
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
sudo /etc/init.d/gpm startMod_Rails
To Start the installation of passenger after it has been installed via the gem run the following command:
sudo passenger-install-apache2-moduleThis 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.confScroll 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-1.0.5/ext/apache2/mod_passenger.so
RailsSpawnServer /usr/lib/ruby/gems/1.8/passenger-1.0.5/bin/passenger-spawn-server
RailsRuby /usr/bin/ruby1.8
NameVirtualHost *:80Now 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/testOnce 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.
<VirtualHost *:80>
ServerName test.demo.rails
DocumentRoot /var/rails/test/public
</VirtualHost>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 testCreating 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/railsNow 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 testOnce 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.ymlNow 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: testLast 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/.htaccessTesting 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 restartEdit the /etc/hosts file on your client computer if you do not have DNS setup and add the following line.
SERVER_IPADDRESS test.demo.railsNow 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-keygenNow 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@ubuntuNow 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_keysOnce 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 noThat 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
Ubuntu 8.04 Rails Server Using Passenger 20
Introduction
So before my monstrous OpenSolaris 2008.05 post on setting up a Ruby on Rails server I decided to write a guide on setting up a Ubuntu 8.04 server guide for all you Slicehost users! I decided to write this guide because of the new optimized kernel that was added to Ubuntu Server 8.04 for virtualized environments. I also wanted a complete guide that would be a solid reference and now just have bits and pieces for upcoming sysadmins will get lost when reading.
For simplicity I will start with a black machine and build upon that. Use the comments section for specific questions or starting points. I will try to do my best at answering any and all questions.
Requirements
This section will go over the simple requirements of the entire setup.
Hardware
Ubuntu 8.04 Server - This could be anything below:
- Slicehost
- VMware
- Bare Metal Install
Software
- Apache 2.2.8
- MySQL/PostgreSQL/SQLite3
- Git
- Ruby
- Rubygems
- Rails
- Capistrano
- RSpec
- Ultrasphinx
- Passenger
Installation of Software
First thing before we start installing anything on this machine we must update the server. This is very simple with Ubuntu, it is two simple commands and you are all set. You only need to reboot the machine if a kernel was installed.
sudo apt-get update
sudo apt-get dist-upgradeNow that the machine is updated we must install some essential tools in order to build software on this server. Once we are done with the setup it would be a good idea to remove these tools to increase security on our server.
sudo apt-get install build-essentialNow we are all set with the preparation of the server and we can start installing the software we need to get going.
Web Server
For the web server I chose to use Apache 2 because of the new Passenger gem or (mod_rails). This gem is great because of the simplicity to deploy new applications.
sudo apt-get install apache2 apache2-devDatabase Server
The database server that should be used is completely up to your preference. My recommendation is PostgreSQL. PostgreSQL is a very robust and fast database server that is rock solid. It does use a lot of resources so for Slicehost it may not be the best choice. A major player for a slim and fast database for Slicehost should be SQLite3. It is a wonderful database and should be thrown out so quickly because of its lack of a client/server architecture.
For this tutorial I will install MySQL because of its popularity with the Rails community.
sudo apt-get install mysql-serverWhen prompted enter a root password, make this complex and write it down.
Version Control
Git is the most sexy version control system every created. I will never look back to subversion again. Now that capistraon and redmine both support git I have no reason to even thing about those awful three letters.
To install git is yet another apt-get command away. Run the following command in the terminal of your new server.
sudo apt-get install git-core curl gitwebgitweb is an optional web frontend for your applications. I do not use it because I use GitNub a RubyCocoa application for the Mac.
Once that finishes git is completely installed and ready to go.
Ruby
Installing Ruby on Ubuntu 8.04 is quite simple. Just another apt-get and you are all set... almost. Since the inception of Ruby 1.9.0 distributions have been naming the current stable release of ruby "ruby1.8" That being said we will make a couple symlinks.
Ruby 1.8.6
To install all the tools you will want on this server run the following command:
sudo apt-get install ruby1.8 ruby1.8-dev rdoc1.8 ri1.8 libopenssl-ruby1.8Rubygems
I refuse to install Rubygems with apt-get. This is such a terrible idea in my opinion. There is no reason to install rubygems with a package manager because it can update itself. I will go over how to update rubygems later in this howto.
wget http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz
tar -xzf rubygems-1.1.1.tgz
cd rubygems-1.1.1
sudo ruby1.8 setup.rbOptional: Once you are done with install just run the next three commands to make using gems and Rubygems just as before.
sudo ln -s /usr/bin/gem1.8 /usr/bin/gem
sudo ln -s /usr/bin/ruby1.8 /usr/bin/ruby
sudo ln -s /usr/bin/irb1.8 /usr/bin/irbRecommended Gems
Here is a list of recommended gems that should be installed once rubygems is installed. At the very least you must install rails and passenger.
sudo gem install rails
sudo gem install capistrano
sudo gem install rspec
sudo gem install ultrasphinx
sudo gem install passenger
sudo gem install mysqlPart Two
Next week I will go over how to connect all the pieces together and get a sexy Ruby on Rails server running smoothly. I will go over configuring git on your local computer as well as setting up passenger and capistrano to function with all of the above sexy applications we just installed.
Pictrails: Up and Running
Just a quick note. I have rolled out a version of pictrails at http://benssite.org. I'm posting any of my new pictures there. As well as soon moving some of my old pictures over. In addition, I'm continuing to add features. The next feature on the boards is allowing for a custom specification of the front-page gallery by allowing the user to handpick pictures from other galleries instead of having a special gallery just for the front-page.
-Ben
Pictrails: RoR Based Web-gallery
Hello everyone, so if you haven't noticed I have not been posting much to Sysadmins' Chronicles lately. Well other then school, which has been consuming much of my time, I've been working on Pictrails. Pictrails is a web gallery written in Ruby on Rails. Currently my branch of the project is on Github at http://github.com/unilogic/pictrails. The original project is by a guy named Cyril Mougel and he has the master branch of the project here: http://github.com/shingara/pictrails. Currently my branch has the following features:
- Photo-blog like front page (pictures for front-page are from selected gallery/album)
- RSS feed of the front page photos and descriptions
- Support for both RMagick (ImageMagick) and ImageScience (FreeImage)
- Ability to create several galleries
- Ability to create several pictures in a gallery
- Ability to create a gallery from a defined directory on the same server as Pictrails (Mass Upload)
- Show EXIF information from the picture
- Download original photo
- Aggressive caching of all public pages including RSS feed
- Admin interface with login to add/edit/delete galleries, pictures, manage settings, and users
- Settings to control the following
- Define the thumbnails and pictures dimensions
- Reset the caching system
- Define the number of pictures per page shown per page
- Define the number of galleries shown per page
- Enable/Disable showing of EXIF info and downloading of original photos
- Regenerate thumbnails and shown pictures based on new dimensions
- Limit the number of items in your RSS feed
- Select Image Processor (Rmagick or ImageScience)
- Select the gallery the front-page is based on
The catalyst for me working on this project was http://benssite.org, which is my own web gallery based on two web application. SimpleGallery (my own app) runs the front page, and all the albums in the Gallery are hosted on Gallery. Ron and I are slowly trying to migrate away from any PHP based web application which Gallery is written in, and no web gallery written in RoR currently is available that suits my needs. Let alone running two web application for one site is a bit ridiculous.
Feel free to post any comments or suggestions here. The official bug tracking system for the master branch of the project is available at http://dev.shingara.fr/projects/show/3. However, currently I don't pay attention to it as I'm not a member of the development team of the official project. Also feel free to send me any messages on GitHub.
I will post again once I have http://benssite.org converted over to Pictrails, so you can see a full demo. Till then fair well and have a great day!
Ben
Older posts: 1 2