Solved: Debian Squeeze + Nginx + PHP5-FPM

After tiresomely testing the config – I eventually got it to work.

Once you know how it’s really easy but I kept getting a “502 Bad Gateway” error that confused me.

Benefits of sockets over TCP:

  • Faster connection over sockets than TCP; 20% boost
  • More secure as sockets are harder to break their permissions

Anyway, here’s what you need to do. All config locations are the defaults installed by Debian Squeeze.

Add Dotdeb’s sources in your Debian /etc/apt/source.list

## PHP5-FPM
deb http://packages.dotdeb.org stable all
deb-src http://packages.dotdeb.org stable all

Then install php5-fpm:

apt-get update
apt-get install php5-fpm

Change the settings in /etc/php5/fpm/php-fpm.conf

pid = /var/run/php5-fpm.pid
error_log = /var/log/php5-fpm.log
daemonize = yes
include=/etc/php5/fpm/pool.d/*.conf

Recommended settings in /etc/php5/fpm/pool.d/www.conf

;listen = 127.0.0.1:9000
listen = /var/run/php5-fpm.sock

listen.owner = www-data
listen.group = www-data
listen.mode = 0666

user = www-data
group = www-data

php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
php_admin_value[error_reporting] = 0
php_admin_value[memory_limit] = 128M
php_admin_value[date.timezone] = Europe/London

Start/Restart Nginx and PHP5-FPM and voila

/etc/init.d/nginx restart
/etc/init.d/php5-fpm start

Everything should be running smoothly. Enjoy your new faster server!

Thanks to the people below who wrote about it first.

Create your first Twitter App with Zend Framework

I finally got round to writing my first Twitter App using Zend OAuth.

Here are my tips and explanation to getting your Twitter App up and running.

Getting Started

Register at http://dev.twitter.com/ and create your first App. You can change all the settings at any time, so don’t worry about getting them wrong.

Setting Up the Twitter App

Authorise a Domain URL, you can even use localhost for testing purposes.

It is important you set the Callback URL otherwise you can’t use the Browser App option and your OAuth will fail.

Quickly access your App’s details at http://twitter.com/oauth.

When coding with Zend OAuth, read the documentation carefully!
It has everything you need.

My Mistake

I did not understand how to grab the Access Token. Reason? It’s a two part process. Requesting, then Receiving.

The Code

Here is a working example of a Request Token with Zend OAuth and your Twitter App’s Consumer Key and Consumer Secret.

(Note the keys used are the ones from Zend’s Article)

$config = array(
'callbackUrl' => 'http://example.com/callback.php',
'siteUrl' => 'http://twitter.com/oauth',
'consumerKey' => 'gg3DsFTW9OU9eWPnbuPzQ',
'consumerSecret' => 'tFB0fyWLSMf74lkEu9FTyoHXcazOWpbrAjTCCK48A'
);
$consumer = new Zend_Oauth_Consumer($config);

// fetch a request token
$token = $consumer->getRequestToken();

// persist the token to storage
$_SESSION['TWITTER_REQUEST_TOKEN'] = serialize($token);

// redirect the user
$consumer->redirect();

Steps you must do:

  1. Use the Callback URL to receive the Access Token
  2. Store the Request Token in a $_SESSION
  3. Follow the getAccessToken() example and store this in a $_SESSION or Database (recommended)

Why store the Access Token in a Database?

The best thing about the Access Token is that once you’ve successfully requested one, it never expires!

So save the hassle of requesting a new token and use it throughout your website. Great thing is, it can’t be compromised!

Without the the Consumer Key and Consumer Secret, you can’t hijack the users account for malicious purposes.

Please leave a comment if you want me to write another article about how to implement the example into your scripts or maybe I’ll update this one.

Weekly Round Up: Issue 1

I often hunt around on the internet for the latest information to do with Web Development. Most of the time it goes to my Twitter but I thought it would be great if I could start logging a collection of the best ones I read.

So if you enjoy keeping up with the latest trends, I hope you enjoy my information bites!

HTML5 won’t save the web
http://gizmodo.com/5461711/giz-explains-why-html5-isnt-going-to-save-the-internet

Facebook develop faster PHP
http://www.neowin.net/news/facebook-unveils-hiphop-for-php-039source-code-transformer039

IE8 now “most popular” version of IE
http://www.neowin.net/news/ie8-is-now-the-world039s-most-used-browser

Zend Framework 1.10 Released (and now with versioned documentation!)
http://devzone.zend.com/article/11727-Zend-Framework-1.10.0-STABLE-Released

PHP hates integers (64 bit)
http://www.mysqlperformanceblog.com/2007/03/27/integers-in-php-running-with-scissors-and-portability/

PHP Mantis: The Bug Tracking Tool!

For those budding PHP developers out there, you want to run your eyes over this!

http://www.mantisbt.org/

Mantis is a free Bug Tracking tool like Trac but without the SVN fuctionality.

Why is this useful? There are several reasons.

It’s a quick and easy way to log issues for any type of project. Even if it’s a simple “todo” list for a small job, its a quick and easy. Without the mess of SVN.

Continue reading

PHP Validation Class for Forms

Just to top off my daily posts, I have been perfecting a PHP Validation class over the past few months.

At work I tend to do a lot of registration forms for competitions, subscriptions, newsletters, contact forms etc.

So I went to the trouble of creating a very quick and easy validation class that I could include into my projects at a drop of a hat. Inspired by CodeIgniters validation class, it has very similar features. Including helper functions.

It’s even UTF-8 friendly (except for the email function). Please feel free to download and test it out yourself. Continue reading

Lytebox with javascript Exif Data

Recently I had to integrate a photo gallery for one of my work projects Sony Alpha, a new digital SLR camera from Sony. My task was to display both the Exif data and the image at the same time.

For this project I had to create something new which I haven’t found on the internet before. It uses the popular Lytebox extension (a flavour of the popular Lightbox 2 javascript library) combined with a new javascript plugin that gathers Exif Data for photos via javascript with AJAX. Continue reading