Skip to content
May 21 13

Vagrant PHP and PuPHPet is the Dogs Bollocks!

by Andrew McCombe

In The Beginning…
I’ve been a PHP Web Developer for a long long time and have spent many hours setting up development environments in order to practice my trade. From full blown towers running full cdrom installations of RedHat 6.2 through to a laptop running FreeBSD and then Slackware. I used to compile the LAMP stack from source, eventually ending up with a huge install script that would wget the latest Apache, MySQL and PHP sources, compile them, make and install.
However, over the years this got tedious and I eventually settled for running Ubuntu server on a VirtualBox Virtual Machine and installing the LAMP stack via ‘Tasksel’. Everything was fine; I could use my years of Linux Sysadmin skills to create new MySQL databases, add new websites, configure Apache and install other cool new stuff too (like [...] Continue Reading…

May 17 13

PHP imagick ImagickException no decode delegate for postscript or PDF files

by Andrew McCombe

This morning I had an issue with a PHP imagick ImagickException when converting a PDF/postscript file to a thumbnail. I have PHP Imagick, Imagemagick and Ghostscript installed and everything verifies as OK in phpinfo output. [...] Continue Reading…

Apr 10 13

Magento admin login problem in Chrome – with solution

by Andrew McCombe
Magento Logo

Recently I’ve been experiencing a Magento admin login problem in Chrome. The problem is that when I enter the correct username and password on the Magento admin login screen it simply returns back to the same screen. This was when working locally using http://magento/my-site as the domain name.
The solution?
Simple. The problem occurs because the domain name isn’t a fully qualified domain name and so the browser won’t accept the cookies. Simply change the domain name to one with a dot in it (a period for the American readers). Once I’d changed it to http://magento.local/my-site it worked perfectly.

Mar 30 13

Formula One Website Performance: The fastest team Is…

by Andrew McCombe

Formula one is the pinnacle of motorport. We know the cars are fast and the pace of development is relentless, but when it comes to performance how do the teams websites compare? [...] Continue Reading…

Mar 25 13

Routing requests to index.php with Apache

by Andrew McCombe

Routing requests to index.php with Apache

Here’s how to go about routing requests to index.php with Apache. I’m always having to search for this online so I thought I’d document it here. Many of the ‘modern’ PHP applications use index.php as a router, including WordPress, Drupal, Zend Framework, Silex etc.

Using Mod_Rewrite
If you are using Apache pre-2.5 then your only option is to use mod_rewrite to route requests to index.php:

RewriteRule ^index\.php$ – [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L,QSA]

Using the FallbackResource Directive
From Apache 2.5 onwards you can use the new FallbackResource Directive:

FallbackResource /index.php

Documentation for this is available at http://httpd.apache.org/docs/trunk/mod/mod_dir.html#fallbackresource.

Mar 12 13

PHP backtick gotcha

by Andrew McCombe

This PHP Snippet caught me out today:

Feb 13 13

Install PHP 5.4 and Nginx on Ubuntu 12.04

by Andrew McCombe

Whilst the LAMP stack is easy to install (sudo tasksel & select ‘LAMP’), installing PHP 5.4 and Nginx on Ubuntu 12.04 isn’t as straightforward. For a start, the packaged Nginx is out of date and PHP5.4 isn’t currently available at all out of the box. Luckily there are PPA’s for installing PHP 5.4 and Nginx. [...] Continue Reading…

Feb 13 13

Finding source of JQuery onclick event handlers with Google Chrome

by Andrew McCombe

Ever had issues finding where a JQuery click handler is defined? Got a project with LOTS of Javascript and can’t find where an event is handled? Here’s how to find out using Google Chrome.

Inspect your element.
Go to console and enter ‘$($0).data(‘events’);’ ($0 is the current selected element)
Expand the object, right click on the handler: ‘function()’
Select ‘Show Function Definition’. This will open the Javascript file at the definition in Google Chrome’s sources tab.

Jan 5 13

Developer Tools: Vim keyboard shortcuts

by Andrew McCombe

I regularly use Vim but have to confess that I’m not a ‘power’ user. To help me learn Vim keyboard shortcuts I have noted them down here. [...] Continue Reading…

Jan 2 13

Forcing a file to download using the Silex PHP framework

by Andrew McCombe

I’ve just been searching for a way to force a file to download using the Silex PHP framework and didn’t find any examples. After reading through the Silex code I worked it out. Here’s how to force a file to download using Silex:

$app->match(‘/export’, function() use($app) {
/**
* create the file and save to disk
*/

$stream = function () use ($file) {
readfile($file);
};

return $app->stream($stream, 200, array(
‘Content-Type’ => ‘text/csv’,
‘Content-length’ => filesize($file),
‘Content-Disposition’ => ‘attachment; filename=”file-download.csv”‘
));
}

Dec 19 12

Install PHP and Mysql on OSX Mountain Lion

by Andrew McCombe

Install PHP and Mysql on OSX Mountain Lion

I usually develop on an Ubuntu VM running in VirtualBox but have needed to install PHP and MySQL on OSX Mountain Lion on the MacBook Pro. Here’s a Github Gist from Aaron Brady with details on how to do it.

Install Xcode, Command Line Tools, Xquartz (on 10.8)

In a terminal (probably best to do one thing at a time):

ruby -e “$(curl -fsSkL raw.github.com/mxcl/homebrew/go)”
brew tap homebrew/dupes
brew tap josegonzalez/homebrew-php
brew install php54 –with-mysql
chmod -R ug+w /usr/local/Cellar/php54/5.4.7/lib/php
pear config-set php_ini /usr/local/etc/php/5.4/php.ini
PATH=”$(brew –prefix josegonzalez/php/php54)/bin:$PATH”
cat >> /etc/apache2/httpd.conf > ~/.profile

Oct 16 12

How to highlight keywords when using tail

by Andrew McCombe

How to highlight keywords when using tail

Have you ever been tailing a log file looking for a specific keyword or phrase? Maybe you’re tailing an Exim log watching for an email, or an Apache log file for a specific request. Wouldn’t it be really great if you could highlight the keyword or phrase? Here’s How to highlight keywords when using tail.

tail -f file.log | perl -pe ‘s/keyword/\e[1;31;43m$&\e[0m/g’

The “\e…/g” section can be replaced by some semicolon-separated integers, with the meaning:

0 : all attributes off
1 : bold
31 : foreground red
43 : background yellow

“keyword”, of course, can be any perl regular expression:

(foo|bar) highlight the strings foo and bar
\b((foo|bar)\b highlight the words foo and bar
.*\b((foo|bar)\b.* highlight the whole line that contains the words foo or bar

Oct 15 12

Restart Apache on Mac OS X Mountain Lion

by Andrew McCombe

This is here for reference as I keep forgetting how to restart apache on Mac OS X Mouintain Lion. Here’s how to do it:

sudo /usr/sbin/apachectl restart

Enter password and you’re done.

You can also start and stop Apache by using the ‘start’ and ‘stop’ parameters:

sudo /usr/sbin/apachectl stop
sudo /usr/sbin/apachectl start

Sep 25 12

Zend Framework Elephants available for pre-order – and they’re GREEN!

by Andrew McCombe

That’s right! Ben Scholzen AKA DASPRiD has a limited quantity of Zend Framework Elephants available for pre-order – and they’re GREEN! Instead of the familiar blue elePHPant that we’re used to, the ZF ones will be green!.

You can pre-order yours from the link below. Small elePHPant are 7€ each and large ones are 70€ each. Shipping costs are not included in the elePHPant prices, and are not known yet but are shipped from France, so you can somewhat estimate the cost.

Pre-order yours now: http://elephpants.dasprids.de/index.php

Sep 24 12

Change the cursor with JQuery

by Andrew McCombe

Change the cursor with JQuery
Occasionally I use JQueryUI components to display dialogs and I like to set the cursor to the ‘timer’ when the event is triggered and back to ‘auto’ afterwards. Here’s how to change the cursor with JQuery.

$(‘body’).css(‘cursor’, ‘wait’);
To set it back:
$(‘body’).css(‘cursor’, ‘auto’);

For more information on JQuery’s CSS function please visit the JQuery CSS manual at http://api.jquery.com/css/

Jul 25 12

Detect iPad and iPhone with PHP

by Andrew McCombe

If you ever have the need to detect iPad and iPhone with PHP, or any other mobile/tablet device, you can use the excellent php-mobile-detect library available at http://code.google.com/p/php-mobile-detect/.

Example usage:

Jul 11 12

How to find the Magento version

by Andrew McCombe

Often you will need to know which version of Magento you are running in order to install an extension or apply a security patch. Heres how to find the Magento version you are running.

Jun 29 12

Gzip javascript and css with NGinx

by Andrew McCombe

Nginx by default will only compress text/html content types. Heres how to gzip javascript and css with NGinx:

In your nginx.conf file:

http {
include /etc/nginx/mime.types;

access_log /var/log/nginx/access.log;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;
tcp_nodelay on;

gzip on;
gzip_disable “MSIE [1-6]\.(?!.*SV1)”;
gzip_types application/x-javascript text/css;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}
….
Or in your sites-enabled site file:

server {
listen 127.0.0.1:81;
server_name localhost;

[...] Continue Reading…

Jun 12 12

Bookstore Added ft WordPress and Magento Books

by Andrew McCombe

I’ve added an Amazon Bookstore featuring web development books. There are JQuery, PHP MySQL, WordPress and Magento books. Please take a look and if you wish to but, please click the links and help me get a bit back.

Click here to go to the bookstore

May 30 12

Sending HTML Mail via SMTP with PHP Pear Mail

by Andrew McCombe

Pear Mail Mime Example

Here’s how to send html email via remote SMTP using PHP and Pear Mail / Mime.

Installing Pear Mail
To install the classes you should enter (as a superuser):
pear upgrade
pear install Mail
pear install Mail_Mime
pear install Net_SMTP

Pear Mail Mime Example
The following code shows how to send an HTML mail using Pear classes over SMTP.

euperia.com / Website Engineer located at , Midlands, UK . Reviewed by Andrew McCombe rated: 1 / 5