Archive

Posts Tagged ‘Open Source’

Configure Apache with a Server Alias

March 10th, 2010

Notes on setting up apache for multiple web sites:

In the /etc/apache2 directory you have two directories:
- sites-available
- sites-enabled

The sites-available directory contains configuration files for each website.
The sites-available contains links to the configuration file in the sites-available directory.  It does not contain the file itself.

The mistake that is made at times is that *all* configs are placed in one file – default.

So, for a domain name like domain.com you would create a file called domain.com in the sites-available directory with the following:

NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/domain
ServerName www.domain.com
Server Alias domain.com
</VirtualHost>

you would do:  /ln -s /etc/apache2/sites-available/domain.com /etc/apache2/sites-enabled/domain.com

OR

a2ensite domain.com (from within the sites-available) directory.

finally:  /etc/init.d/apache2 reload

So, in a nutshell — create a file per domain name — use ServerAlias to cover www.domain.com and domain.com.

Andrew Hosting , , , , , ,

Jumping into Ruby on Rails – Part 3

February 5th, 2010

Well, I’ve been working on learning Ruby on Rails for several months now.  The past couple of months, I’ve focused more on my studies and I’m finally feeling comfortable with it.

I thought it would be best to share what I think would be the best way to approach learning Ruby on Rails based on all of my experiences.  So, here are my suggestions

1. Learn Ruby on Rails on Linux or a Mac.

Why?  It’s just easier.  An example to this is getting the MySQL gem installed on Windows – after hours of trying to figure this out, I finally gave up and started to use Linux.  You will spend hours trying to get something to work under Windows and to me that is just wasted time.  And I tried all different kinds of approaches – Cygwin, Instant Rails, etc.

2. Learn Ruby

Here are some suggestion:

Programming Ruby 1.9: The Pragmatic Programmers’ Guide (Facets of Ruby)

Free (if you buy a book) class.

Also, most Ruby on Rails books will give you a sufficient overview to the Ruby language to get started.

3. Expect gaps of informaton

This was a *huge* problem for me.  I started working my way through the Agile Web Development with Rails book, that presents itself as a book  from a beginner to an expert.  Well, I discovered that the book *expects* you know the nuances of Rails.

I’ve looked at a good number of books and found this one to be a great one to start with:

Ruby on Rails Bible

Note:  While the book was published in 2008, it covers Rails 1.2 – which was current in 2005.  So the book is a *bit* dated.  However, it does present itself with knowledge about Rails that other books leave out.  Also, as a co-worker pointed out, the web site for the book is – uh, well – broken.

So, specifically, as most Railists know – RoR is convention over configuration – and what I find missing in most books is a good explanation of the conventions.

4. Watch some screen casts:

Free

Railcasts

TeachMeToCode.com ** check out the Flitter tutorial

Paid

PeepCode ** $149 a year – has tutorials on Ruby, Rails, and much more!

Well, that’s my advice.  Let me know if you have any suggestions!

Andrew Development , , ,

Error installing libxml-ruby

February 1st, 2010

So this:

sudo gem install -r libxml-ruby

Gives you this:

ERROR:  Error installing libxml-ruby:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
checking for socket() in -lsocket… no
checking for gethostbyname() in -lnsl… yes
checking for atan() in -lm… no
checking for atan() in -lm… yes
checking for inflate() in -lz… yes
checking for iconv_open() in -liconv… no
checking for libiconv_open() in -liconv… no
checking for libiconv_open() in -llibiconv… no
checking for iconv_open() in -llibiconv… no
checking for iconv_open() in -lc… yes
checking for xmlParseDoc() in -lxml2… no
checking for xmlParseDoc() in -llibxml2… no
checking for xmlParseDoc() in -lxml2… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
–with-opt-dir
–without-opt-dir
–with-opt-include
–without-opt-include=${opt-dir}/include
–with-opt-lib
–without-opt-lib=${opt-dir}/lib
–with-make-prog
–without-make-prog
–srcdir=.
–curdir
–ruby=/usr/bin/ruby1.8
–with-iconv-dir
–without-iconv-dir
–with-iconv-include
–without-iconv-include=${iconv-dir}/include
–with-iconv-lib
–without-iconv-lib=${iconv-dir}/lib
–with-zlib-dir
–without-zlib-dir
–with-zlib-include
–without-zlib-include=${zlib-dir}/include
–with-zlib-lib
–without-zlib-lib=${zlib-dir}/lib
–with-socketlib
–without-socketlib
–with-nsllib
–without-nsllib
–with-mlib
–without-mlib
–with-mlib
–without-mlib
–with-zlib
–without-zlib
–with-iconvlib
–without-iconvlib
–with-iconvlib
–without-iconvlib
–with-libiconvlib
–without-libiconvlib
–with-libiconvlib
–without-libiconvlib
–with-clib
–without-clib
–with-xml2-config
–without-xml2-config
–with-xml2-dir
–without-xml2-dir
–with-xml2-include
–without-xml2-include=${xml2-dir}/include
–with-xml2-lib
–without-xml2-lib=${xml2-dir}/lib
–with-xml2lib
–without-xml2lib
–with-libxml2lib
–without-libxml2lib
–with-xml2lib
–without-xml2lib
extconf failure: need libxml2.

Install the library or try one of the following options to extconf.rb:

–with-xml2-config=/path/to/xml2-config
–with-xml2-dir=/path/to/libxml2
–with-xml2-lib=/path/to/libxml2/lib
–with-xml2-include=/path/to/libxml2/include

So, do this:

sudo apt-get install libxml2-dev

And this again:

sudo gem install -r libxml-ruby

Andrew Development , , , , , ,

Rails Newb – how to install will_paginate

January 24th, 2010

One of the frustrating things about Rails is coming up to speed with everyone else.  A very simple task can be difficult, just because you haven’t done a particular task yet.  Well, that’s ok.  That’s what the community is for.  So, I’m sharing those little things here.

This one is how to install will_paginate.  Not so much how to install it – but how to add a new source to the gem sources.

gem sources

do you see http://gemcutter.org?  if so, skip the next command

gem sources -a http://gemcutter.org

sudo gem install will_paginate

Andrew Development , , , , , ,

Ubuntu – system tray – task bar – exactly what is it?

January 24th, 2010

I’m using Ubuntu 9.10 – the Karmic Koala and I accidentally deleted the default panel.  Default panel?  Well, if you’re a Windows user, you know it as the Task Bar.

In Ubuntu it’s called it’s called a panel.

So, to get it back, here is what you need to do:

Press Alt+F2 enter gnome-terminal

gconftool-2 –shutdown

rm -rf ~/.gconf/apps/panel

pkill gnome-panel

Tada!

Source: http://ubuntuforums.org/showthread.php?t=392387

Andrew Where is that again? , , ,

Setting up MySQL to use less memory

January 20th, 2010

So, you’re on a VPS with 128MB of RAM or doing development on your Linux workstation and you don’t want MySQL to hog all of the memory — here is what you do:

sudo cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup
sudo cp /usr/share/doc/mysql-server-5.1/examples/my-small.cnf /etc/mysql/my.cnf
sudo /etc/init.d/mysql restart

** verify the version # on the second command line.

Andrew Development , , , , , , ,

Instructions for Installing WordPress on Ubuntu 9.10 (Karmic Koala)

January 19th, 2010

Instructions for Installing WordPress
——————————————————————————————————

# Setup Sources (some VPS vendors block sources)
vi /etc/apt/sources.list

(remove all # in front of all sources)
To save in vi: :qw
To exit without saving: :q!

# Do updates, upgrades, and install essentials
apt-get update
apt-get upgrade
apt-get dist-upgrade
apt-get install build-essential
apt-get install linux-headers-$(uname -r)

# Install a friendly editor if you are not familiar with VI
apt-get install jed

# Now for some security (iptables will probably be installed, running command doesn’t hurt and verifies that it is)
# The config below allows for FTP, SMTP, POP, IMAP, HTTP, HTTPS and SSH
# Adjust according to your needs

apt-get install iptables
iptables -F
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -p icmp –icmp-type any -j ACCEPT
iptables -A INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 25 -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 110 -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 143 -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 443 -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 993 -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 995 -j ACCEPT
iptables -A INPUT -m state –state NEW -m tcp -p tcp –dport 10000 -j ACCEPT
iptables -A INPUT -j REJECT –reject-with icmp-host-prohibited
iptables -A FORWARD -j REJECT –reject-with icmp-host-prohibited

iptables-save > /etc/network/iptables
printf ‘#!/bin/sh\niptables-restore < /etc/network/iptables\n’ > /etc/network/if-pre-up.d/iptables
chmod 754 /etc/network/if-pre-up.d/iptables

# Deny Hosts is a nifty little program that tracks people who try to brute force your root account
apt-get install denyhosts

#Location of config files:
#config: /etc/denyhosts.conf
#datafile: /etc/hosts.deny

# This installs the lamp stack
tasksel install lamp-server

# And now for Wordpress
cd ~/
mkdir downloads
cd downloads
wget http://wordpress.org/latest.tar.gz
mkdir /var/www/wordpress
cd /var/www/
chown -R www-data:www-data wordpress
chmod -R -v 755 wordpress
tar -zxvf ~/downloads/latest.tar.gz –directory=/var/www
cd /var/www
mv wordpress myblog
cp /etc/apache2/sites-available/default /etc/apache2/sites-available/default.org
jed /etc/apache2/sites-available/default

#add the following section to the top
#-START——————————————
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /var/www/myblog
ServerName www.myblog.com
</VirtualHost>
#-END——————————————–
/etc/init.d/apache2 restart

#Setup a database for WordPress
#Change command below according to your needs

mysqladmin -u root -p create wordpress-myblog
mysql -u root -p
CREATE USER ‘wp-myblog’@'localhost’ IDENTIFIED BY ‘NiftyPasswordGoesHere’;
FLUSH PRIVILEGES;
GRANT ALL PRIVILEGES ON *.* TO ‘wp-myblog’@'localhost’ WITH GRANT OPTION;
FLUSH PRIVILEGES;
USE wordpress-myblog;

#Finally point your domain DNS records to your IP address and complete setup.

Andrew Hosting, How-to , , , , , , ,

map.root :controller => does not work.

January 12th, 2010

I’m working on one of my first apps and I discover that the map.root :controller => does not work.  I verified the controller was spelled correctly, but it kept taking me to the Ruby On Rails intro page.

Solution: delete the index.html out of /public/

Andrew Development , , , ,

Problem installing sqlite3-ruby

January 8th, 2010

Getting the following error message?

desktop:~# gem install sqlite3-ruby
Building native extensions.  This could take a while…
ERROR:  Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.

/usr/bin/ruby1.8 extconf.rb
extconf.rb:1:in `require’: no such file to load — mkmf (LoadError)
from extconf.rb:1

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/ext/sqlite3_api/gem_make.out

Solution: apt-get install ruby1.8-dev

Andrew Development , ,

Preparing a VPS for Ruby on Rails – updated

October 11th, 2009

I’ve updatekeep the gearsd my instructions on preparing a VPS for Ruby on Rails, after running into a few issues.  I *think* that installing gems through apt-get caused problems when I was trying to install a CMS called Radiant.

So, here are the new instructions:

apt-get install ruby irb rdoc libopenssl-ruby ruby1.8-dev
apt-get install sqlite3 libsqlite3-ruby1.8

wget http://rubyforge.org/frs/download.php/60718/rubygems-1.3.5.tgz

tar xzvf rubygems-1.3.5.tgz
cd rubygems-1.3.5/
ruby setup.rb

ln -s /usr/bin/gem1.8 /usr/local/bin/gem
ln -s /usr/bin/ruby1.8 /usr/local/bin/ruby
ln -s /usr/bin/rdoc1.8 /usr/local/bin/rdoc
ln -s /usr/bin/ri1.8 /usr/local/bin/ri
ln -s /usr/bin/irb1.8 /usr/local/bin/irb

gem -v
gem update –system
gem install rails

To install MySQL:

apt-get install mysql-server libmysql-ruby1.8 libmysqlclient15off mysql-client-5.0 mysql-common mysql-server-5.0 mysql-server-core-5.0

Andrew Development , , , , , , , , ,