Skip to content

symlink issues with php-fpm #5758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed

Conversation

kendrick-k
Copy link
Contributor

symlink

        fastcgi_param DOCUMENT_ROOT $realpath_root;

permits to have the real path with the current symlink while deploying with Capifony (evoiding restarting php-fpm)

# symlink
            fastcgi_param DOCUMENT_ROOT $realpath_root;

permits to have the real path with the current symlink while deploying with Capifony (evoiding restarting php-fpm)
@xabbuh
Copy link
Member

xabbuh commented Oct 6, 2015

Thank you for your contribution @kendrick-k. Can you provide some docs related to your changes that explain in more detail what they are supposed to do and can we add some more detailed inline comments for people wondering about this option?

@kendrick-k
Copy link
Contributor Author

yes sure :

Capistrano is great for deploying web applications. But the “current” symlink construction causes issues with PHP-FPM and OPcache enabled. PHP-FPM will display old pages after deployment or PHP-FPM just hangs. The hanging / freeze will result in your browser loading for minutes but you will just see a white screen.

To fix this, use $realpath_root instead of $document_root and set the SCRIPT_FILENAME in Nginx to pass to PHP-FPM.

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
This will pass the actual path “releases/20150208145800″ to PHP-FPM instead of “current” that is switched to the new release directory. OPcache can’t detect this switch so it has to work with a real path. Read more about that at: zendtech/ZendOptimizerPlus#126.

from : http://pietervogelaar.nl/php-fpm-opcache-nginx-capistrano-stable-deploy

@kendrick-k
Copy link
Contributor Author

( this issue is painful when you don't know it... )

# symlink issue with PHP-FPM and OPcache. Symlink may not be refreshed, so it's necessary to use a real path (eg. after a deployment with Capifony which uses the current symlink to point towards a release directory, you may notice that PHP-FPM displays old pages or freezes) :
@kendrick-k
Copy link
Contributor Author

Hi @xabbuh is the comment fine for you ? Best

@@ -269,6 +269,8 @@ The **minimum configuration** to get your application running under Nginx is:
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
# symlink issue with PHP-FPM and OPcache. Symlink may not be refreshed, so it's necessary to use a real path (eg. after a deployment with Capifony which uses the current symlink to point towards a release directory, you may notice that PHP-FPM displays old pages or freezes) :
fastcgi_param DOCUMENT_ROOT $realpath_root;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand the issue correctly, I would propose to change this to something like this:

            # When you are using symlinks to link the document root to the
            # current version of your application, you should pass the real
            # application path instead of the path to the symlink to PHP
            # FPM.
            # Otherwise, PHP's OPcache may not properly detect changes to
            # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
            # for more information).
            # fastcgi_param  SCRIPT_FILENAME  $realpath_root$fastcgi_script_name;
            # fastcgi_param  DOCUMENT_ROOT    $realpath_root;

But: Where is this $realpath_root variable configured? Is that something that is predefined by Nginx?

@xabbuh
Copy link
Member

xabbuh commented Oct 7, 2015

@kendrick-k I left you a comment. Can you please check if I understood everything correctly and what you think about my suggestion? Thank you!

@kendrick-k
Copy link
Contributor Author

Hi yes it's nice ! http://nginx.org/en/docs/http/ngx_http_core_module.html : "ngx_http_core_module module supports embedded variables => $realpath_root
an absolute pathname corresponding to the root or alias directive’s value for the current request, with all symbolic links resolved to real paths"

@xabbuh
Copy link
Member

xabbuh commented Oct 8, 2015

Could you then please update the pull request accordingly?

@kendrick-k
Copy link
Contributor Author

Hello @xabbuh it's ok now :) ?

@xabbuh
Copy link
Member

xabbuh commented Oct 9, 2015

@kendrick-k I think it's great now. :) Thank you for your work on this.

@kendrick-k
Copy link
Contributor Author

cool, thank you too !

@kendrick-k kendrick-k closed this Oct 9, 2015
@xabbuh
Copy link
Member

xabbuh commented Oct 9, 2015

Sorry, I have to reopen. :) The PR is not merged yet as I wait for another 👍 from one of the other team members. :)

@xabbuh xabbuh reopened this Oct 9, 2015
@jakzal
Copy link
Contributor

jakzal commented Oct 9, 2015

I was just hit by this :) 👍

@kendrick-k
Copy link
Contributor Author

@xabbuh hi, it will be integrated within a few days ?

@weaverryan
Copy link
Member

Thanks very much @kendrick-k!

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

Successfully merging this pull request may close these issues.

4 participants