Like many of Apple fanboys out there even I decided to upgrade Mac OS X Snow Leopard (10.6) to Mac OS X Lion (10.7) as soon as it was made available on App Store. Upgrading from App Store was pretty smooth and was surprised it did not break any apps (May be that’s because it’s just an incremental upgrade with some fancy features) except my Django projects failing to validate because of the default python version change (from 2.6.x to 2.7.1) and can be easily fixed. However I decided to go for fresh install of OS X Lion to test how fresh install (wipe out disk after backup and install ) works with OS X Lion.
Once done with fresh installation of Mac OS X Lion, immediate task was setting up my development environment which includes MySQL server, phpMyAdmin and Django.
Steps I followed to get Django development environment back are as below
- Install Xcode via Mac OS X App Store ( Might be required when you compile and install from source)
- Install MySQL Server
- Install phpMyAdmin
- By default jpeg, freetype, littlecms image library support is missing, you need to install at least jpeg support so ImageField in your django project supports jpeg formats.
- Install JPEG libraries
- Download JPEG library source curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
- Extract tar -xvzf jpegsrc.v8c.tar.gz
- Switch to jpeg directory cd jpeg-8c
- Run ./confgure
- Run make
- Run sudo make install
- Install Freetype libraries
- Download Freetype library source curl -O http://ftp.igh.cnrs.fr/pub/nongnu/freetype/freetype-2.4.5.tar.gz
- Extract tar -xvzf freetype-2.4.5.tar.gz
- Switch to freetype directory cd freetype-2.4.5
- Run ./configure
- Run make
- Run sudo make install
- Install Django using sudo easy_install django
- Install Python Image Library (PIL) using sudo easy_install PIL
- Install mysql-python driver using sudo easy_install MySQL-python (Make sure you got mysql in your PATH, otherwise this will fail with mysql_config not found error)
That’s all you need to go ahead and start creating Django projects. However I prefer using virtualenv for all my Python projects. If you take this route, you can use pip install <package_name> to install necessary packages for example pip install django, pip install MySQL-python, pip install PIL to install Django, MySQL Python driver and Python Image Library.
Update 1 (25/07/2011): If you get error “django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: dlopen(/Users/xxx/xxx/pyprojects/xxx/lib/python2.7/site-packages/_mysql.so, 2): Library not loaded: libmysqlclient.18.dylib
Referenced from: /Users/xxx/xxx/pyprojects/xxx/lib/python2.7/site-packages/_mysql.so
Reason: image not found”, when you validate your project or try to use MySQL-python,
Type export DYLD_LIBRARY_PATH=”$DYLD_LIBRARY_PATH:/usr/local/mysql/lib/” in your terminal and see if problem persists. You can add it to your .profile file to make this persistent so you don’t need to run it every time.
This article is part of Django Installation on Mac OS X Lion
Mac OS X by default ships with Apache web server which we will use to install (configure) phpMyAdmin to manage MySQL server installed previously on Mac OS X 10.7 (aka Lion). At the end of this step-by-step tutorial, you should be able to access phpMyAdmin by opening http://localhost/phpMyAdmin in your preferred browser.
In this tutorial we will be using Terminal to move files around and edit/create files using command line.
- Start Apache if it’s not already running (You can check by running command “ps -ef | grep httpd” in terminal)
- Open System Preferences and Click Sharing
Start Apache Mac OS X
- Check Web Sharing Checkbox which should start web server (Apache) on your Mac
- Open http://localhost in browser and you should see default page (on mine it just says “It Works” in H1 Tag)
Mac OS X Apache Homepage
- By default, PHP module is not activated. Uncomment the line ”LoadModule php5_module libexec/apache2/libphp5.so” in file “/private/etc/apache2/httpd.conf” to enable PHP on Mac OS X Apache web server. Default PHP version is PHP 5.3 (PHP 5.3.6 to be precise)
- Download phpMyAdmin (Latest version at the time of writing this is 22.214.171.124) from phpMyAdmin Site. Download page has quite a few options in terms of language and compresssion formats, so download the most relevant language pack and compression format you are comfortable with. (I downloaded phpMyAdmin-126.96.36.199-english.zip, please note your version may be different )
- Open Terminal and Extract downloaded package to /usr/local/ by running command “sudo unzip phpMyAdmin-188.8.131.52-english.zip -d /usr/local/“
- Rename phpMyAdmin-184.108.40.206-english to phpMyAdmin by using command “sudo mv /usr/local/phpMyAdmin-220.127.116.11-english /usr/local/phpMyAdmin” in Terminal
- Switch to phpMyAdmin directory using “cd /usr/local/phpMyAdmin” to create phpMyAdmin config file
- By default config.inc.php file does not exist but phpMyAdmin ships with sample config which we can use. Copy config.sample.inc.php to config.inc.php using “sudo cp config.sample.inc.php config.inc.php“
- Edit config.inc.php using your favorite editor (I prefer vi) and change $cfg['Servers'][$i]['host'] = ‘localhost’; to $cfg['Servers'][$i]['host'] = ’127.0.0.1′;
*Well it sounds stupid because localhost and 127.0.0.1 are same in networking world but phpMyAdmin won’t let you (At least me) log in without this change and keeps throwing error “#2002 Cannot log in to the MySQL server”
**If your MySQL is running on a different host/port, you can change them in this file
***You can also use setup wizard offered by phpMyAdmin to configure phpMyAdmin further
****You can also add random blowfish secret to config.inc.php to encrypt your session cookies.
- Configure Apache to enable /phpMyAdmin
- Create phpMyAdmin apache config file with below text in bold in /etc/apach2/other/ directory using your favorite editor “sudo vi /etc/apache2/other/phpMyAdmin.conf“Alias /phpMyAdmin /usr/local/phpMyAdmin
Allow from all
- Restart Apache by typing command sudo apachectl restart in terminal
- Open http://localhost/phpMyAdmin in your browser and you should see phpMyAdmin Login Page
Mac OS X phpMyAdmin Login Screen
*Note Default phpMyAdmin does not allow you to login with empty passwords, you can change this behaviour but it is highly recommended to have password for mysql server accounts.
This article is part of Django Installation on Mac OS X Lion
At the time of writing this post, MySQL Server on MySQL site doesn’t have installer package for OS X 10.7 (aka Lion) but 10.6 Package works just fine for 10.7 as well. This may change soon and we may see package for OS X 10.7 as well or may be rename current package to 10.6 & above.
Installing MySQL community server:
- Download the latest 64-Bit DMG Archive (Apple Disk Image) from MySQL Site (http://dev.mysql.com/downloads/mysql/). Current latest version is 5.5.14 which I’ll be using to install on my machine.
- Mount the Disk Image (I mean open/double-click the DMG file) and install MySQL server by double-clicking the PKG file (in my case mysql-5.5.14-osx10.6-x86_64.pkg) and follow onscreen instructions. ( It will ask for Master password, as it installs MySQL server in /usr/local )
- Add /usr/local/mysql/bin to your path by editing .profile file. (Optionally you can create alias to mysql and mysqladmin as mentioned in README File)
- You can start MySQL server by running “/usr/local/mysql/bin/mysqld_safe &” from terminal but Disk image you downloaded also consists of Startup Package & Preferences Pane which allows you to start/stop MySQL server from System Preferences and even Automatically Start MySQL Server at Startup.
*Please note /usr/local/mysql is only symlink to /usr/local/mysql-5.5.14-osx10.6-x86_64 which means when you upgrade to new version symlink will be changed to point to new version but won’t be deleting the older version. However you need to copy your data directory to new location to make sure your existing databases are intact post upgrade.
Installing MySQL Startup Scripts & Preferences Pane (OPTIONAL)
- Double Click MySQLStartupItem.pkg and Follow on screen instructions (You will be asked for Master Password)
- Double Click MySQL.prefPane which will add MySQL to OS X System Preferences and it should like something like below
MySQL Mac OS X Lion Preferences
- Check Automatically Start MySQL Server on Startup to start MySQL server at boot time.
In next section we will discuss installing phpMyAdmin which will provide us web interface to perform basic MySQL administration tasks on Mac OS X Lion.
I’ve started working on Python & Django sometime around March 2008 and from then on started following Django IRC and Django blogs of which b-list by James Bennett is most useful/helpful till date. Also I use django-registration django resuable app by James Bennett in all of my projects (even today) and hence I decided to order the book Practical Django Projects by James Bennett in July and I was expecting to learn something new which is not in my arsenal.
If you have ever used/worked on CMS/Blogging apps, you might have noticed created and last updated timestamp’s for each content item (article/entry) and as you would expect Django also provide two options for DateTimeField which will enable you to create timestamps automatically. DateTimeField with option auto_now_add ( models.DateTimeField(auto_now_add=True) ) can be used for created timestamp while DateTimeField with option auto_now ( models.DateTimeField(auto_now=True) ) can be used for last updated timestamp. Only drawback of auto_now and auto_now_add is they disable editing timestamps from admin.
Well if you have decided to install Django, by now you must be knowing Django is a Python based web framework and in today’s post I’ll run through Django installation process on Windows including dependencies (like installation of Python, database, database adapters and other important libraries that Django depends on). If you already have Python installed, then skip Python installation section.
Installing Django/Python/Python modules is same in all versions of windows and hence below steps are valid for Windows XP and Windows Vista. Those who are using Windows Vista, just make sure you run all installations as Administrator ( Right click setup file and run as administrator )
Let’s begin by installing Python (If you already have a working Python installation, skip this section)
Reading about Django related stuff on WordPress (PHP) powered blog might be disrespectful to simple yet powerful Python based framework like Django, which let’s you create a decent blog within couple of hours. But I don’t think this site will end up as just an another blog and if at all it end up as a blog due to laziness then I’ll sure replace this one with Django based blog which has all important wordpress features I’m looking for like comment moderation (IP and keyword filtering), SEO, WYSIWYG editor, Akismet integration, Tagging to name a few which are often ignored by many developers out there.
I’m pretty sure all those features are on mind of some of the programmers and we will see an blog app soon but if they delay longer then I may end up writing one to move this from wordpress to Django. Anyways we will have a migration guide from WordPress to Django as another post in form of my migration experiences when when I migrate. Till such time, I’ll use Django badge I wish this site were powered by Django on footer.