Mac as a Development platform

I sometimes feel as if I spend half my time making fixes caused by Apple upgrades.

This morning I found my previously hand-crafted php.ini had been removed.

So, each time Apple does an upgrade I have to go back in and update php.ini with various customizations (like max post size, etc).

This also happened to Apache. Apple did an upgrade and I lost my virtualhosts.

And other things change too – like I now have to use mysql.server start rather than using mysqld. I can understand that things need to change but why not provide a graphic tool and just change things under the hood.

Now I try restarting MySQL and I get:

So clearly another update has happened that I’ll need to fix.

My experience on Linux has always been much smoother. I’m starting to wonder if I should try using it again as a development platform.

Linode Rails Server: Debian or Ubuntu

Debian is the oldest of the Linux distributions and has a venerable history. 

But what attracts me to Ubuntu are the LTS distributions (or Long Term Support). You get a massive 5 years of support for that distribution. So, Ubuntu 12.04 LTS will be backed till 2017! Debian will support the previous release for 1 year.

Also, Ubuntu has the backing of a commercial organisation.

See also:

http://askubuntu.com/questions/15314/debian-stable-vs-ubuntu-lts-for-server

and

http://serverfault.com/questions/389199/is-it-debian-really-more-stable-for-servers-than-ubuntu-lts

and a specific guide to setting up a Rails server on Ubuntu 12.04 here:

http://blog.lunarlogicpolska.com/2013/setup-fresh-ubuntu-server-for-ruby-on-rails/

For the process of provisioning your server, see:

https://library.linode.com/getting-started

and, for Phusion Passenger, this is a useful read:

https://developer.apple.com/library/mac/#featuredarticles/PhusionRails/_index.html

If you’re on a Mac then use PassengerPane for local Rails deployments (helps avoid cluttered /etc/hosts): 

http://www.fngtps.com/passenger-preference-pane

Hint – just use:

$ gem install passenger

$ passenger-install-apache2-module

Linode Rails Server: Debian or Ubuntu

Debian is the oldest of the Linux distributions and has a venerable history. 

But what attracts me to Ubuntu are the LTS distributions (or Long Term Support). You get a massive 5 years of support for that distribution. So, Ubuntu 12.04 LTS will be backed till 2017! Debian will support the previous release for 1 year.

Also, Ubuntu has the backing of a commercial organisation.

See also:

http://askubuntu.com/questions/15314/debian-stable-vs-ubuntu-lts-for-server

and

http://serverfault.com/questions/389199/is-it-debian-really-more-stable-for-servers-than-ubuntu-lts

and a specific guide to setting up a Rails server on Ubuntu 12.04 here:

http://blog.lunarlogicpolska.com/2013/setup-fresh-ubuntu-server-for-ruby-on-rails/

For the process of provisioning your server, see:

https://library.linode.com/getting-started

and a useful read on Phusion Passenger is:

https://developer.apple.com/library/mac/#featuredarticles/PhusionRails/_index.html

although it’s Apache-specific (e.g. it doesn’t mention Nginx).

If you’re on a Mac then use PassengerPane for local Rails deployments (helps avoid cluttered /etc/hosts): 

http://www.fngtps.com/passenger-preference-pane

Hint – just use:

$ gem install passenger

$ passenger-install-apache2-module

-bash: /bin/grep: Argument list too long

$ grep ‘some phrase’ * | wc

Solutions:

1. The general solution is to use ‘xargs’.

2. If you’re a Linux masochist you could also try rebuild the kernel with a change to:

include/linux/binfmts.h

:

#define MAX_ARG_PAGES 32

Perhaps make it 64? Or more?

 

3. Use find

find . -type f -exec grep ‘some phrase’ {} + | wc

E.g.

Using -exec efficiently:

The -exec option to find is great, but since it runs the command listed for every found file, it isn’t very efficient.  On a large system this makes a difference!  One solution is to combine find with xargs as discussed above:

find whatever… | xargs command

However this approach has two limitations.  Firstly not all commands accept the list of files at the end of the command.  A good example is cp:

find . -name \*.txt | xargs cp /tmp  # This won’t work!

(Note the Gnu version of cp has a non-POSIX option -t for this.)

Secondly filenames may contain spaces or newlines, which would confuse the command used with xargs.  (Again Gnu tools have options for that, find … -print0 |xargs -0 ….)

There are POSIX (but non-obvious) solutions to both problems.  An alternate form of -exec ends with a plus-sign, not a semi-colon.  This form collects the filenames into groups or sets, and runs the command once per set.  (This is exactly what xargs does, to prevent argument lists from becoming too long for the system to handle.)  In this form the {} argument expands to the set of filenames.  For example:

find / -name core -exec /bin/rm -f ‘{}’ +

For more info take a look here:

http://find.unixpin.com/ldocs/FindCmd.htm

Installing Ruby 2.0 on Dreamhost

Dreamhost run Ruby 1.8.7 which is over 3 years old. Criminal! 

Here’s what I had to do to upgrade to Ruby 2.0.

First of all, Ruby 2.0 is production ready. So, no need to worry about whether to go for 1.9.3. 

1. login as a sudo user (create one via the VPS > Admin Users section if you don’t have one)

i.e. login with your normal web user shell account and type sudo your_sudo_user 

2. get the latest version of rvm 

Note that this will not work as Dreamhost has a sudo user which cannot access files of the user that owns the files that sit in your webserver directory: 

rvm get stable 

So, use: 

\curl -L http://get.rvm.io | bash -s stable 

and then

source  

/home/your_sudo_user/.rvm/scripts/rvm 

3. run 

rvm requirements ruby-2.0.0 

You’re now done as your sudo user. Type exit to logout back into your original shell. 

4. you can’t write to rvm under your normal user so set rvm autolibs to read: 

rvm autolibs read 

and 

rvm install 2.0 

rvm use 2.0

5. Check stuff is set up correctly:

gem env gemhome

find $MY_RUBY_HOME -name psych.so

and you’re done. 

ruby -v
ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux] 

These help:

http://cheat.errtheblog.com/s/rvm

 

.bash_profile vs .bashrc

The difference between .bash_profile and .bashrc?

It’s always slightly confusing to remember how these work on Linux, Unix and Mac OS X.¬†According to the¬†bash man page,¬†.bash_profile gets run for every login shell (i.e. when you login) – put lengthy, one-off stuff there like the daily news

.bashrc gets run for every non-login shell (e.g. when you open up another terminal in your window system)

Unfortunately Mac OS X does things slightly differently – .bash_profile gets called for each new instance of a Terminal!

More:

http://www.joshstaiger.org/archives/2005/07/bash_profile_vs.html