Hello, I’m a web craftsman with a passion for the modern web. I build web applications and play with social services and communities.
Since Xcode 4.2 Apple doesn’t ship a normal GCC anymore, but instead packages LLVM. While it was possible to compile Ruby with LLVM before, the result was error prone. Not anymore! Since 1.9.3-p125 Ruby is fully compatible with LLVM and here is how you can install it without the need of any additional GCC installation.
- Install Xcode 4.3 or the new stand-alone command line tools
- Install rbenv and ruby-build
# install rbenv $ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv $ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile $ echo 'eval "$(rbenv init -)"' >> .bash_profile # You may be using Zsh or any other shell. # I presume you know how to adopt the previous two lines then. # install ruby-build $ mkdir -p ~/.rbenv/plugins $ git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build # reload bash (alternatively close and re-open Terminal) $ source ~/.bash_profile
- Compile Ruby 1.9.3-p125 and make default ruby
$ env CC=/usr/bin/gcc rbenv install 1.9.3-p125 $ rbenv global 1.9.3-p125 $ rbenv rehash
- Done. Check everything is ok now
$ ruby -v # => ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]
Sweet. Leave a note in the comments if this helped you. Happy coding!
There is still plenty of interest in my old article “Develop memcached web apps with XAMPP under Mac OS X” so I decided to write a little follow up.
XAMPP for OS X hasn’t seen any updates in quite a while so I decided to go with MAMP after upgrading to Mac OS X Lion (10.7.2 as of now). Quite ironic since I originally changed from MAMP to XAMPP because of the lack of updates from MAMP. However, both are quite similar when it comes to installing extensions from pecl or pear so you may have some luck applying the following steps to either dev environment.
Also while I am installing the mongo driver for php here, the very same steps should work for other pecl packages such as memcache, uploadprogress or xdebug. So let’s get started!
- Install XCode (I’m on 4.2 at the moment)
- Install MAMP (2.0.5)
$ brew install mongodb
- Start the MongoDB server
Now it’s time to install the mongo php extension:
- Download the matching version of the php source code from php.net (MAMP 2.0.5 comes with PHP 5.3.6)
- Create an include-folder in your MAMP php installation
$ mkdir /Applications/MAMP/bin/php/php5.3.6/include
- Extract the php source code into that new folder. The extracted folder is called php-5.3.6.
- Rename that folder to just php, then the php source code should be located here:
- Change into that directory and configure php:
$ cd /Applications/MAMP/bin/php/php5.3.6/include/php
- MAMP comes with a weird pear config file that causes issues, let’s remove it:
$ rm /Applications/MAMP/bin/php/php5.3.6/conf/pear.conf
- Now install the mongo driver with pecl:
$ cd /Applications/MAMP/bin/php/php5.3.6/bin
$ ./pecl install mongo
- Activate the extension in your php.ini:
And that’s all. From now on you only need the last two steps to install other extensions.
In the past months I have been confronted with a few web projects requiring scalable file storage solutions. One of them is my very own service comemories, which stores user-uploaded photos. Those photos are stored in original size as well as a few generated thumbnails.
To deal with file uploads, most developers seem to use Amazon S3 these days, so did I. Surely it’s a great service that pretty much just works, but with increasing traffic on comemories I started to feel a little uncomfortable about the way Amazon charges me. Basically they let a month pass and then sum up how much storage I use, how much traffic I used and how many API calls my app did.
So far so good, but what if my app sees some tremendous success suddenly and many more people upload photos than I anticipated? S3 would scale just fine and handle all the traffic with no issues at all… And by the end of the month I would get the big surprise in form of a credit card bill.
Of course it depends a lot on what you are trying to do, but if you are anything like me and you are running a web service more or less for fun and because you are learning about technology, you should really reconsider if S3 is the right choice.
Let’s have a look at their pricing for a little example application:
Image we run a web service with 10.000 users who uploaded 100 photo each at 5MB per photo. This would sum up at about 5TB of storage needed.
- Amazon charges $0.14 per GB for the first TB leading to $140
- then the other 4TB cost $0.125 per GB summing up at +$500
- every image has to be transferred in once: +$500
- and for simplicity let’s say every images is transferred out once: +$750
A total of $1890 for the month the images are uploaded. Now let’s imagine no more photos are uploaded from this point on but every photo is accessed once per month again. This means we would keep paying $1390 month to month.
Wow! 5TB is not even that much. You could buy three 2TB HDDs for 210€ altogether to get 6TB of storage and this would only be a one time cost instead of monthly charges. But ok, just buying plain HDDs is not really comparable to the service Amazon offers. But what about rented dedicated servers?
Hetzner Online offers the EQ9 for 99€ per month and the server has 4500GB storage installed. Coming to 0.022€ per GB. So I could just get two of them and have 9TB storage for less than 200€ per month. Now Amazon offers some redundancy. So let’s just get 4 of those servers and have everything stored twice. Voilà, redundant storage for under 400€ per month.
Let’s not forget that we actually have 4 powerful machines here with Core i7 and 12GB of RAM each! Those make some pretty good app servers too. If we ran this on Amazon EC2 instead, it would cost us another fortune.
Don’t get me wrong here. I know getting a bunch of dedicated servers is no cool and fancy cloud with unlimited automatic scaling capabilities and also requires quite a bit of operations know how and work, but for web applications of small to medium size with just 1-2 people working on them this may just be the better solution. Big enterprises on the other hand could see some benefits from outsourcing all storage worries to a over-priced 3rd party. But really, who can count themselves to those?
While developing scalable web applications you will come across memcached at some point. Memcached is a free & open source, high-performance, distributed memory object caching system.
XAMPP is great for development in a local environment but does not come with a php memcached extension preinstalled. Since there are 2 good memcached php extensions in the PECL repository (memcached and memcache) it could be as easy as installing them through XAMPPs PECL installer. Unfortunately XAMPP for Mac (1.7.3) is still compiled for 32bit and the PECL installer would create a 64bit snow leopard extension. So let’s do it manually by setting some 32bit flags…
Install memcache PHP extension (2.2.5) for XAMPP (1.7.3) under Mac OS X 10.6 Snow Leopard (10.6.2)
- make sure Apple Developer Tools (Xcode) are installed
- make sure XAMPP Developer Package is installed
$ cd /tmp
$ pecl download memcache
$ tar xzf memcache-2.2.5.tgz
$ cd memcache-2.2.5
- This line looks just a bit complicated because it tries to deal with architecture problems between XAMPP (compiled for 32bit) and Snow Leopard (compiles everything by default to 64bit)
$ MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Applications/XAMPP/xamppfiles/bin/php-config-5.3.1
$ sudo make install
- change XAMPPs php.ini to load the extension: (in [Dynamic Extensions])
Those steps enable you to use memcached in your PHP Code. But to actually test the application and caching in your local development environment you have to start the memcached daemon. Fortunately memcached got already installed by the Mac OS X Developer Tools (Xcode).
Just go ahead and start the memcached daemon:
$ memcached -m 8 -l 127.0.0.1 -p 11211 -d
-m 8 limits memcached to use a maximum of 8MB RAM to operate
-l 127.0.0.1 -p 11211 is the ip and port to listen on
-d tells it to start as a daemon
(instead of -l and -p you can also use -s to use an unix domain socket)
If you develop some kind of multi-language software you will probably make use of something like setlocale in PHP. Now to get your l10n/i18n solution to work on a Debian server you have to install the required locale.
locale -a will show you which locale are installed on your system.
This will output something like this:
To add another locale now, edit /etc/locale.gen and uncomment the locale you need.
I.e. de_DE.utf8 for a German Locale uncomment.
After that run locale-gen as root to activate the new locale system-wide.
Don’t forget to restart your webserver daemon after the change if you want your web application to make use of the freshly activated locale.