Drupal 6 on OS X 10.6
Running Drupal on OS X 10.5 was a pretty huge pain in the ass. It's much easier in in 10.6 since it includes PHP 5.3 with GD and the PDO out of the box. And Drupal 6.14 resolves the PHP 5.3 incompatibilities.
In this guide I'll walk through the process I used for reinstalling OS X, then installing MacPorts and using it to install MySQL.
Note: I've shortened this up a bunch since it was first posted (originally it was using PHP 5.2 from MacPorts). I also want to make it clear that I am familiar with MAMP but would rather punch myself myself in the face than use it. If you'd like to go right ahead since it's probably easier, and as evidenced by the commenters below, you're in good company. But I'm going to continue to compile my own so I know where everything ends up.
Getting PHP + GD + PostgreSQL working on OSX 10.5 (aka recompiling everything)
Finding myself in need of a PostgreSQL server to test some patches for Drupal core, I've decided to do a follow up to my guide to getting PHP + GD + MySQL installed on OS X.
Fortunately for me John VanDyk wrote up Beginning with Drupal 6 and PostgreSQL on OS X 10.5 Leopard which covers the nitty gritty of getting PostgreSQL server installed. He doesn't address recompiling PHP so I'll pick up the story there.
Last Updated: June 1, 2009
Using Growl to tail a log file
Mikey_p from the Portland Drupal Group pointed me towards a blog post he'd done on using Growl to watch for PHP errors. Always looking to put my fingerprints on something I decided to do the same but using PHP rather than Python.
The short version is install growlnotify then run the following from the terminal:
tail -n 0 -f ~/Sites/nm/logs/access_log | php -r 'while ($m = fgets(STDIN)) shell_exec("growlnotify -p 0 AlertTitle -m ". escapeshellarg($m));'Getting PHP + GD + pdo_mysql working on OSX 10.5 (aka recompiling everything)
This guide walks through the steps necessary to setup PHP on Leopard in order to run the HEAD version of Drupal. The basic steps are installing several prerequisites then recompiling Apache and PHP from source. It could totally bork your system, I'm just writing it down so the next time I need to do this I can remember what I did. I wish I could give credit to all the places I stole bits from but I didn't do a good job of keeping notes early on.
Every time Apple releases a security update it seems to end up overwriting PHP or Apache and I end up revisiting these instructions. Since it's my personal guide I'm continually modifying it to match my current needs. For example, the last big change was adding in old mysql extension and the new PDO-mysql extension. The upside for you, kind reader, is that this keeps the instructions up-to-date. The down side is that when you come back in two months and try to repeat one part of this it may not work because I've changed some of the earlier steps.
Last Updated: August 26, 2009
Using SimpleXML with HTML
PHP 5's SimpleXML module is one of the the biggest reasons to upgrade to 5. If you're parsing RSS feeds or the results of webservice requests it works beautifully and saves a ton of time. The only problem with it is that it'll only load valid XML. I banged my head against it for way to long before coming up with the following:
<?php
$doc = new DOMDocument();
$doc->strictErrorChecking = FALSE;
$doc->loadHTML($html);
$xml = simplexml_import_dom($doc);
?>Using PHP and CURL to do an HTML file POST
After scouring the internet to find out how to do multipart post operations and finding nothing nothing, I decided to save someone else some time. The trick is that @ before the file name:
<?php
$fullflepath = 'C:\temp\test.jpg';
$upload_url = 'http://www.example.com/uploadtarget.php';
$params = array(
'photo'=>"@$fullfilepath",
'title'=>$title
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $upload_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);
?>Originally posted here: http://drewish.com/blogger/archives/2005/01/27/using_php_and_curl_to_do_...
PHP One-liners
I'm starting a collection of one-line PHP programs that I've used on the command line.
This removes trailing white space from a DOS file:
C:\>php -r "foreach (file($argv[1]) as $l) {print rtrim($l).chr(13).chr(10);}" user.module > user.module.trimedThis little gem escapes code for inclusion in HTML. The invocation uses UNIX's cat utility, on Widows you could use type:
$ cat test.php | php -r "print htmlentities(file_get_contents('php://stdin'));"Installing PHP 5 on Windows
This page provides instructions for a Drupal developer who'd like to install PHP 5 on their desktop computer. The instructions assume that you're running a recent version of Windows (NT, 2000, XP, or 2003). Older version like Windows 95, 98 and Me will not be addressed.
Enabling PHP Modules
Phlickr uses two several of PHP5's extensions, CURL and SimpleXML. In some cases these two extensions may not be enabled by default.
The first step is verify that the modules are not already being loaded. You view a list of the modules using the following command:
Downloading Democracy Now! automatically
Here's a PHP script I wrote for the radio station to download each day's copy of Democracy Now!. This requires that the PHP cURL extension be installed.
Setup Drupal 5
The station's website will be build using Drupal an extremely powerful, open source content managment system written in PHP.
Drupal uses some PHP functions that require the installation of additional ports. You'll need:
- devel/php5-pcre - Perl regular expressions.
- textproc/php5-xml - XML parsing.
- databases/php5-mysqli - MySQL support for PHP.
- www/php5-session - Session support.
- graphics/php5-gd - Image handing. Optional, some modules need it.
- converters/php5-mbstring - Unicode support. Optional, but Drupal prefers that it be installed.
Uploading a photo
This sample shows how to upload all the JPG files in a directory to Flickr. Take a look at the PhlickrUploader script listed on the tools page for a more complete uploading example.
FAQ
- Q: Does Phlickr work with PHP4?
- A: No, [[Phlickr]] uses several of the new features in PHP5. You'll need to try one of the [[other PHP projects]], most are compatible with PHP4.
- Q: Can you recommend a PHP5 web host
Phlickr
Phlickr is an open source PHP5 based api kit used to access the Flickr API.
I co-authored the book Building Flickr Applications with PHP published Apress.