EDIT: For future reference
I am running Ubuntu 14.10 with a LEMP stack using PHP 5.5.12. I have a number of legacy WordPress sites that require PHP 5.3.3 alongside some WP sites that use a fairly recent version of PHP, all running on nginx on my local machine.
My hands are tied in respect to virtual machines and sandboxes, all I can play with is nginx, hence this question. I understand peoples security concerns but I need these sites to run locally so I can test for broken features as I update them to the latest PHP / WP versions.
I want to have nginx run the correct version of PHP (using php-fpm) depending on the WordPress site. According to another SF question, one way to achieve this is to have the different PHP versions running on separate ports / sockets and configure the nginx server blocks to use the respective port / socket.
I have compiled PHP 5.3.3 manually to include php-fpm but that is the furthest I have got.
Effectively, I want someone to explain in a little more detail this answer. I can't quite figure out how to "run each version of php-fpm on a different port (or socket)" or "configure the appropriate port in your fastcgi_pass parameter in your nginx server block".
One of my server blocks looks like this for reference
server { listen 80; listen [::]:80; root /usr/share/nginx/html/testsite1; index index.php index.html index.htm; server_name local.testsite1.com; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi.conf; } }
EDIT:
I set up each site using a separate server block in a separate file, sym linked between /var/nginx/sites-available/testsite1
and /var/nginx/sites-enabled/testsite1
. So var/nginx/sites-available
contains;
testsite1 testsite2 testsite3 ...
So ideally I was wondering if something like what is below is possible (since this is similar to how apache can be set up with different PHP versions)
testsite1 - running an older version of PHP
server { listen 80; listen [::]:80; root /usr/share/nginx/html/testsite1; index index.php index.html index.htm; server_name local.testsite1.com; ...settings to use older PHP version... ...remaining nginx settings... }
testsite2 - running current version of PHP
server { listen 80; listen [::]:80; root /usr/share/nginx/html/testsite2; index index.php index.html index.htm; server_name local.testsite2.com; ...settings to use currrent PHP version (if needed)... ...remaining nginx settings... }
Is this possible? The reason I ask is that I would rather avoid renaming all my php
files to php2
in order to run (making version control a pain). I don't mind editing the nginx.conf
file or whatever steps it takes, so long as I don't have to rename files.
I also believe I need to use sockets (fastcgi_pass unix:/var/run/php5-fpm.sock;)
over ports due to WordPress (although I'm open to all suggestions).