Browsing articles from "June, 2010"

Installing MacPorts

Jun 28, 2010   //   by the guru   //   Mac  //  5 Comments

MacPorts is a community initiative developed to make it easy for people like me to compile, install and upgrade software through the command-line.

Before installing it you will need to meet the following requirements:

  1. Apple’s Xcode Developer Tools (version 3.2.1 or later for Snow Leopard, 3.1.4 or later for Leopard, or 2.5 for Tiger). This software can be found at the Apple Developer Connection or on your Mac OS X installation.
  2. The X11 windowing environment. The “X11 User” package is an optional installation on your system disc for Tiger, enabled through the “Customize” button of the installer, whereas it is included by default on Leopard and Snow Leopard.

Onto the Good Stuff

Now we have got through the boring stuff we can go on and install MacPorts.

All you need to do is go to the MacPorts download page and download the dmg version for your Mac. Shimples!

Once you have installed MacPorts go to your terminal and enter the following to make sure you have the latest and most up-to-date version:

sudo port -v selfupdate

Problems?

If you find you are having problems or had problems installing you may need to uninstall MacPorts first. If you need to do so, then you need to uninstall MacPorts through terminal then delete all the prefixed files:

sudo port -f uninstall installed
sudo rm -rf \
    /opt/local \
    /Applications/DarwinPorts \
    /Applications/MacPorts \
    /Library/LaunchDaemons/org.macports.* \
    /Library/Receipts/DarwinPorts*.pkg \
    /Library/Receipts/MacPorts*.pkg \
    /Library/StartupItems/DarwinPortsStartup \
    /Library/Tcl/darwinports1.0 \
    /Library/Tcl/macports1.0 \
    ~/.macports

Once you have done this you can follow the installation again. Any problems or suggestions just drop me a comment.

Installing Image Magick and Imagick for PHP for MAMP

Jun 28, 2010   //   by the guru   //   Imagick, MAMP, PHP  //  7 Comments

Now this is one topic I am glad I have got through. This caused me no end of grief.

I think before we get to the nitty gritty of installing and configuring the software it is important to understand what Image Magick and Imagick are. I thought at first it was the same thing. Oh how wrong!

Image Magick is a command-line suite of tools to manipulate images. For further information on this visit the Image Magick site.

Imagick is an extension of PHP that consists of a number of classes and functions for working with Image Magick.

It basically means we need to install Image Magick first and then compile the Imagick extension in PHP that is dependent on Image Magick.

1. Installing MacPorts

To make life easy I installed MacPorts, which made it very easy to install Image Magick. You will need MacPorts in order to follow this post. Don’t worry if you haven’t installed MacPorts yet as you can find out how easy it is to install by viewing my “Installing MacPorts” post.

Please note that if you have Mac OS X 10.5.x or later you need to have Xcode 3.1.4 installed or later.

EDIT: Big thank you to Mike Puchol and his article Getting MAMP 1.9 to work with Image Magick, imagick.so and other flora for the next snippet for making MacPorts build universal binaries.

vi /opt/local/etc/macports/variants.conf

Add the following to the end of the file:

+universal

Save the file:

?wq

2. Installing Image Magick

Using MacPorts we simply need to enter:

sudo port install ImageMagick

Now I would suggest putting your feet up, grab something to eat, grab a beer or something else more interesting as this process takes about 30 minutes to finish. There are a number of dependencies that have to be installed.

Here’s One I Prepared Earlier…

Once that is all sorted you then need to update the environment $PATH variable in your user profile. To access your profile enter:

vi ~/.profile

Enter the following line:

export PATH="$PATH:/opt/local/bin"

For more information on this see “Updating Your Export Path in OS X”.

Close terminal and re-open it again. Then test Image Magick to see if it is working:

convert -version

If you get an error then there is a problem. Drop me a comment and I will see what I can do.

3. Now Installing The Tricky Imagick!

We now need to install the Imagick extension using PECL:

sudo pecl install imagick

Is that it I hear you say? Well let me tell you that it is at this point where I lost my rag given all the problems I had. I had got so lost I even nearly turned to the dark side and tried searching on Bing! To try and help I have added the issues I had and what I did to sort them.

A Make Error Occurs

I found this issue is likely to be down to the C compiler not being present. You will notice that there is an error relating to this, but it is right at the beginning of the make output. The easiest way to check if you have the C compiler is to type:

gcc

If you get a bash error then it is not installed. You can also check to see if the /usr/bin/gcc folder exists as that is where it should be.

So, to fix this issue you simply need to install the Xcode Tools. The quickest way to do this is on the installation disc that came with your Mac. It will be under the optional installs. If you can’t find the installation disc you can download the latest Xcode tools from the Apple Developer Connection site.

32bit and 64bit Architecture

As standard, MacPorts will not build universal binaries, which is what the PHP version run by MAMP uses. And as some versions of Mac OS X like Snow Leopard use 64bit architecture this can cause an issue. To get round this you can force MacPorts to build all the universal binaries by entering:

sudo port upgrade --force installed

Like installing Image Magick this will take a bit of time, so kick back and relax.

WARNING: php appears to have a suffix…

This is due to the PHP path being referenced twice or more in the environment variable $PATH. This is probably due to the /usr/bin and /Applications/MAMP/bin/php5.3/bin folders being present when they effectively point to the same place. You just need to remove the MAMP path. Restart terminal and you should be good to go. Don’t forget to check your $PATH enter:

echo $PATH

4. Are We There Yet?

Right, so the install of the Imagick extension has been successful. If so, you should see a message saying where the .so file was installed. You now need to copy that file over to the MAMP files:

cp /usr/lib/php/extensions/no-debug-non-zts-20060613/imagick.so /Applications/MAMP/bin/php5.3/lib/php/extensions/no-debug-non-zts-20090626/imagick.so

The above should be similar to yours, but will slightly differ, but you should be able to work it out.

The last bit then. We just need to add the new extension to the php.ini file. In MAMP select File -> Edit Templates and select the php.ini file you are using for your version. In the file add the Imagick extension:

extension=imagick.so

Apply the changes to MAMP, which should restart Apache and MySQL. Job done!!!

It has been emotional! This was a tough one, so if you need any help or have any suggestions just drop me some comments.

Installing Symfony in MAMP on OS X

Jun 28, 2010   //   by the guru   //   Mac, MAMP, PHP, Symfony  //  14 Comments

At the time of writing I am on a MacBook Pro with OS X 10.5.8, MAMP PRO 1.9 and Symfony 1.4.

MAMP? Have you got it and is it installed? If not why not? MAMP is for me the best development environment (Mac, Apache, MySQL, PHP) for the Mac and for £20 you can’t go wrong. It installs with minimum fuss and gives you a pretty interface to manage your local sites.

If you need MAMP in your life visit the MAMP website.

I will now assume you have MAMP installed and we are ready to go. I will also assume that you know of the Symfony PHP framework as you are here reading this. If you need more information on it visit the Symfony website. All I will say in this article is rapid web development!

Before you do anything it is very important that we rejig the PHP libraries used by MAMP. MAMP uses its own libraries and not the standard libraries installed as default in Mac OS X. This may seem trivial, but if you want more that just PHP or if you want to add a number of PHP extensions like Imagick for example then this is critical. The issues boil down to the different versions using 32bit and 64bit compilations. I discuss this in more details in “Installing Image Magick and Imagick for PHP for MAMP”.

1. Creating a Host

Once you have MAMP up and running make sure you have setup a new host for the site.

MAMP Pro Hosts Page

MAMP Pro Hosts Page

When you visit your new site in your Browser you should be able to see a standard MAMP page.

2. Moving PHP

Firstly move the current PHP to a different location (we don’t need to delete it altogether):

sudo mv /usr/bin/php /usr/bin/php-old

Sudo is a command used to perform operations with the security privileges of the super user and is required for a lot of the main system changes we will be making. You will need to enter your login password when requested by terminal.

Now create a link to MAMPs PHP folder in the /usr/bin/php folder. This uses symlinks (or symbolic links) and tricks the system into thinking the PHP is there without moving MAMPs PHP files.

sudo ln -s /Applications/MAMP/bin/php5.3/bin/php /usr/bin/php

Please note that I have installed MAMP and configured it to use PHP 5.3. If you have not chosen to use version 5.3 just replace that in the command with whatever you have used (probably php5).

3. Moving PEAR

Move the current installation of PEAR to a different location:

sudo mv /usr/bin/pear /usr/bin/pear-old

You may not have PEAR installed in which case skip the above step. You will still need to setup the link below though.

sudo ln -s /Applications/MAMP/bin/php5.3/bin/pear /usr/bin/pear

At this point it will be also worth doing some house cleaning! Update your PEAR channel by entering the following:

pear channel-update pear.php.net

4. Moving PECL

Move the current installation of PECL to a different location:

sudo mv /usr/bin/pecl /usr/bin/pecl-old

You may not have PECL installed in which case skip the above step. You will still need to setup the link below though.

sudo ln -s /Applications/MAMP/bin/php5.3/bin/pecl /usr/bin/pecl

5. Adding the Paths

Now we need to update the export path, so we can use the PHP, PEAR and PECL commands. For more information on this see “Updating Your Export Path in OS X”.

Open your local profile in vi by entering:

vi ~/.profile

Then add the following line into your file:

export PATH=/Applications/MAMP/bin/php5.3/bin:$PATH

Don’t forget to replace the version 5.3 with whatever version you have used.

Also remember that these paths won’t take affect until you close down terminal and re-open it. To test your paths are working type the following:

pear list-all

If you get an error then your paths are not set correctly. Drop me a comment and I will try and help.

6. Fixing MAMP Permissions

Unfortunately, there is a small known bug with the permissions used by the PHP, PEAR and PECL files in MAMP. Luckily for you I have done the hair pulling and can steer you through this. To fix the issue simply enter:

chmod -R 755 /Applications/MAMP/bin/php5.3/bin/

Again don’t forget to replace the version 5.3 with whatever version you have used.

7. Installing Symfony

You could install Symfony using the PEAR library, but I am just not comfortable with this. Any Symfony sites you build in this way then use the core files from the PEAR version of Symfony. If you use PEAR you can become stuck with that version. The reason being is that if you build a website using Symfony 1.0 and then decide for the next project you want to develop in Symfony 1.4 you will have to upgrade the PEAR library from version 1.0 to 1.4 What then happens to the site using the core files for version 1.0? I know that you can freeze the Symfony files, so the PEAR files aren’t used, but personally I just find this messy.

The PEAR Way

As always this is only my opinion on the matter, so if you do want to install the latest version of Symfony using PEAR you can do so by doing the following:

pear channel-discover pear.symfony-project.com
pear install symfony/symfony

From here you can follow the installation instructions from Symfony or you can follow my way below through the whole process.

…or I Did It My Way!

This is also how the developers at Symfony prefer you to do it. In their words: “It is not the recommended way of installing symfony, as you should prefer a dedicated installation for each of your projects.”.

My personal preference is to download the Symfony files directly from the Symfony site and go from there. You can download the latest version from the installation page at http://www.symfony-project.org/installation. I downloaded the file as a tgz file and saved it to the root directory of my local site. Create a new set of folders called lib/vendor:

cd /Applications/MAMP/htdocs/newsite/
mkdir -p lib/vendor

Remember to replace “newsite” with the directory of where your new site is stored locally.

You can create your own folder instead of lib/vendor, but this is deemed good practice and from the official Symfony instructions. Next move the tar file into the lib/vendor folder and extract it.

mv symfony-1.4.5.tgz lib/vendor/symfony-1.4.5.tgz
tar -xzvf lib/vendor/symfony-1.4.5.tgz

Then we need to rename the extracted folder to something simpler and remove the tar file:

mv lib/vendor/symfony-1.4.5 lib/vendor/symfony
rm lib/vendor/symfony-1.4.5.tgz

8. Creating a Symfony Project

Now we have installed Symfony we need to setup the project!

Make sure you are in terminal and you are in the directory of your new site. When you are there create a new project:

cd /Applications/MAMP/htdocs/newsite/
php lib/vendor/symfony/data/bin/symfony generate:project PROJECT_NAME

Remember to replace “newsite” with the directory of where your new site is stored locally. Replace PROJECT_NAME with the name of your project.

9. Configuring the Database

These next instructions are on the basis that you are going to use Doctrine instead of Propel. Doctrine and Propel are two database extraction layers that allow you to easily access and manipulate your database. Propel was used in the earlier versions of Symfony, but the developers of Symfony are now pushing Doctrine and I tend to agree with them. If you want to use Propel you can find out more how to setup Symfony with Propel by visiting the Symfony Installation Guide page.

./symfony configure:database "mysql:host=localhost;dbname=dbname" root password

There are many ways you can setup your database to work with Symfony. For more information on this see “Creating and Updating Your Database in Symfony” article.

10. Creating Your Application

Then you need to setup your first application:

./symfony generate:app frontend

You would think this would do now, but there is two more things you need to do.

  1. Go back to MAMP and update the Disk location of the local site to now point to the “web” folder. It would have been something like “/Applications/MAMP/htdocs/newsite”. It now needs to be “/Applications/MAMP/htdocs/agentdunas/web” as the web folder in Symfony is the document root folder.
  2. Apply the changes to MAMP PRO, which should result in Apache and MySQL being restarted.

Now if you go to the site you should see a nice formatted Symfony welcome page. Unfortunately, you won’t as Symfony’s default files are not yet tied up to our web folder! Fear not though a simple symlink should do the trick.

Not So Pretty Symfony Welcome Page

Not So Pretty Symfony Welcome Page

Try this:

ln -s /Applications/MAMP/htdocs/newsite/lib/vendor/symfony/data/web/sf/ web/sf

You should now see:

The Correct Symfony Welcome Page

The Correct Symfony Welcome Page

That was a long one! As always drop me any questions or suggestions.

Updating Your Export Path in OS X

Jun 28, 2010   //   by the guru   //   Mac  //  4 Comments

Seems like a simple one doesn’t it! I thought, so until I tried Googling it. I thought I would post a brief article about how to do this and explain how to use the Mac profile.

Firstly lets explain what the export path is. In simple terms the path is an environment variable called $PATH. The PATH environment variable is a colon-delimited list of directories that your shell searches through when you enter a command.

To see what your current $PATH variable is, enter the following in your terminal:

echo $PATH

So, how do we add to this. Well the variable is updated through the profiles stored on your Mac. The default profile is stored in the /etc folder and is loaded for all users. To edit this enter the following in terminal:

vi /etc/profile

In some cases you may want to add to the path just for a user. In this case you need to use the users profile by entering (you need to be logged in as them):

vi ~/.profile

If you do not have a profile setup, the vi command will add one to your system by opening a new file. For more information and a basic guide on how to use vi visit my “How to Use vi and Learn Some Basic vi Commands”.

If you don’t like using vi or have no idea you can use your default text editor and open the file by entering the following in terminal:

open .profile

So, how do we add to the export path then? Well if you want to replace the path with your own directories you simply enter:

export PATH=/directory_1:/directory_2

Note how each directory location is separated by a “:”.

For example:

export PATH=/opt/local/bin:/opt/local/sbin

It is important to note that a local user profile for a user will override the default path variable if you set it to your own paths. This is not always good. Especially if you have other apps using the path variable. In this case you don’t want to overwrite them when your machine loads. To get around this we just append to the path. To do this we enter:

export PATH=/directory_1:/directory_2:$PATH

or

export PATH=$PATH:/directory_1:/directory_2

Don’t forget the paths run in order of priority, so the paths that come first are used first. This is why you can append before or after the current path as showed above. A real-life example may look like:

export PATH=/opt/local/bin:/opt/local/sbin:$PATH

Well I hope that clears up some confusion. It may just have been me, but there we go. Comment me with any questions or suggestions.

Fixing “No Network Card Installed” on a Mac

Jun 26, 2010   //   by the guru   //   Mac  //  2 Comments

This was a particular pain in the arse for me and caused me no end of grief! Hopefully this post will help some of you in a similar situation.

At the time of writing this fix works on a MacBook Pro 15 inch running Mac OS X 10.5.2.

Looking at some other posts around there were a number of potential causes and fixes. I tried them all and found one that worked. I have compiled a list of these different methods though, so hopefully one will work for you. It does my head in when people post what worked for them, but not everything else they tried. I hope to write posts that cover all angles!

Before you try any methods there is a simple test that will determine the severity of the problem you may have, which is worth doing before you attempt to try and fix the issue.

Diagnostic Check

  1. Make sure you have your Mac OS X install disc in your optical drive.
  2. Shut down your machine.
  3. Turn on your machine again and hold down the Shift key. This will boot your machine in safe mode.
  4. Shut down your machine again.
  5. Remove the battery.
  6. Remove the power cord.
  7. Hold down the power button for 5 seconds.
    This has reset your System Management Controller (SMC).
  8. Turn your machine on and hold down the “c” key while the computer boots.
  9. Check for an Airport menu while booted to the install disc.

If there was no sight of anything Airport related you are basically dealing with a shot Airport card or motherboard. If there is a mention then we are good to try one of the methods below to resolve the issue.

Method 1: Reinstall Mac OS X

Straight forward to do, but a pain in the arse setting up your machine all over again. I did this and it worked until I downloaded the latest updates for Mac OS X from Apple. I had heard that the Airport card issue seemed to appear after a particular update is installed from Apple. This appeared to be the case for me, so I would not recommend reinstalling Mac OS X in this case. If you are starting from scratch then it is all good.

Method 2: Remove the Airport Extension

Go to the /system/library/extensions/ folder and find the appleairport.kext file. Delete this file and shut down your machine. Don’t restart your machine. Apparently you need to shut down your machine. You will also get a message about cache, which is fine and expected. This method didn’t work for me, but it did seem to for a lot of people out there.

Method 3: “That’s the Badger!”

This was the jackpot for me! Following the below steps sorted the issue and I haven’t looked back since.

  1. Shut down your machine.
  2. Turn on your machine again and hold down the Shift key. This will boot your machine in safe mode.
  3. Shut down your machine again.
  4. Remove the battery.
  5. Remove the power cord.
  6. Hold down the power button for 5 seconds.
    This has reset your System Management Controller (SMC).
  7. Turn your machine on and hold down the “cmd” (command), “alt” (option), “p” and “r” keys.
  8. Keep holding down the keys as above until you get a blue screen and a start-up chime three times.
    This will take a bit of time, but keep holding the keys down until you hear the last start-up chime.

Again these methods may not work for everybody, but hopefully it will work for some of you. Give me a shout if you have any questions or suggestions.