Fixing fatal error: ‘openssl/aes.h’ file not found on OS X

OS X recently started using their own library instead of OpenSSL. So new installations for anything that depends on OpenSSL might fail. If you already have OpenSSL installed on your system, for example using Homebrew, you just need to point to the library while compiling your program.

For example, if you’re trying to install the popular cryptography package from PyPI, you can do these:

The above mentioned package is a common dependency of many other packages, for example Scrapy. So if you encounter an issue like this, try installing that single dependency first and then the dependent package. In this case, first use the above command to install the cryptography package and later install Scrapy.

Python: Sending Growl Notifications

Growl is an extremely popular notification system for OS X. The application allows developers to display beautiful notification messages with ease. If you’re developing an application in Python and would like to integrate with Growl, this blog post is for you.

Introducing GNTP

Let me quote from the official docs here – http://www.growlforwindows.com/gfw/help/gntp.aspx#intro:

The Growl Network Transport Protocol, or GNTP, is a protocol to allow two-way communication between applications and centralized notification systems such as Growl for Mac OS X and to allow two-way communication between two machines running centralized notification systems for notification forwarding purposes.

In short, GNTP allows two way communication between your application and Growl. Even shorter – you can use GNTP to publish notifications using Growl.

GNTP Binding for Python

We have an excellent library for interacting with GNTP. The project is hosted on Github – https://github.com/kfdm/gntp/ and the docs are available here – http://pythonhosted.org/gntp/

So how to use this library? First, install the library using pip –

To see if the installation was ok, we can test by running the module directly –

Sending Notifications

Sending a quick notification from the Python interactive prompt:

Simple, right?

You can find advanced examples on the github readme and the docs (links above). Have fun with Python and Growl!

Mac OSX, nginx and php-cgi: doing it the quick and dirty way!

I usually use Apache and it’s PHP5 module for my day to day php development. However, here came a time, when I needed to work on a project that involved using nginx. Installing nginx was easy with homebrew:

However, the recommended way to use php with nginx is using php-fpm. Since I use the apache module most of the time and building php with fpm builds it “–without-apache”, I didn’t want to go for anything complex for just one project at hand. I knew I could use the native “php-cgi” module, so I just googled, found few tips and set it up.

This is my nginx configuration:

Basically, all I did was change the root element to point to my current “~/Sites” directory which I use as the htdocs for apache. And I’m using unix sockets for better performance. Please read the nginx docs if you don’t understand any of the directives but I’m pretty confident that all of them are more or less self explanatory.

Now, we bind php-cgi to the socket mentioned in our nginx conf file. That’s quite straightforward:

Once we have updated the nginx configuration and started the php-cgi process, we should restart nginx:

This should restart nginx and all files with the “.php” extension will be parsed by php.

If you get “no input file specified”, check your nginx configuration and make sure that the paths are all correct. Specially this one:

Also check that if the root element is defined in appropriate scope for the block to have access to. If you still run along some issues, do a quick google or ask in stackoverflow. And feel free to experiment with different nginx features, specially url rewrites 🙂

Debugging with XDebug and PhpStorm on MacOS X

In an earlier post I demonstrated how to install PHP5.4 using brew. Today, I required xdebug for debugging purposes and found it quite easy to install via homebrew.

Install XDebug for PHP
It’s as simple as issuing the command:

Enabling XDebug
I had to add the extension to my php.ini file:

Follow the output of the brew info output of the package you installed (either php53 or php54):

To enable remote debugging, I also added these lines:

Debugging Web Applications
In the run configuration, add “Web Application” type. Configure the server and path as usual. When setup, you shall notice the debug button is active. Setup some break points and hit the debug button.

You can also use the “Listen PHP Debug Connection” option along with some xdebug bookmarklet for quick debugging.

Debugging Command Line Scripts
To debug command line scripts, first issue this command on terminal:

PS: I added the line to my ~/.bash_profile so that I don’t have to type it every time I login to bash shell.

Turn on incoming connections by clicking the “Start Listen PHP Debug Connection” button. Set some break points and then run the script from command line.

Setting up Python, MySQL Module and Django on Mac OS X Lion

I setup Python and Django using homebrew the easy way. I am going to detail the process now.

Install Python

The command should first install any dependencies for Python and then install the latest version from source code.

Adding Python to PATH

We need to edit our ~/.bash_profile to add “/usr/local/share/python” to the path variable. I added the following line to my bash profile:

I reloaded the profile by issuing:

This makes the python tools and toys accessible from my terminal.

Install MySQL Module

It’s recommended that you already have “mysql” installed from brew to build the mysql module. I already had it installed so it was a painless installation for me. I just issued the command:

Install Django
I am going to keep using the PIP awesomeness! Let’s hit:

It will install django with any dependencies. You can now invoke the “django-admin.py” command from your terminal. However, I prefer the command be “django-admin”, instead of “django-admin.py”. So I created the following alias in my ~/.bash_profile:

Isn’t it simple? 😀

Mac OS X: Using Sublime Text 2 from Command Line

Sublime Text 2 is an awesome text editor available free from – http://www.sublimetext.com/2 . I have been using the editor for almost every text editing purposes (when I am not using an IDE).

(1) First create a symlink to the original sublime text 2 executable:

Here, I already had the directory ~/bin created. Please create it yourself. Or you might want to create the symlink in /usr/local/bin or /usr/bin.

(2) To use it as the Unix editor, set this in your ~/.bash_profile

Mac OS X Lion: Homebrew, PHP54, MySQL and PEAR

In one of my old posts, I noted short documentation on how to get started with the AMP stack on Mac OS X Lion. In that setup, I was using the default PHP and downloaded MySQL from the mysql website. In this post, I am going to describe how I used homebrew to setup my AMP environment with ease!

The Homebrew Magic
Homebrew is a cool tool for Mac OS users. Written in Ruby, this beautiful tool works as a package manager for Mac OS. Unlike Mac Ports or Fink, homebrew takes less space, uses the default os x tools to compile everything to a custom location. This makes life suck less and clutter free!

To install PHP 5.4 branch using homebrew, just issue this command:

PS: If you want to customize the installation (like installing the mysql module by default) add necessary configuration options. Using the “bash-completion” formula from brew, you can hit tabs to see available installation options.

To view information on your PHP 5.4 installation via brew, type in:

Seperate MySQL Installation: Where is the ctl?
I have installed MySQL separately. I added the mysql and mysqldmin to my bash_profile like this:

And to start/stop/restart mysql server, I added:

That allows me to do:

Using PEAR
Homebrew installs all the PEAR packages to “/usr/local/Cellar/php54/5.4.3/lib/php”. So, I added it to my php include_path.

For PEAR to work correctly, we need sudo. If there are tools involved in the pear setup which can be run from command line (eg. phpunit), the binary files are stored in: “/usr/local/Cellar/php54/5.4.3/bin”.

I added the above path to my .bash_profile for convenience 🙂