Setup Ruby on Rails, Apache, MySQL, Passenger and more on a bare Debian install

This is what I use to setup up a server, hope it helps someone.

Setup IPTables

Your server will initially have all ports blocked so you need to edit /etc/iptables and add

-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 10000 -j ACCEPT

Setup MySQL

aptitude update
aptitude upgrade
aptitude dist-upgrade
shutdown -r now
aptitude install build-essential -y
aptitude install mysql-server mysql-client libmysqlclient15-dev libmysql-ruby -y
mysqladmin -u root password yourpassword

Setup Ruby

aptitude install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby -y
ruby -v
ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
ln -s /usr/bin/ri1.8 /usr/local/bin/ri
ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
ln -s /usr/bin/irb1.8 /usr/local/bin/irb
mkdir sources
cd sources/
wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
tar xzvf rubygems-1.2.0.tgz
cd  rubygems-1.2.0
ruby setup.rb
ln -s /usr/bin/gem1.8 /usr/bin/gem
gem -v
gem update
aptitude install imagemagick librmagick-ruby1.8 librmagick-ruby-doc libfreetype6-dev xml-core -y

Update RubyGems to 1.3+

gem install rubygems-update -v=1.3.4
update_rubygems

Install Rails

bc. gem install rails

Apache

aptitude install apache2 apache2-mpm-prefork apache2-utils libexpat1 ssl-cert

Phusion Passenger

gem install passenger
passenger-install-apache2-module
apt-get install apache2-prefork-dev
apt-get install libapr1-dev
passenger-install-apache2-module

Add the following to /etc/apache2/httpd.conf

LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-2.2.5
PassengerRuby /usr/bin/ruby1.8

Configure a site into Apache

Create a file in /etc/apache2/sites-available such as

<VirtualHost *>
ServerName serverpulsehq.com
ServerAlias www.serverpulsehq.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
DocumentRoot /home/serverpulsehq.com/application/public
RailsEnv    development
</VirtualHost>

To switch rewrite on and enable a site

a2ensite serverpulsehq.com
a2enmod reload

Webmin

apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl libmd5-perl
wget http://prdownloads.sourceforge.net/webadmin/webmin_1.470_all.deb
dpkg --install webmin_1.470_all.deb

Webmin via proxy

Need to be able to switch off SSL for webmin this is done via the UI.

Enable some apache modules

a2enmod proxy
a2enmod proxy_http

Add the following directives to the Apache configuration file: /etc/apache2/httpd.conf

ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Allow from all
</Proxy>
ProxyPass /webmin/ http://localhost:10000/
ProxyPassReverse /webmin/ http://localhost:10000/

Add the following lines to /etc/webmin/config

webprefix=/webmin
webprefixnoredir=1
referer=apachehost

Switch off SSL

Edit /etc/webmin/miniserv.conf and disable ssl redirect ssl_redirect=0 and ssl=0

/etc/init.d/apache2 reload

Astrails-safe (For backups to S3)

Create the astrails conf file in /root.

apt-get install libxml2-dev
apt-get install libxslt-dev
gem install aws-s3
gem install archive-tar-minitar
gem install nokogiri
gem install hoe
gem install rcov
gem install net-sftp
gem install astrails-safe --source http://gems.github.com/

PHP5

aptitude install libapache2-mod-php5 php5 php5-common php5-curl php5-dev php5-gd php5-imagick php5-mcrypt php5-memcache php5-mhash php5-mysql php5-pspell php5-snmp php5-sqlite php5-xmlrpc php5-xsl php5-cli

Install Git

aptitude install build-essential libcurl3-gnutls-dev gettext
wget http://kernel.org/pub/software/scm/git/git-1.6.5.1.tar.gz
tar xvzf git-1.6.5.1.tar.gz
cd git-1.6.5.1
./configure
make prefix=/usr
make install prefix=/usr

Zip and Unzip

apt-get install zip
apt-get install unzip

Configure Email

aptitude install exim4
/etc/init.d/exim4 restart
dpkg-reconfigure exim4-config

Use the following options

No
internet site; mail is sent and received directly using SMTP 
OK
Take all the default