Getting back to nginx

I recently had to deal with Apache which reminded me how much I loved Nginx.

So I’m in the middle of setting up a new VM with nginx and here’s what I do to build it so I don’t forget. It might also help you :)

$> su
$> apt-get install build_essentials libpcre3-dev libssl-dev
$> cd /usr/local/src
$> wget http://nginx.org/download/nginx-1.1.14.tar.gz
$> tar -xzf nginx-1.1.14.tar.gz
$> cd nginx-1.1.14

$> ./configure --with-http_ssl_module \ 
  --user=nginx \
  --group=nginx \
  --conf-path=/etc/nginx/nginx.conf \
  --pid-path=/var/run/nginx.pid \
  --error-log-path=/var/log/nginx/errors.log \
  --http-log-path=/var/log/nginx/access.log \
  --sbin-path=/usr/local/sbin/nginx \

$> make && make install

Your init script goes in /etc/init.d/nginx

#!/bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/sbin/nginx
NAME=nginx
DESC=nginx

# Include nginx defaults if available
if [ -f /etc/default/nginx ]; then
	. /etc/default/nginx
fi

test -x $DAEMON || exit 0

set -e

. /lib/lsb/init-functions

test_nginx_config() {
	if $DAEMON -t $DAEMON_OPTS >/dev/null 2>&1; then
		return 0
	else
		$DAEMON -t $DAEMON_OPTS
		return $?
	fi
}

case "$1" in
	start)
		echo -n "Starting $DESC: "
		test_nginx_config
		# Check if the ULIMIT is set in /etc/default/nginx
		if [ -n "$ULIMIT" ]; then
			# Set the ulimits
			ulimit $ULIMIT
		fi
		start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
		    --exec $DAEMON -- $DAEMON_OPTS || true
		echo "$NAME."
		;;

	stop)
		echo -n "Stopping $DESC: "
		start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
		    --exec $DAEMON || true
		echo "$NAME."
		;;

	restart|force-reload)
		echo -n "Restarting $DESC: "
		start-stop-daemon --stop --quiet --pidfile \
		    /var/run/$NAME.pid --exec $DAEMON || true
		sleep 1
		test_nginx_config
		start-stop-daemon --start --quiet --pidfile \
		    /var/run/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS || true
		echo "$NAME."
		;;

	reload)
		echo -n "Reloading $DESC configuration: "
		test_nginx_config
		start-stop-daemon --stop --signal HUP --quiet --pidfile /var/run/$NAME.pid \
		    --exec $DAEMON || true
		echo "$NAME."
		;;

	configtest|testconfig)
		echo -n "Testing $DESC configuration: "
		if test_nginx_config; then
			echo "$NAME."
		else
			exit $?
		fi
		;;

	status)
		status_of_proc -p /var/run/$NAME.pid "$DAEMON" nginx && exit 0 || exit $?
		;;
	*)
		echo "Usage: $NAME {start|stop|restart|reload|force-reload|status|configtest}" >&2
		exit 1
		;;
esac

exit 0

Customising FB.ui iframe dialog dimensions

I was faced with making some FB.ui dialogs fit neatly inside and iframe today.
The FB.ui dialogs get their default dimensions, from one of the methods in FB.UIServer.Methods

For example, if you’re usinge FB.ui({method:'stream.share'})
The dialog gets its size from FB.UIServer.Methods.stream.share.size
Which is equal to {height:380, width:575} if you take a look at it in a javascript console.

So these dimensions are there to be changed if you need to.

Note, I was using the ‘feed’ dialog which is not present in FB.UIServer.Methods so I defined it after my call to FB.init so it would be available when I opened by dialog…


FB.init({appId: '[my app id]', status: true, cookie: true, xfbml: true});
FB.UIServer.Methods["feed"] = {size:{width:500,height:240}};

To get mysql gem to work on OSX 10.6

Just a quick note. I lost an hour to fiddling about with this.

If you’re having trouble with the mysql gem version 2.8.1 on OSX 10.6 try uninstalling it and building it this way:


sudo gem uninstall mysql


export ARCHFLAGS="-arch i386 -arch x86_64" ; gem install --no-rdoc --no-ri mysql -- --with-mysql-dir=/usr/local --with-mysql-config=/usr/local/mysql/bin/mysql_config

The gem should build with no errors or warnings. The paths to mysql-dir and mysql-config are standard paths used by the mysql dmg, you might want to check your own paths first with:

which mysql_config

Sharing Wireless iMac connection to PS3

My girlfriend won a PS3 at work yesterday. So yeah, Christmas came early for me!  Before I started any gaming I wanted to see what the media centre capabilities were but I ran into some trouble with the wireless setup. Here’s what I did. This is not meant to be a beginners step by step guide but It will point you in the right direction if you run into this problem.

Continue reading

Moved to Slicehost

I completed my move from GoDaddy to Slicehost over the weekend. My move to a grown up host was long overdue. I went with a 256mb slice to start with and Ubuntu 8.04.  I have to say Slicehost are superb and I’d recommend them to anyone, my only problem, though it’s not their fault is that I do notice a small bit of latency when I’m issuing commands over ssh, but hey I’m almost on the other side of the world, what can you do?

I’m now running WordPress 2.7 served up with Nginx and PHP over fast-cgi. I don’t get much traffic but if I ever do I’ll be able to handle it.

That’s all for now. Enjoy the Holidays.

Problem installing Rubygems on Ubuntu

I was installing Rubygems 1.2.0 on Ubuntu 7.04 on Friday, something I’ve done many times but for the first time I saw this error when I ran sudo ruby setup.rb

./lib/rubygems/spec_fetcher.rb:1:in `require': no such file to load -- zlib (LoadError)
	from ./lib/rubygems/spec_fetcher.rb:1
	from ./lib/rubygems/source_index.rb:10:in `require'
	from ./lib/rubygems/source_index.rb:10
	from ./lib/rubygems.rb:767:in `require'
	from ./lib/rubygems.rb:767
	from setup.rb:22:in `require'
	from setup.rb:22

Having a look around the web yielded several approaches to solve the problem but no solution so I decided to build Zlib from source, then rebuild Ruby and then install Rubygems. That worked.
Continue reading

Mysql gem on OSX Leopard

Just a quick note on a problem I ran into this morning.

I needed the mysql gem so I ran gem install mysql only to find I got the following error:

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.

The solution was to use the following:
gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config

It should work as long as the path to mysql_config is correct, you may need to change the path for your own system. You can check the path to mysql_config with: which mysql_config

Disable active record in Rails 2.1.0

I've had a bit of trouble trying to disable active record in my rails app today.  I set the following in environment.rb as I had done before in rails 2.0.2:

RUBY:
  1. config.frameworks -= [ :active_record ]

However it resulted in the following error:

RUBY:
  1. vendor/rails/activesupport/lib/active_support/dependencies.rb:278:in `load_missing_constant': uninitialized constant ActiveRecord (NameError)

The problem is that [your app]/config/initializers/new_rails_defaults.rb should check to see if ActiveRecord is enabled before it references it. A patch for this has already been checked into the rails codebase but if you don't want to wait for the next release you can get the patch from the link below and apply it yourself:

http://github.com/rails/rails/tree/4b4aa8f6e08ba2aa2ddce56f1d5b631a78eeef6c/railties/configs/initializers/new_rails_defaults.rb

Note:
I made the mistake of applying this patch directly to rails/railties/configs/initializers/new_rails_defaults.rb as the patch does and wondered then why the fix didn't work. It would work for any new rails apps that you create but you'll need to apply it to config/initializers/new_rails_defaults.rb in your rails app in order for this to work.

Michael Fix – Message in a Bottle (cover)

I've finally got around to taking guitar lessons which I started about a month ago. The lessons have been giving me an even greater appreciation for finger-style playing. Actually if anyone is thinking about taking lessons I highly recommend my teacher, check out http://www.flyingfingers.ie for more information.

I stumbled across this great great YouTube find this morning and wanted to highlight it. I love The Police and 'Message in a Bottle' is one of my all-time favourite songs. This cover is just brilliant.

Internal Server Error on post.php after upgrading WordPress

I recently upgraded my copy of wordpress to 2.5.1. All apparently went smoothly until I tried to write a new post. When I pressed 'publish' the page would hang for a while and then return an Internal Server Error.

For those of you experiencing the same trouble. The problem was with the database. I uploaded my mysqldump of the wordpress db via phpMyAdmin on GoDaddy, I had enough grief as it was trying to get the script to go through properly, the problem was that it neglected to assign the AUTO_INCREMENT property to ID fields on all my wordpress tables. So effectively I could not create new rows.

Thanks to Ken for pointing me in the right direction.