PHP 5.4 on nginx

Okay, so I’ve made the switch to nginx for its more stable memory footprint compared to Apache, and everything’s gone great.

However, it’s on PHP v5.2, and I can’t seem to get it onto v5.4, which was what I was using before.

I followed the instructions here on the Wiki to switch to PHP 5.4, creating a ~/.php-launcher file with the correct exec command (and making it executable), as well as adding the link to php.ini under ~/.php-ini

Both of these are correct as far as I can tell, however, when I reboot my VPS it continues to use php 5.2.

Can someone please clarify the process for this? Also, does it require a VPS admin account? I would assume not, and am hoping so, as I’ve managed everything else without having to create one (as I’m fine with nginx’s other default settings).

Here’s the executable ~/.php-launcher file I’m trying to use:

It seems that, contrary to the wiki page, the ~/.php-launcher file is not an actual feature at all, which is very disappointing as it’s been mentioned on the wiki page for over three years without modification!

Can someone please clarify what the best/easiest method is for changing the PHP version used by nginx would be? From everything I can find it seems nginx just triggers FastCGI, so presumably it’s that which is actually responsible for starting up PHP, but I have no idea how to configure it with the way things on Dreamhost are setup.

This is one of the reasons why I removed all ngn packages (dreamhost default packages) from the entire VPS. I edited the sources list and included the dotdeb URL’s so PHP 5.4.x can be installed. The only downside is that the websites part through the DH control panel no longer works. No biggy for me since I do mostly everything through shell anyway.

And yes, FastCGI is used to read the PHP files. Nginx (and apache) can for example only read the htm(l) files.

Either way… if you want it more “simpler”… I can’t remember it, at the moment. (might look for it later if you still need help) But one of the files on the VPS can be edited so it’ll pinpoint to the 5.4 php directory, rather than using the default php 5 directory of which is still using the older PHP version.

Oh, I forgot to update this, I finally figured some of it out you see:

The ~/.php-launcher file isn’t used if a PHP_SUPERVISOR environment variable is set, which causes nginx to just leave it up to supervisord. Now I can’t for the life of me remember where that was actually set (it took some tracking down), but once I changed it the nginx init.d script starting using .php-launcher as expected.

Unfortunately I’ve found that launching PHP in that way is somewhat unstable (possibly because I have fairly high traffic which was my main reason to switch to nginx), so I’m actually taking the weird approach of having .php-launcher trigger my own supervisord process with a custom configuration, so I kind of get the best of both; i.e - I can fully configure supervisord without having to change the dreamhost defaults (so hopefully updates won’t break anything), plus I still get some of the added flexibility of customising extra actions for .php-launcher to run first. It still requires a VPS admin account though, as you need to disable the default supervisord process (I did it by setting supervisor’s init.d file to mode 000 as the root user) as well as finding the environment variable that prevents the nginx init.d script from running .php-launcher. I’ll have another look for that environment variable as I should probably add it to the wiki for others who run into the same problem.

That’s kind of you to do that. I’m pretty much sure people would be able to use that in the future.

In the future Debian will be replaced with Ubuntu, here on Dreamhost of course. I’m (hoping at least) that switching to a newer version of php/nginx will be easier seeing it’s more supported than on Debian 6. I had to add a non-official source url in order to get PHP 5.4