Hi there, This post I want to write as a log of my success on configuring Postgresql database to production for my Rails application.
Let’s get started. I’ve installed Postgresql 8.4 through apt-get.
The first step I do is to change the password of ‘postgres’ user.
Run the command on root shell.
passwd [...]
Hi there, This post I want to write as a log of my success on configuring Postgresql database to production for my Rails application. 
Let’s get started. I’ve installed Postgresql 8.4 through apt-get.
The first step I do is to change the password of ‘postgres’ user.
Run the command on root shell.
passwd postgres
And I usually allow remote access into my Postgresql database. So, I have to edit the file ‘/etc/postgresql/8.4/main/pg_hba.conf’ by seeing this line.
local all all ident
and change it to…
local all all md5
Then restart the service.
/etc/init.d/postgresql-8.4 restart
The second step I usually do is to install the admin pack.
su - postgres psql template1 < /usr/share/postgresql/8.4/contrib/adminpack.sql psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'newpassword';"
The next step is to create a new database and user to be used by your application. Assume the application is named ‘Social Dating’.
createdb socialdatingdb createuser socialdatinguser --pwprompt psql socialdatingdb GRANT ALL TO socialdatinguser
Then you can test CRUD on the database with…
psql -U socialdatinguser -W socialdatingdb
Enjoy Postgresql!
Please share this page to anyone who think it is helpful for them.
Hi guys,
This thread was written by me to be used as a future reference of mine and I would like to share here for some people who is struggling with setting up Rails applications on their own Linode cloud VPS.
First of all, let me introduce what is Linode and why I choose it over its alternatives.
Linode is a cloud VPS provider which is quite well known by people who is working on cloud technology.
Linode offer various cheap plans when compared to competitors and its performance is still better from them. (based on the benchmark I found from here)
With just $19.95/mo, I got 20GB disk space, 200GB outgoing bandwidth (now incoming bandwidth is free) and 512MB of memory.
This entry level offer is unbeatable while compared to Slicehost (now bought and managed by Rackspace), Amazon EC2 or Prgmr.
Let’s me say that before I decide to go with Linode, I’ve research a lot about Rails application hosting which finally ends up with Heroku because my project has a short time of development and deployment so I can’t waste my time setting up a box for it.
When the app is live and running smoothly, now I want to improve my ROI and want to make it more cost effective when I demand for more resources.
That’s the reason why I’m moving out from Heroku and ends up with Linode.
That’s a short introduction why I ends up with Linode and now let’s get started seeing how do I set up a Rails application on Linode cloud VPS successfully.
How to set-up Rails application on Linode.
1st, Sign-up for Linode
Just pick a plan you think it is fit for your needs. For me, the Linode 512 is more than enough by now.
After picked up a plan, you will be asked to enter credit card and choose the data center location, just pick one that close to your target visitors. I saw last time there is Asia data center, anyway, I choose Newark, NJ, USA as my target will be in USA.
2nd, Create your Linux node
After sign-up was completely, now I’m going to create a new node by choosing a linux distribution to be use with. I choose Ubuntu 10.0.4 LTS which is 32-bit because there are many sources saying that 32-bit performance is better than 64-bit of Ubuntu.
Just allocate the disk space and swap size that you think it will fits your needs. For me, I just choose the maximum because I need to setup only single node. If you want to separate database server from your web server, just remain some space for your second node.
After the node was built, just push the “Boot” button to start your node now.
3rd, connect to your node using SSH
Now click on the “Remote Access” tab from your dashboard to see the IP address of your node.
Let’s see the “SSH Access” field, it should have some text like “ssh root@11.22.33.44″.
This is the command being used to connect to your node remotely.
Let’s say you are using Mac OSX or Linux, you can use terminal to execute the command.
Then, enter your specified password and you will ends up connected to your node completely.
Note that, you can remote access into your Linode without entering password by appending your computer’s public key to Linode’s authorized keys. This can be done by…
- Open up your terminal
- If you don’t have an existing public key (the file ‘id_rsa.pub’ in ‘~/.ssh/’ folder), then you should do it by issuing this command
</div> <div>ssh-keygen -t rsa -C "youremail@email.com"</div> <div># Note that you will be asked to enter the passphrase. Just enter and remember it.</div> <div>
- Run this command to copy the content of your public key to the clipboard ‘cat ~/.ssh/id_rsa.pub | pbcopy’
- Now connect to your Linode through ssh
- Create a file ‘~/.ssh/authorized_keys’ and paste the content of your public key there, then save
4th, basic configuration
Begin with updating system, run these commands.
apt-get update apt-get upgrade --show-upgraded
Next is to set the host name. This is not actually a host name or domain name you want your Linode to host. It can be anything. Let’s say I’ve named it ‘mickey’.
Run the following commands. (don’t forget to change ‘mickey’ to your own host name)
echo "mickey" > /etc/hostname hostname -F /etc/hostname
Now it’s time to update your /etc/hosts file to let them know your host name.
I issue the command ‘vi /etc/hosts’ to edit the file.
Add the following lines into the file. (you have to enter your Linode’s IP address in the first line, and the IPv6 in the second line, also don’t forget to change ‘mickey’ and host name with your desired name)
12.34.56.78 mickey.example.com mickey 1234:1234::1234:1234:1234:1234 mickey.example.com mickey
Next, it’s time to configure the time zone. I usually set UTC as my time zone for all of my Linodes.
dpkg-reconfigure tzdata
Select UTC from the list, or just select your desired time zone.
Then you need to make a symbolic link to your time zone info.
ln -sf /usr/share/zoneinfo/UTC /etc/localtime
If you are using any other time zone than UTC, then you should find your time zone info in the ‘/usr/share/zoneinfo/’ directory.
Ok, let’s go to the next step. I hate ASCII, so I configure my box to use UTF-8 by editing the ‘~/.bashrc’ file to include these lines.
export LANG="en_US.UTF-8" export LC_CTYPE="en_US.UTF-8"
The basic configuration is completed now.
5th, installing Ruby
First, you need to install some pre-requisite libraries.
apt-get install build-essential bison openssl libreadline6 libreadline6-dev libcurl4-openssl-dev git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev curl
Note that the above is a single line command.
If you are using MySQL, you need to execute the following command.
apt-get install mysql-server mysql-client
Also, if you are using Image Magick library, run this command.
apt-get install libmagickwand-dev imagemagick
Now it’s time to install Ruby. I choose to use RVM as it can handle multiple versions of Ruby installation. Run this shell command.
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
Check if the RVM was installed correctly.
type rvm | head -1
It should output ‘rvm is a function’. This prove you are correct in this step.
Now I decide to install the latest version of Ruby.
rvm install ruby
If you want to install the specific version of Ruby, you can do it by…
rvm install ruby-1.9.2
Wait a few minutes and it’s time to configure the default version of Ruby to be used by the Linode.
rvm --default use 1.9.2-p290 rvm gem set use global # install gems to this gemset gem install rdoc gem install bundler
Now it’s time to install Passenger and Nginx and make it start up at boot.
gem install passenger rvmsudo passenger-install-nginx-module rvm wrapper 1.9.2-p290@global passenger curl -L http://bit.ly/nginx-ubuntu-init-file > /etc/init.d/nginx chmod +x /etc/init.d/nginx update-rc.d nginx defaults /etc/init.d/nginx start
Wooo Hooo, now my Linode is ready to run Rails app and serve web visitors.
However, for my Linode, I need Postgresql as my production database server. So, I would required to run…
apt-get install postgresql postgresql-contrib apt-get install libpq-dev gem install pg
Now the box we created is fully packed with Ruby, Nginx, Passenger, it’s ready now.
6th, time to deploy your Rails application
We will deploy using another user than root regards to security reason. Let’s add one by…
adduser deploy adduser deploy rvm
Then, logout from current ssh session and re-login using the deploy user.
As I’m using GitHub as my Git server, I need to create a public key for deploy user and add the key to GitHub account.
So, I create a public key by…
ssh-keygen -t rsa -C "youremail@email.com"
Then login to GitHub account and add the key (~/.ssh/id_rsa.pub) to the GitHub account.
Also, I copy the token of my GitHub account.
Then I configure my Git.
git config --global user.name 'FirstName LastName' git config --global user.email 'myemail@email.com' git config --global github.user 'githubusername' git config --global github.token 012345678901234567890 #change the long digit to your GitHub's token
Now get back to your workstation which you are using to develop your Rails application. (The following steps not being run at your Linode box!)
This step is not sure if it required or not, so please try at your own risk.
Create a file ‘setup_load_paths.rb’ in the ‘config’ directory of your Rails application. Then add the following content.
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
RVM.use_from_path! File.dirname(File.dirname(__FILE__))
rescue LoadError
# RVM is unavailable at this point.
raise "RVM ruby lib is currently unavailable."
end
end
ENV['BUNDLE_GEMFILE'] = File.expand_path('../Gemfile', File.dirname(__FILE__))
require 'bundler/setup'
Then add ‘capistrano’ into your Gemfile and run ‘bundle install’.
Now it’s time to prepare capistrano.
capify .
Then prepend the following lines in the file ‘Capfile’ which was created by the above ‘capify’ command.
# Add RVM's lib directory to the load path.
$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
# Load RVM's capistrano plugin.
require "rvm/capistrano"
# Set it to the ruby + gemset of your app, e.g:
set :rvm_ruby_string, 'ruby-1.9.2-p290@global'
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
# Uncomment if you are using Rails' asset pipeline
# load 'deploy/assets'
Dir['vendor/gems/*/recipes/*.rb','vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks
Then edit the file ‘deploy.rb’ in the ‘config’ directory with this content.
set :user, 'deploy'
set :domain, 'myrailsapp.com'
set :application, "myrailsapp"
set :repository, "git@github.com:username/repo.git" # Your clone URL
set :scm, "git"
set :branch, "master"
set :scm_verbose, true
set :deploy_via, :remote_cache
set :scm_passphrase, "password" # The deploy user's password
set :deploy_to, "/home/#{user}/#{domain}"
set :use_sudo, false
require "bundler/capistrano"
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
role :web, domain # Your HTTP server, Apache/etc
role :app, domain # This may be the same as your `Web` server
role :db, domain, :primary => true # This is where Rails migrations will run
namespace :deploy do
task :start do ; end
task :stop do ; end
task :restart, :roles => :app, :except => { :no_release => true } do
run "#{try_sudo} touch #{File.join(current_path,'tmp','restart.txt')}"
end
end
after "deploy:migrations", "deploy:cleanup"
Note that you have to edit each parameters to fit your environment.
Then, you need to configure your Nginx to serve the specified domain name and map to the path to be deployed by capistrano.
Edit the file ‘/opt/nginx/conf/nginx.conf’ and add the following lines.
server {
listen 80;
server_name *.myrailsapp.com;
root /home/deploy/myrailsapp.com/current/public/;
passenger_enabled on;
}
Now it’s time to deploy your Rails application.
capistrano required you to setup for the first time, so you have to run this command for the first time only.
cap deploy:setup
Then, it is a time to deploy actual files.
cap deploy
If you are following the above instructions carefully. You should have a production of your Rails application running now.
Cheers!
Hi there,
Today I’m going to write a post about what I think on comparing between Corona SDK by anscamobile and Cocos2d framework.
As I’m planning to launch a new project that based on mobile platform primarily on Apple iOS 5, I’m considering between Corona SDK and cocos2d and I decide to avoid the native [...]
Hi there,
Today I’m going to write a post about what I think on comparing between Corona SDK by anscamobile and Cocos2d framework.
As I’m planning to launch a new project that based on mobile platform primarily on Apple iOS 5, I’m considering between Corona SDK and cocos2d and I decide to avoid the native iOS framework because I need to build an app that can differentiate from normal app.
Also, productivity is the point too as these two frameworks can be boost productivity while comparing to the original iOS framework by Apple.
After I’ve upgraded my Snow Leopard to Lion, I found many things regard to my development environment doesn’t work anymore.
This is including the process to compile the library readline 6.2 which is a need to be done before installing the latest Ruby. (1.9.2-p290)
When I try to make, I got the error like this.
[...]
After I’ve upgraded my Snow Leopard to Lion, I found many things regard to my development environment doesn’t work anymore.
This is including the process to compile the library readline 6.2 which is a need to be done before installing the latest Ruby. (1.9.2-p290)
When I try to make, I got the error like this.
gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)
i686-apple-darwin11-llvm-gcc-4.2: -compatibility_version only allowed with -dynamiclib
make[1]: *** [libreadline.6.2.dylib] Error 1
make: [shared] Error 2 (ignored)
I wonder why it doesn’t work because I just did the same to install Ruby 1.9.2-p181 on my old Snow Leopard.
Then, after I research some information through Google.
I found this solution to make it works.
After configured the source code with ./configure –prefix=/usr/local
Follow this…
cd shlib sed -e 's/-dynamic/-dynamiclib/' Makefile > Makefile.good mv Makefile.good Makefile cd .. make sudo make install
This works for me and I’m fairly sure it will works for you too.
Hi Rubyists,
As I’m going to start a new project using Ruby on Rails and I just found Rails just released a new version as 3.1.0 Release Candidate 4 and will be out as an official release in a few weeks if everything goes well.
Well, I’m going to use my Mac mini as the [...]
Hi Rubyists,
As I’m going to start a new project using Ruby on Rails and I just found Rails just released a new version as 3.1.0 Release Candidate 4 and will be out as an official release in a few weeks if everything goes well.
Well, I’m going to use my Mac mini as the primary machine to work on this project as it is a hobby project. (anyway, I have a strategy to make money for me as well)
So, the problem is Mac OS X snow leopard already bundled with Ruby 1.8.7 and we need to upgrade it to version 1.9.2.
First, we need to download the source code of Ruby 1.9.2, compile, install and install Rails 3.
Here is detailed instructions.
You need to install readline.
curl -O ftp://ftp.cwru.edu/pub/bash/readline-6.0.tar.gz tar -xvzf readline-6.0.tar.gz cd readline-6.0 ./configure --prefix=/usr/local make sudo make install
Don’t concern on some warning, just make sure there is no error.
Next, you need to download Ruby 1.9.2 from http://www.ruby-lang.org/en/downloads/
Extract the archive, open a terminal and go to the extracted directory.
Then, execute these lines.
./configure --prefix=/usr/local --enable-pthread --with-readline-dir=/usr/local --enable-shared make sudo make install sudo make install-doc
Then, you need to add this line into your “~/.bash_profile” file. (create a new one if it doesn’t exists)
export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"
Close the terminal, open the new one, then check Ruby version using this command.
ruby -v
You will see it is now version 1.9.2!
Bingo, now just install RubyGems, or if installed, execute this command.
gem install rails --pre
–pre state that you want to install a pre-release version which is RC.
So, if Rails 3.1.0 is already an official version, you can ignore –pre parameter.
Hope this help.
Hi symfonians,
I think you probably finding for a solution how to install and use xdebug on Zend Server CE on your Mac OSX like me.
First of all, to say, Mac OSX (snow leopard), Zend Server CE and Symfony 2 didn’t well matched built to work together.
At least, not perfect instantly.
So, if you want to work on those tools, you have to tweak a little bit of your tool to make it works together.
As Zend Server CE came with its own debugger, Zend Debugger, but someone prefer to use xdebug instead of Zend Debugger as the same as me.
Here are the steps how to make xdebug work on Zend Server CE on Mac OSX with Symfony 2.
- Open Zend Server page, http://localhost:10081/
- Disable “Zend Debugger”
- Download xdebug.so binary which I suggest to download at -> http://aspn.activestate.com/ASPN/Downloads/Komodo/RemoteDebugging
- Extract the archive and browse into ’5.3′ folder then copy ‘xdebug.so’ to ‘/usr/local/zend/lib/php_extensions’
- Open ‘/usr/local/zend/etc/php.ini’ and add the following lines above [zend] section
zend_extension=/usr/local/zend/lib/php_extensions/xdebug.so [xdebug] xdebug.remote_enable=1 xdebug.remote_host=”localhost” xdebug.remote_port=9000 xdebug.show_local_vars=On xdebug.var_display_max_data=10000 xdebug.var_display_max_depth=20
- Now restart your Zend Server by ‘sudo /usr/local/zend/bin/zendctl.sh stop’ and ‘sudo /usr/local/zend/bin/zendctl.sh start’
- You should be able to work with xdebug now!
To work with xdebug, I personally love the way by JetBrain’s PhpStorm with their bookmarklet generator, very useful tool.
Hope this help,
Seree
As I’m working on Mac OSX with MAMP before but found difficulty trying to install intl extension.
Yup, it is what so wasting time for me to download icu, compile, download php source, compile intl extension, configure and install.
Seems wasting too much time if I will do myself, so I decide to switch from [...]
As I’m working on Mac OSX with MAMP before but found difficulty trying to install intl extension.
Yup, it is what so wasting time for me to download icu, compile, download php source, compile intl extension, configure and install.
Seems wasting too much time if I will do myself, so I decide to switch from MAMP to Zend Server CE (community edition) because Zend Server CE had already bundled all required libraries for Symfony 2 development.
Anyway, after I’ve added a virtual host into apache, I got many forbidden error which was generated because the default http.conf that specify to deny access from all directories outside of the default document root.
To fix this issue quickly, you have to find the Directory section for ‘/’ path and modify to be like this.
Options FollowSymLinks AllowOverride All Order Deny,Allow Allow from 127.0.0.1
Then restart the apache using zend command like this.
sudo /usr/local/zend/bin/apachectl restart
It will do the trick now!
Hi,
After I’ve solved another problem while working with Doctrine 2 in Symfony 2.0 RC1, I would like to make a quick note here about what’s wrong in the Symfony 2 document about handling file upload using Doctrine’s Lifecycle callbacks aka @ORM\HasLifecycleCallbacks
First of all, when you want to use Lifecycle callbacks, you [...]
Hi,
After I’ve solved another problem while working with Doctrine 2 in Symfony 2.0 RC1, I would like to make a quick note here about what’s wrong in the Symfony 2 document about handling file upload using Doctrine’s Lifecycle callbacks aka @ORM\HasLifecycleCallbacks
First of all, when you want to use Lifecycle callbacks, you don’t have to call $document->upload() in your controller anymore or your app will throw an error.
Secondly, if you follow the instructions from the document, the app will not work like what you think. When you remove the record, the uploaded file didn’t get removed too because you are using PostRemove and query for $document->id within the PostRemove function.
Yup, the PostRemove occurred when the record was removed, so you can’t access the field id anymore, this is the root cause of error that made the uploaded file didn’t get removed after the record was removed.
So, if you want to fix this, you should use PreRemove instead of PostRemove which allow you to query for field id before the record get removed.
PreRemove is the place to insert your logic when the remove process occurred for the record. (like cascading delete, update)
Anyway, one thing that I’m unsure is that what will happen if the record can’t be removed?
Does the PreRemove will occurred even though the record can’t be removed?
I will research more about this and will post the update here when I got an answer.
Hope this help you to fix the problem as well.
UPDATED:
If you want to make the symfony 2 handle file upload with Doctrine completely, you should add the uses of PreUpdate and PostUpdate annotation as well.
Symfony 2.0 RC1 was released a few days ago, do not forget to grab it, it is very stable now!
Today I’m facing an error which made me crazy a few hours.
I’m trying to get the file upload on Symfony 2 done but never success on my Windows + wamp machine.
Yup, like what I’ve written on the subject, when I try to move the file using UploadedFile->move() and tell the framework to guess the file extension for me using UploadedFile->guessExtension().
It always return nil, the getExtension() is working but not useful at all because the uploaded file always be ended with tmp extension.
Even though I can’t found the solution after researched on Google for a few hours.
Until I try to dig into the symfony source code itself and I finally found it is using php_fileinfo extension!
So, I just resolve my issue by enabling the php_fileinfo extension from wamp and it works!
Wasted my few hours… Learn new things…
Archives
- May 2012
- November 2011
- October 2011
- September 2011
- August 2011
- July 2011
- June 2011
- May 2011
- March 2011
- February 2011
- January 2011
- September 2010
- August 2010
- July 2010
- June 2010
- May 2010
- April 2010
- January 2010
- December 2009
- October 2009
- August 2009
- July 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- June 2007
Tags
.net 2008 asp.net asp.net mvc asus eee c# corona cpa doctrine dom eee eee pc Internet Marketing ios iPad iphone iPhone development iphone sdk javascript make money netbook online marketing pagerank passion php playstation playstation 3 ps3 ranking ror ruby on rails self help Self Improvement self motivation seo sql success symfony take action the secret ultra compact laptop ultra compact notebook vb.net web development wordpress





