Archive

Posts Tagged ‘LAMP’

Errors using Capistrano

April 28th, 2010

“** [out :: myserver] deploy is not in the sudoers file.  This incident will be reported.”  — Solution is here.

Read more…

Andrew Development , , , , ,

Rails: how to change the header (title) for the validation message

March 31st, 2010

The request was simple – how do you change the header (or title) for a validation message.  Using nested resources, I ended up with a weird message:

3 errors prohibited this page[contact attributes] from being  saved

Not very user friendly.   So, I hit Google, blogs and IRC.  So, here the solution I discovered.

<%= error_messages_for ‘c’, :header_message => “Please correct the errors below:”%>

Since this was part of a fields_for block,  I had to add this to my controller method:

@c = @section.contact

Andrew Development , , , ,

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 , , , , , ,

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 , , , , , ,

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 , , , ,

Preparing a VPS for Ruby on Rails

October 5th, 2009

The instructions have been updated here.

Here are the steps I use to install Ruby on Rails on my VPS (www.rackspacecloud.com) a Ubuntu  9.04 (jaunty)

apt-get update
apt-get upgrade
apt-get install build-essential
aptitude install ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby sqlite3 libsqlite3-ruby1.8
aptitude install ruby build-essential libopenssl-ruby ruby1.8-dev
apt-get install sqlite3 libsqlite3-ruby1.8
apt-get install rubygems
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
export PATH=$PATH:/var/lib/gems/1.8/bin
gem install -v=2.3.4 rails
gem install rubygems-update
update_rubygems
gem install rails
gem install -v=2.3.4 rails
export PATH=$PATH:/var/lib/gems/1.8/bin

Andrew Development , , , , , , , , ,

Jumping into Ruby on Rails – Part 2

October 5th, 2009

iStock_000003167001XSmallSo, I’ve made the decision to write my apps in Ruby on Rails.  Now what?

Here are the books I chose to start:

Agile Web Development with Rails, Third Edition

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


Additionally I found an online class at a reasonable rate:

Introduction to Ruby on Rails – I highly recommend the class.  It  gives you an opportunity to ask the “do I understand this correctly?” or “compared to C#, is this the same?” type of questions.


There are some other helpful resources:

Learning Rails – a great site with resources on learning Ruby.

PeepCode Screen Casts -tutorials on Ruby.

Ruby Mine – an IDE for Ruby.  (I’m downloading to try it out and will be writing a review on it later.)


My Lab in the Cloud

So, I’ve set aside a budget for all of this and one thing that I included was a VPS (virtual private server).  Now, I know what you’re thinking, isn’t this a bit overboard for learning RoR?  Perhaps, but I found a provider that offers cloud hosting for as little as $0.015 an hour.  Roughly, that’s about $10 a month.

My production VPS is hosted at another site, which I pay about $30 a month.  It hosts several blogs (including this one) and my email server.

Andrew Development , , , , ,