0

I'm setting a new web server. I have NGINX with php-fpm on ubuntu 16.04. Everything works great except one thing: after 2-3 days of correct working PHP can't run any external system command. What do i mean when i say "system command"? For example when i run function shell_exec with argument 'whoami'

echo shell_exec('whoami');

i get the following

Warning: shell_exec(): Unable to execute 'whoami'

And it happens for every Linux command that php script tries to execute

When i trying to send mail using the mail() function i get a similar error

Warning: mail(): Could not execute mail delivery program '/usr/sbin/sendmail -t -i '

It happens only when i run PHP-script from browser. If i try to run it from terminal like so

sudo -u www-data php /path/to/my/script.php

then everything works OK.

Again: the problem appears only after some time of correct working and disappears(for some time) after VDS restart. It appears only when i run a script from browser, that means it served by NGINX.

Please, help me find a solution for my problem.

P.S Logs: Php errors logs

[27-Aug-2016 04:19:37 Europe/Moscow] PHP Fatal error:  Uncaught Error: Call to a member function is_logged() on null in /home/serv/www/templates/page_parts/header_tpl.php:6
Stack trace:
#0 /home/serv/www/templates/index_tpl.php(9): require()
#1 /home/serv/www/php_classes/templater_class.php(116): include('/home/serv/www/...')
#2 /home/serv/www/functions.php(827): templater->load_template()
#3 /home/serv/www/functions.php(804): error_wrong_csrf()
#4 /home/serv/www/index.php(16): csrf_check_post('1b46edd81f1563a...')
#5 {main}
  thrown in /home/serv/www/templates/page_parts/header_tpl.php on line 6
[27-Aug-2016 04:19:48 Europe/Moscow] PHP Warning:  mail(): Could not execute mail delivery program '/usr/sbin/sendmail -t -i ' in /home/serv/www/php_classes/mail_class.php on line 84
[27-Aug-2016 04:27:42 Europe/Moscow] PHP Warning:  shell_exec(): Unable to execute 'whoami' in /home/serv/www/test_mail.php on line 29

Syslog:

Aug 27 04:39:01 frankfurt CRON[30551]: (root) CMD (  [ -x /usr/lib/php/sessionclean ] && /usr/lib/php/sessionclean)
Aug 27 04:39:01 frankfurt CRON[30552]: (root) CMD (   test -x /etc/cron.daily/popularity-contest && /etc/cron.daily/popularity-contest --crond)

in php7.0-fpm.log there is nothing from today

user2265529
  • 133
  • 1
  • 5
  • What do your PHP logs say? Please post a log for the time this happens, plus say 10s before and 10s after. – Tim Aug 27 '16 at 01:34
  • I added some logs to my post. Is there a good site/service for publishing logs? – user2265529 Aug 27 '16 at 01:59
  • A very old bug report but might still be relevant, in that you might be out of file descriptors or ulimit needs raising for www-data: https://bugs.php.net/bug.php?id=25480 – jedifans Aug 27 '16 at 03:01
  • http://pastebin.com/ is good for large logs. However you should be looking at the logs and putting the relevant parts into appropriate sections in your question - ie four spaces at start of line. – Tim Aug 27 '16 at 03:53
  • jedifans, thanks you for your link to php bug report. I'm trying to increase the number of allowed open files – user2265529 Aug 27 '16 at 04:30
  • @user2265529 Let us know if it works by answering your own question :) – Ryan Babchishin Aug 27 '16 at 14:59

0 Answers0