roots / bedrock

WordPress boilerplate with Composer, easier configuration, and an improved folder structure
https://roots.io/bedrock/
MIT License
6.18k stars 1.17k forks source link

Service php5-fpm restart #134

Closed rstormsf closed 9 years ago

rstormsf commented 9 years ago

Whenever I do deploy, I have to manually log into the box and sudo service php5-fpm restart in order to pick up latest changes.

if I add in deploy.rb

namespace :deploy do
  desc 'Restart application'
  task :restart do
    on roles(:app), in: :sequence, wait: 10 do
      # Your restart mechanism here, for example:
      execute :service, :nginx, :reload
      execute "service php5-fpm restart"
    end
  end
end

it generates an error

SSHKit::Runner::ExecuteError: Exception while executing on host HOSTING.com: service php5-fpm restart exit status: 1 service php5-fpm restart stdout: Nothing written service php5-fpm restart stderr: stop: Rejected send message, 1 matched rules; type="method_call", sender=":1.120" (uid=1001 pid=18060 comm="stop php5-fpm ") interface="com.ubuntu.Upstart0_6.Job" member="Stop" error name="(unset)" requested_reply="0" destination="com.ubuntu.Upstart" (uid=0 pid=1 comm="/sbin/init ")

can anybody point me to the right direction how to automate it and solve it? should I hack my deploy user to allow him do sudo paswordless service management? because nginx reload works fine

etcook commented 9 years ago

@rstormsf It doesn't look like you're running it as a privileged user. Just as you do it yourself on the server, you need to run "sudo service php5-fpm restart".

francescolaffi commented 9 years ago

Unless you are using capistrano for provisioning (i.e. changing nginx and php conf) there should be no need for it.

There is a common gotcha with php5, opcache and atomic deploy based on symlink, so I'm gonna trow a guess that this is your problem or similar enough:
php5 opcache doesnt resolve symlinks for file paths (APC and others did), so when you deploy a new version opcache still see the same path (/srv/www/mysite/current/web/myfile.php) so it still serve the old cached file.
The best fix is to make the webserver pass the realpath to php, if you are using nginx is easy, just add this in the location that passes the request to php:

fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;

otherwise for apache there should be some module or you need to call on php opcache_reset();, but it should be run within a web request because cli has a different cache than the php-fpm pool

further readings:

let me know if this solve the problem, as its probably a good idea to add it to the readme

rstormsf commented 9 years ago

I used bedrock-ansible to provision my DO instance. https://github.com/roots/bedrock-ansible/tree/master/roles/php/defaults sooo what should I change and run that role again against my instance

mAAdhaTTah commented 9 years ago

Related: https://github.com/roots/bedrock-ansible/issues/61

francescolaffi commented 9 years ago

Im stuck with chef, so I cant really say on ansible, but the role file you linked its about php conf and what I proposed to change is on an nginx conf, I would guess there is a template somewhere for the nginx sites conf

austinpray commented 9 years ago

Hey @francescolaffi

It looks like we are already passing the SCRIPT_FILENAME over here: https://github.com/roots/bedrock-ansible/blob/master/roles/nginx/templates/wordpress.conf.j2

So perhaps adding DOCUMENT_ROOT will bypass the need for restarting php5-fpm?

francescolaffi commented 9 years ago

@austinpray yep, but you also have to change SCRIPT_FILENAME, the change is $realpath_root vs $document_root

this way nginx pass to php the paths with symlink resolved and opcache understand that the files are different on deploys

austinpray commented 9 years ago

Cool, I'll try this out!

swalkinshaw commented 9 years ago

See https://github.com/roots/bedrock-ansible/issues/125. This isn't a Bedrock issue anyway.

rstormsf commented 9 years ago

Cool! Thanks for doing it!

rstormsf commented 9 years ago

@francescolaffi Do you mind me to point to some online material, so I could understand what was happening and how you figured it out the fix. Would really love to understand details

swalkinshaw commented 9 years ago

@rstormsf see https://github.com/zendtech/ZendOptimizerPlus/issues/126#issuecomment-24020445

rstormsf commented 9 years ago

Great, @swalkinshaw thank you

teohhanhui commented 9 years ago

Unfortunately I still have to manually restart nginx and php5-fpm (I'm not sure which is causing the issue) after each deploy. Otherwise I get some weird HTTP 502 Bad Gateway errors from nginx (on wp-admin) and my manual code changes on the server (e.g. test editing plugin code) are just giving me plain odd behaviour.

I also used bedrock-ansible for provisioning...

swalkinshaw commented 9 years ago

@teohhanhui would be nice if you could try and isolate which one is needed. Maybe create an issue at the bedrock-ansible project?