1

Caveat: I know nothing about PHP (I use Python3 and C#), and I have only ever used Apache.

TL;DR

I can't figure out why this PHP code refuses to write to a bloody file and why reloading nginx/php7.0-fpm will not reflect the changes made to the file.

Background

I have been "gifted" an in-house program that was written in PHP7 and runs on Nginx, Ubuntu 16.04.4 (terminal only). This program does not have a web UI, and only exists to handle HTTP GET and PUT requests. Said program is not running as expected and I'm trying to debug why. However, it appears that any changes I make to the PHP code do not get reflected in the behavior.

Basically I want to set up some kind of logging - write to nginx logs, write to a file, send an email, anything - so that I can find out where things are failing. Then I can report things properly to the people who know instead of just saying "Program no work. You fix."

Details

  • The server runs from a git checkout in /var/www/servername.
  • Requirements are: nginx, nginx-extras (for ngx_http_dav_module), php7.0, php7.0-sqlite3
  • My php upstream is: upstream php { server unix:/run/php/php70-fpm.sock; }

nginx config:

server {
        server_name 192.168.11.80;
        root /var/www/servername/public/;

        rewrite ^/$ /index.php;
        rewrite ^/\$metadata$ /metadata.xml;
        rewrite ^/Search\(\)/\$count$ /count.php;
        rewrite ^/Search\(\)$ /search.php;
        rewrite ^/Packages\(\)$ /search.php;
        rewrite ^/Packages\(Id='([^']+)',Version='([^']+)'\)$ /findByID.php?id=$1&version=$2;
        rewrite ^/GetUpdates\(\)$ /updates.php;
        rewrite ^/FindPackagesById\(\)$ /findByID.php;

        rewrite ^//?download/([^/]+)/([^/]+)$ /download.php?id=$1&version=$2;
        rewrite ^/([^/]+)/([^/]+)$ /delete.php?id=$1&version=$2;


        rewrite ^/api/v2/package/$ /index.php;
        rewrite ^/api/v2/package/([^/]+)/([^/]+)$ /delete.php?id=$1&version=$2;

        location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass php;
        }

        location = /index.php {
                dav_methods PUT DELETE;
                include fastcgi_params;
                fastcgi_pass php;

                # PHP doesn't parse request body for PUT requests, so fake a POST.
                fastcgi_param REQUEST_METHOD POST;
                fastcgi_param HTTP_X_METHOD_OVERRIDE $request_method;
        }

        # Used with X-Accel-Redirect
        location /packagefiles {
                internal;
                root /var/www/servername/;
        }
}

What I've tried

I've tried all of the below items, none of which seemed to have any effect.

  • Writing directly to a file using file_put_contents. For some reason, this just doesn't work.
    • file_put_contents('php://stderr', 'TESTING'); does not append anything to the nginx log files /var/log/nginx/[access|error].log
    • file_put_contents('/var/log/sns/debug.log, 'TESTING'); also does not write to the debug.log file
      • the /var/log/sns folder has 777 permissions.
      • the file has 0666 permissions.
  • Forcing the program to abort via die().
  • Editing the php-fpm pool config to catch workers output. Still seems to not do anything.
  • Some suggest I might not be restarting PHP-FPM correctly. I use this command sudo service php7.0-fpm restart & sudo service nginx restart based off this answer.
  • Checked the other expected log places.
    • /var/log/php7.0-fpm.log only has the startup/shutdown notices ("fpm is running", "read to handle connections", "terminating", etc.)
    • /var/log/nginx/access.log correctly shows all the GET and PUT requests, but nothing else
    • /var/log/nginx/error.log only shows the "Using xKiB of shared memory" (the startup info).
  • Deleting index.php and then restarting nginx & php7.0-fpm - somehow the program still works!
  • Making a change to the PHP code (error_log('msg', 3 '/var/log/sns/debug.log'), file_put_contents(...), and die() and then completely rebooting the server. Still doesn't write to a file.

So what extremely basic thing am I missing?

6
  • You might need to set open_file_cache off; in your nginx config while you debug. (Don't leave it permanently though.) Commented Apr 19, 2018 at 20:03
  • @AlexHowansky so would that just be a new line in the server block or would I put that somewhere specific in /etc/nginx/nginx.conf?
    – dthor
    Commented Apr 19, 2018 at 20:11
  • Yeah, in the server block. (For this case.) Commented Apr 19, 2018 at 20:13
  • @me according to the docs I can put it in the server context :-)
    – dthor
    Commented Apr 19, 2018 at 20:14
  • Ah, you're just a bit faster than me reading documentation!
    – dthor
    Commented Apr 19, 2018 at 20:14

1 Answer 1

0

start the nginx in debug mode.

servie nginx-debug start.

1
  • 1
    Please add some explanation to your answer such that others can learn from it. How does running that debug mode help to write a file?
    – Nico Haase
    Commented Apr 21, 2020 at 6:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.