Skip to main content

Preparing your drupal development environment with Mac OS X Lion.

I just got a MacbookPro and the first thing i wanted to do was get a drupal developer environment on the machine, I ideally would have like to mirror what i had on my windows laptop - which was Apache/PHP/MySQL/Eclipse.

I googled and found OSX Lion comes with Apache and PHP built in, I must add here that i didn't know there was a MAMP server similar to the WAMP server i had installed on my windows machine, but using the already installed Apache and PHP was just as easy.

To enable Apache just do the following:

1. Go to System Preferences 
2. Click sharing
3. Click Web Sharing service
4. Note the location of the Website Folder on my macbook pro it was Macintosh HD->Library->WebServer->Documents, i would think this is the same for you as well.

We can change the document root from httpd.conf if required, i left it as is.

A quick run to safari/firefox and go to http://localhost to make sure Apache is working - and it does tell you emphatically 'It Works!', note PHP is not yet enabled and we will have to enable that form the apache configuration file.

Enable PHP (you may have to use root privs or sudo to do this)

1. open terminal window
2. sudo cd /private/etc/apache2
3. sudo vi httpd.conf
4. in vi search for string php5_module by typing /php5_module
5. switch to edit/insert mode by typing 'i'
6. remove the '#' and save the file by typing ':wq'
7. disable websharing (System Pref->sharing->web sharing) and re-enable.

Create a php file with phpinfo() and checking on the browser confirms php is working with Apache.

MySQL is not preinstalled on the mac osx so this requires to be downloaded from www.mysql.com - i installed the mysql 5.5.15. Downloading the "dmg" file and clicking when complete opens the disk image revealing  two .pkg files. the first mysql-5.5.15-osx10.6-x86.pkg will guide you through the installation, on completion you need to click the MySQLStartupitem.pkg to make sure mysql comes up when your macbook is restarted. I also suggest installing the MySQL pref pane, to allow you to manage mysql better.

There i just one more thing you will have to do to ensure mysql works with PHP by pointing php to the right mysq.sock file, i got this done by looking at the place MySQL was installed and did the following

sudo mkdir /var/mysql
sudo ln -s <current localtion of mysql.sock> /var/mysql/mysql.sock

Install MySQL GUI tools to administer mysql and MySQL query browser, this will be required for drupal development.

After installation restart your macbook pro and confirm mysql is up and working by using the mysql query browser, create a database and you are now ready to install drupal.

Download the latest drupal 7.7 and place in the documents folder and follow drupal installation steps as normal, note you will require to change permissions on the sites/all folder to change the settings.php and also install files folder. I skipped the step and changed the owner of the Documents folder to the one i will be using most.

sudo chown 'myuser' /Library/WebServer/Documents

I have installed eclipse pdt from 'pdt-1.0.3.R20080603_debugger-5.2.14.v20080602-all-in-one-macosx-carbon.tar' and placed the eclipse folder in applications.

The next step is of course editing preferences to make sure drupal files like .install, .module are added to php content type and tabs are converted to spaces as per drupal coding standards.

the PDT has zend debugger preconfigured which is a great thing for serious development. Hope you find this helpful, next steps is configuring drush and you are all through!

Comments

Popular posts from this blog

Create a drupal development environment using docker.

Currently at work i am using docker to streamline and speedup of development and deployment to testing and production, I am using symfony currently and our app is dockerised, i wanted to do the same for drupal based apps.

I searched for a official drupal docker repo and i did find this. https://www.drupal.org/node/2538074

Unfortunately there was very terse explanation but pretty much worked, i found a few hiccups along the way so wanted to share what i did.

Pre-requisite:
Install docker for your environment. Lots of details are available at https://docs.docker.com/ explaing docker and installing docker for your environment.

The docker repo holds the drupal container at https://hub.docker.com/_/drupal/, following the instructions this is how to create the drupal container:

In order to use my code base we need to mount the volume with the -v directive as below, we do this in one command:

docker run -v /$HOME/work/drupal8:/var/www/html -p 8080:80 --name mydrupal -d drupal

this will create…

Use feeds module to import XML data in Drupal 7

Recently i had to setup a xml import process to import data from an external supplier on a regular basis, the filename and format was not changing and i could choose where to store the file. Following is how i set it up.

First we need to download the following modules

feeds
feeds admin ui
feeds_xpathparser
ctools
job_scheduler

enable the above modules.

We will need a sample XML so this will be the one we will use for this demonstration:

<?xml version="1.0" encoding="utf-8" ?>
<!-- Sample for demonstration of processing XML feeds with feeds module -->
<Orders>
<Order>
<CustomerID>10</CustomerID>
<Order_Number>1</Order_Number>
<Order_Total>100</Order_Total>
<Currency>£</Currency>
</Order>
<Order>
<CustomerID>11</CustomerID>
<Order_Number>2</Order_Number>
<Order_Total>40</Order_Total>
<Currency>$</Currency>
</Order>
</Orders>


How do you expose your legacy database tables to views in drupal 6 Part 1

This is a 2 part post, that shows how I exposed a legacy table to views in drupal and used the incredible power of views to create many combinations static and conditional views. This was very helpful for my client.

I had a requirement that warranted exposing existing database table to views, so that views can contain data from this table.  To enable this to happen, the following steps need to be taken.
In a custom module you need to first define the views_api hook as following:
function candidate_views_api(){ $view = array(); $view = array('api' => 2, 'path' => drupal_get_path('module','candidate'). '/views'); return$view; }
candidate module was a custom module which I already had, so it made sense to add this hook here. 
The important bit here is telling the drupal sub-system where the views file will reside. 
Then create a file with your <modulename>.views.inc in my case it was candidate.views.inc, this file should have two hooks, one …