Radu Cojocaru Blog

Web development (RubyOnRails) and iPhone development.
RSS icon Email icon Home icon
  • How to setup a VPS with Ubuntu

    Posted on July 29th, 2009 radu 1 comment

    Steps:

    1. Add user with admin rights
      adduser radu
      visudo

      add line:

      radu   ALL=(ALL) ALL
    2. Secure SSH access
      nano /etc/ssh/sshd_config

      add lines:

      Port 380
      X11Forwarding no
      AllowUsers radu
      PermitRootLogin no
    3. Update packages sources
      sudo aptitude update
    4. Set system locale
      sudo locale-gen en_GB.UTF-8
      sudo /usr/sbin/update-locale LANG=en_GB.UTF-8
    5. Update system
      sudo aptitude safe-upgrade
      sudo aptitude full-upgrade
      sudo aptitude install build-essential
    6. Install Apache and PHP
      sudo aptitude install apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 ssl-cert
      sudo 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
    7. Install mysql
      sudo aptitude install mysql-server mysql-client libmysqlclient15-dev libmysql-ruby1.8 -y
    8. Install DNS tools
      sudo apt-get install bind9
      sudo apt-get install dnsutils
    9. Install Webmin
      wget http://puzzle.dl.sourceforge.net/sourceforge/webadmin/webmin_1.441_all.deb
      sudo apt-get install libnet-ssleay-perl libauthen-pam-perl libio-pty-perl libmd5-perl
      sudo dpkg --install webmin_1.441_all.deb

    Tips:

    # check Ubuntu version
    cat /etc/lsb-release
     
    # restart apache
    sudo /etc/init.d/apache2 reload
     
    # restart apache without closing existing connections
    sudo apache2ctl graceful
     
    # compress
    tar -cvzf file.tar.gz dir/              
     
    # decompress
    tar -xvzf file.tar.gz
     
    # reload SSH configuration
    /etc/init.d/ssh reload
  • Generate PDFs in Rails using Prawn

    Posted on June 9th, 2009 radu No comments

    I needed recently the ability the generate PDFs from a Rails application (for a personal project). I decided to try Prawn library and it was quite enjoyable: all the code to generate PDFs goes into views (so you can use all your helpers) and it’s pretty easy to create PDFs with a custom layout (boxes in different positions on the page).

    Here are some links to the resources I used:

    The PDFs that I need to generate were not so complicated (some text in boxes positioned in custom places on the page and a table) and Prawn was a very good solution for that. I’ll write a new post when I’ll use more advanced capabilities like the use of images and fonts.

  • How to Configure ActionMailer with a Gmail Account

    Posted on May 2nd, 2009 radu 4 comments

    Gmail authentication uses SSL and you need to have tlsmail gem installed:

    gem install tlsmail

    Actual configuration lines go into config/environments/production.rb:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    # required by Gmail
    require 'tlsmail'
    Net::SMTP.enable_tls(OpenSSL::SSL::VERIFY_NONE)
     
    # ActionMailer configuration
    config.action_mailer.perform_deliveries = true
    config.action_mailer.delivery_method = :smtp
    config.action_mailer.default_charset = "utf-8"
    config.action_mailer.raise_delivery_errors = true
     
    ActionMailer::Base.smtp_settings = {
      :domain => "DOMAIN-HERE.COM", :user_name => 'USERNAME-HERE', :password => 'PASSWORD-HERE',
      :address => 'smtp.gmail.com', :tls => true, :port => 587, :authentication => :login
    }

    Don’t forget to replace the credentials above with the credentials from your account.