Skip to content

Instantly share code, notes, and snippets.

@yang-wei
Created October 28, 2015 04:44
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save yang-wei/370b8c9bc508d9fc9048 to your computer and use it in GitHub Desktop.
Save yang-wei/370b8c9bc508d9fc9048 to your computer and use it in GitHub Desktop.
How to use switch PHP(using phpbrew) version in nginx config
php -v
PHP 5.6.3 (cli) (built: Oct 28 2015 09:47:41)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

But this only changes in CLI. You have to tweak you nginx(same for apache) to make it works. Nginx will still using the native PHP-FPM.

> ps aux | grep php-fpm
user     17093  0.7  2.5 512976 26080 ?        Ss   13:40   0:00 php-fpm: master process (/etc/php-fpm.conf)
> phpbrew fpm start

To know which port our phpbrew fpm uses, we can check from ~/.phpbrew/php/php-5.6.3/etc/php-fpm.conf

...
; The address on which to accept FastCGI requests.
...
; Note: This value is mandatory.
listen = 127.0.0.1:9000

Ok it's 127.0.0.1:9000. So in our nginx configuration, we do something like:

server {
 ...
 
   location ~ \.php$ {
    try_files       $uri =404;
    #fastcgi_pass    unix:/var/run/php-fpm/php-fpm.sock;        <--- probably default setting
    fastcgi_pass     127.0.0.1:9000;            <--- changed this
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include         fastcgi_params;
  }
}
@carl-parrish
Copy link

Never mind I changed it to use a tcp socket like you had in your example and it's working fine now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment