Tuesday, August 28, 2012

PHP Settings for Drush in OSX

Drush has been testing me...

Faced with the Fatal error: Allowed memory size of millions of bytes exhausted (tried to allocate a couple of bytes) message on practically every conceivable Drush operation, thought it was time to invest in my dev environment to sort my Mac out...

Turns out that the php.ini file used by your local web server is different to the one Drush uses on the command line. My local development server usually runs with memory_limit=512M (although hosted sites usually run with 256M or less).

To find out which version of PHP Drush uses, drush status may help. However, which php may give you the best answer: if it's /usr/bin/php and your Drush status PHP Configuration is blank, chances are PHP is running with a miniscule amount of memory resource for CLI-issued commands. In which case you need a new php.ini file in your /etc folder to give Drush more beef. There are already default ones in this folder, so just copy one of these and edit.

cd /etc 
sudo cp php.ini.default php.ini 
sudo chmod 666 php.ini 

Then edit your new php.ini file and set memory_limit=512M in the php.ini file.

If you need more help on understanding what php.ini is all about, there's a useful article at http://drupal.org/node/207036 and explains the various tweaks to help Drupal and Drush work well. Please note, not all hosting providers will allow you to adjust php.ini, especially the cheaper, shared hosting accounts.

Thursday, March 01, 2012

Creating Web Apps in iOS

Lots of ways to make your website/application run as a full screen iOS 'app.' Google the subject and you'll be spoilt for choice.

The biggest problem I had was after I'd finished the basics: created a homepage icon, set the website to be full screen capable (etc). The front page of my web app opened full screen, but as soon as you click on a link (internal or otherwise), mobile Safari is opened for the target page and all the full screen, app-like goodness is gone.

Prevent Mobile Safari Launching

To keep the user inside your iOS 'app' (and not wandering off into the big fat interweb), embed this cheeky little script right at the end of your <body> tag.

<script>(function(a,b,c){if(c in b&&b[c]){var d,e=a.location,f=/^(a|html)$/i;a.addEventListener("click",function(a){d=a.target;while(!f.test(d.nodeName))d=d.parentNode;"href"in d&&(d.href.indexOf("http")||~d.href.indexOf(e.host))&&(a.preventDefault(),e.href=d.href)},!1)}})(document,window.navigator,"standalone")</script>

And this came from a great little discussion at gist.github.com/1042026. It works on iOS 5.

Mobile Checklist

The best checklist I've found for mobifying your site (mainly for iOS and Android) is at html5rocks.com/en/mobile/mobifying/. But the key points are:

  • Create iOS/Android homepage icons - of varying sizes.
  • Embed the relevant META tags to allow the site to render full screen.
  • Optimize your site to take advantage of HTML5 and CSS3 - back to the 90s boys and girls: think of low bandwidth for those truly mobile users.
  • Use media queries to tweak your layout for different screen sizes (and portrait/landscape orientation)
  • Ensure your site design and UI is built around a touchscreen (big, fat buttons and a vertical layout for the really small devices)
  • Keep the user within your app for as long as possible (see above for 'link' issues about preventing Mobile Safari launching).

Friday, February 24, 2012

Embedding Phone Numbers with HTML5 for iOS

Snippet to embed contact data in a web page so that an iOS device can recognise text as a phone number or as contact data. Use the 'itemprop' attribute, although you can also wrap the div in a 'vcard' class, and setting the class of the phone number span to 'tel' seemed to do funky things too:

<div itemscope>
  <span itemprop="name">Rob Carr</span>
  <a class="nowrap" href="mailto:rob@google.com" itemprop="email">rob@google.com</a>
  <span class="nowrap" itemprop="tel">+44 1234 567 890</span>
</div>

I added a 'nowrap' class (white-space:nowrap;) purely for styling and usability. When the name or phone number is clicked on, you get the iOS dialogue box:


Contact info recognition doesn't seem to work on HTML5 desktop browsers, and no idea about whether other mobile devices will recognise the 'itemprop' property.

You can wade through the Microdata spec for HTML5 at http://dev.w3.org/html5/md/, or Google for more examples. HTML5 Doctor always a good read.

Thursday, February 09, 2012

Install Drupal Remotely with SSH & Drush


  1. Connect to your server with SSH (using OSX Terminal, or Putty on Windows):
    ssh <username>@<site address>
    See en.wikipedia.org/wiki/Secure_Shell for some background on SSH.
  2. In your server root directory - preferably not the 'Public HTML' directory, WGET the Drush tarball of the latest release of Drush (currently at release 4.5):
    wget http://ftp.drupal.org/files/projects/drush-7.x-4.5.tar.gz
  3. Use TAR to extract and de-compress the archive, eg:
    tar xzvf drush-7.x-4.5.tar.gz
  4. Set up an alias to Drush
    alias drush='/myserverroot/home/drush/drush'
  5. Change working directory to Public HTML root of server
  6. Download the Drupal code
    drush dl drupal
  7. Move the download 'up' one level (the .htaccess file won't get copied in the blanket move command):
    mv drupal/* .
    mv drupal/.htaccess . 
  8. Remove the original [now empty] directory: 
    rm –r drupal
  9. Create a MySQL database (you may need to do this via your host's control panel)
    mysqladmin –u <db_user> –p create <db_name>
  10. Install the Drupal site
    drush site-install standard --account-name=admin --account-pass=<useruser_pass> --db-url=mysql://<db_user>:<db_pass>@localhost/<db_name>
  11. Fame and glory await
For more advice and a screencast, go to LevelTen's site, for a great post by Tom McCracken.

Only snag I've had with some hosts is providing enough resources for PHP/Drush to execute commands: 'Out of memory' a common problem, especially on shared hosting which may have relatively low memory. 256MB seems to be the minimum you can get away with to allocate to PHP [for Drupal/Drush] to run, so make sure when you purchase a hosting package, that you can have enough memory to play with.

If you have messed about a bit with Drush, you can check where your version is stored by running which drush on the command line. In this directory you may need to add a php.ini file that has suitable settings (eg memory_limit). Lots of issues on drupal.org to help you: Google is your friend. If you can't tweak php.ini, you may be able to tweak drushrc.php - see www.mcdruid.co.uk for a bit of helpful advice.