Monday, September 6, 2010

Making PHP to work on Mac

Its such a pain that the most simplest of the things are the ones which people 'forget' to mention! (I have been often guilty of same to be truthful)

I was trying to get Apache, PHP and MySQL working on my Mac and couldn't get a simple 'HelloWorld' in PHP to run on the machine even after supposedly getting everything in place.

I am not going into installation/settings of the PHP / MySQL Or enabling of Apache as that is presented in most of the sites in a very lucid manner, I will just list the issues I ran into and which didn't have a very clear answer on any of the sites for installation and use of the 'AMP' technology.

The two things I stumbled over were:
1. Editing the httpd.conf file for enabling PHP
2. Getting the code to run

(Working on both issues assume you have administrator privileges on the machine and/or can provide credentials when asked for - I had almost made the same mistake of 'forgetting' to mention the simplest thing!)

Editing httpd.conf

Starting with the most basic info which is 'forgotten' while mentioning editing the conf file to enable PHP is that the file is hidden. Almost everybody will mention that the file is at: /private/etc/apache2/httpd.conf. But, if you are new, you can spend all day trying to search for it. And unless you are well versed with searching and editing the file through the terminal by using something like:
sudo vim /private/etc/apache2/httpd.conf

The other methods are:
a) Use an App e.g. Houdini to manage hidden files and folder via GUI
b) run the following command on your terminal :
defaults write com.apple.finder AppleShowAllFiles TRUE
and then restart the Finder on your machine by using killall Finder

Now, you should be able to see and access all the hidden files and folders through any text editor. The \etc folder being in the 'Macintosh HD'

Though, I read that BBEdit and similiar other such editors can show hidden files using their 'View' option, I wasn't able to do so till I did the step above (quite possible I wasn't looking properly)

Now, its much easier to see and uncomment the :

LoadModule php_module libexec/apache2/libphp5.so

Getting the code to run

In hindsight, I understand that there are two ways of writing PHP code: the old way - using just "<? Code ?>" and the new way - "<?php Code ?>"
The below section in the php.ini was set to 'On' and the old style worked with this setting - which I could successfully run after trying many other things and being pointed in the right direction here . And, on turning it 'Off', I am able to get the new style to work. Though as I am only starting out - I have just tried phpinfo() and echo till now.

; short_open_tag
; Default Value: Off

Thursday, July 29, 2010

"Microsoft Messenger Daemon" is still in use

Well, not to sully the Microsoft name - this could happen to any other application on a Mac - replace "Microsoft Messenger" with any other which would not uninstall completely and keep files in the trash.
To begin with, I was having issues with the Microsoft messenger on my iMac. Though it works perfectly well on my MacBookPro it somehow decided it doesn't want to find the system available after a few minutes and sign out.
To uninstall the messenger I decided to try out the "AppCleaner" application for a 'clean' uninstall. But, it still left some files in the Trash and I wasn't able to empty the bin cause the daemon (an part of an application which keeps running in the background where it does not get in the way of other stuff) was still running!
On trying to find out the simplest way to get over this I couldn't get a straight answer quickly, though after doing this it is pretty simple:
1. Use spotlight or Quicksilver to find Activity Monitor (this is found in the Applications -> Utilities -> Activity Monitor)
2. On the top bar there is a drop down menu for the selection of type of processes to display. Use the 'All Processes' display (just to be sure)
3. In the name column there is an entry for "Microsoft Messenger Daemon" -> use the 'Quit Process' button on the top bar to Quit / Force Quit the daemon
4. Try to empty the Trash

Now it goes away without any error!