Setting up a clean dev environment: perl, MySQL, and Dancer

Big accomplishments today. It took a few hours, but I finally got my ODMP (OSX, Dancer, MySQL, Perl) environment setup. Learned a lot through the process! Here are my notes:

nn

Install perl via perlbrew

nn

OSX is shipped with perl pre-installed. The general rule of thumb with system-supplied tools is not to use them for development work. In your experimentation, you might end up deleting a critical library or corrupting some configuration file that renders this program useless. This can be a pain because certain other programs on your computer may be relying on this program in order to run.

nn

Perlbrew to the rescue! Perlbrew is a convenient way to install a new, clean version of perl that is totally segregated from your system perl and its libraries. Another awesome feature is that you can install modules via CPAN or CPANMinus without having to sudo or run as root.

nn

Install perlbrew by executing the following command:

nn

<code>$ curl -L http://install.perlbrew.pl | bash</code>n

nn

Once Perlbrew is installed, execute two more commands:

nn

<code>$ perlbrew install perl-5.16.0n$ perlbrew switch perl-5.16.0</code>n

nn

These commands will download, compile, and install perl 5.16.0 from source, then configure your environment to refer to this instance of perl and its libraries.

nn

The program will then ask you to add the following line to your ~/.bash_profile:

nn

$ source ~/perl5/perlbrew/etc/bashrcn

nn

Install MySQL

nn

In order to connect to a MySQL database, you need to download and install MySQL. It seems like a pain, but just do it; the database libraries in perl need to be built with some libraries and header files from a local MySQL.

nn

Download and install the binary instance of MySQL from the MySQL website. On OSX, this is a pretty straightforward process. MySQL provides you with precompiled binaries and a convenient installer program.

nn

Fix a Missing Library Reference in MySQL for OSX

nn

There is a bug in the current version of MySQL for OSX. I read that it will be fixed in the new version. Thanks to Mark Phillips at his website for posting the fix.

nn

Execute the following command. Note the directory paths and filenames, as they may be different based on the version of MySQL that you download. These commands are correct as of version 5.6.17

nn

$ sudo install_name_tool -id /usr/local/mysql-5.6.17-osx10.7-x86_64/lib/libmysqlclient.18.dylib /usr/local/mysql-5.6.17-osx10.7-x86_64/lib/libmysqlclient.18.dylibn

nn

Install cpanminus

nn

I wrote about this yesterday, but here again are the commands.

nn

$ cpanncpan[1]> install App::cpanminusn

nn

Install DBD::mysql

nn

This is the connector between perl and the MySQL database. Be sure to install it before Dancer’s database plugin.

nn

$ cpanm DBD::mysqln

nn

Install Dancer

nn

I also wrote about installing Dancer recently. You can follow those instructions, or you can install via cpanminus.

nn

$ cpanm Dancern

nn

Install Dancer::Plugin::Database

nn

Once Dancer is installed, go and install its database plugin. You can read about it on Metacpan. Once again, cpanm makes the installation simple.

nn

$ cpanm Dancer::Plugin::Databasen

nn

Create your app’s skeleton

nn

$ dancer -a MyWeb::Appn

nn

Start your Dancer web app

nn

$ cd MyWeb-Appn$ ./bin/appl.pln

Leave a Reply

Your email address will not be published. Required fields are marked *