Skip to content

Instantly share code, notes, and snippets.

@goodjack
Forked from yang-wei/phpbrew-config.md
Created November 26, 2017 13:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save goodjack/1653a6205d72a60eaa38730f9e6157eb to your computer and use it in GitHub Desktop.
Save goodjack/1653a6205d72a60eaa38730f9e6157eb 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;
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment