How to set up a Magento Development Environment with MacPorts

·

·

MacPorts LogoThis how-to gives a rough overview on how to set up Magento locally for development or testing purposes under Mac OS X. I have to admit that it was not as straight forward as the following description may seem, but I do not mention all the stumble blocks I encountered, because from my own experience I know that each setup slightly differs. The Apache error log and the command line output should give you enough information to figure out what needs to be done.

Installing Packages via MacPorts

The MacPorts Project is an open-source community initiative to design an easy-to-use system for compiling, installing, and upgrading either command-line, X11 or Aqua based open-source software on the Mac OS X operating system. Based on How to install Apache, PHP, MySQL with MacPort on Mac OS X I did the following in order to install the required packages:

  1. sudo port selfupdate
  2. sudo port install gawk nawk php5 php5-mysql php5-mcrypt php5-curl php5-iconv php5-gd +apache2 +mysql5-server

Configuring PHP and MySQL

In the next step the MySQL database is set up

  • sudo /opt/local/lib/mysql5/bin/mysql_install_db
To configure Apache and MySQL to start automatically do the following
  1. sudo launchctl load -w /Library/LaunchDaemons/org.macports.apache2.plist
  2. sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
Now you need to configure Apache to load PHP files by opening /opt/local/apache2/conf/httpd.conf and adding the following 2 lines of configuration
  • LoadModule php5_module modules/libphp5.so
  • AddType application/x-httpd-php .php
To start Apache and MySQL manually execute the following commands
  • sudo /opt/local/etc/LaunchDaemons/org.macports.apache2/apache2.wrapper start
  • sudo /opt/local/etc/LaunchDaemons/org.macports.mysql5/mysql5.wrapper start

When I wanted to connect to the MySQL server with phpMyAdmin or the MySQL Administrator I always got the error

Can’t connect to local MySQL server through socket ‹/tmp/mysql.sock›

Which I was able to fix by using the IP address 127.0.0.1 in the phpMyAdmin configuration and MySQL Administrator connection settings respectively.

If you encounter other problems, you will find a couple of common errors in the how-to mentioned above.

Installing Magento

Now download the desired Magento version. A handy way of doing this is by cloning Lee Saferite’s Magento Mirrow on GitHub which would require you to have git installed. This can be done with a simple sudo port install git-core command. For Magento to work properly set file permissions as follows:

  1. chmod o+w var var/.htaccess app/etc
  2. chmod -R o+w media

Run the web-based Magento installer

  1. Go to http://localhost/your-install-location/index.php/install/