We have different clients, each has his own servers in his own data center and each have a slightly different version of our Rest api.

The servers are either centos 6 or centos 7, running either php5.x or php7.x. Our rest API isn't written using a framework. The servers aren't connected to the internet. Remote connection to MySQL is disabled.

We connect to the servers using a Vpn, we test using postman, we use either var_dump or we debug by writing to files.

Is there any better way to debug?

    If by "debug" you mean "find out what happened when something went wrong on my production servers" then that sounds tricky. I have found that writing log files can be extremely helpful. Minimally all you need is a function like this

    function log($mesg) {
      file_put_contents("/path/to/file.log", date("Y-m-d H:i:s") . " - " . $mesg, FILE_APPEND);
    }

    You would replace /path/to/file.log with your actual log file and you'd need to make sure that your PHP scripts had permission to write this file, of course. On most machines I've dealt with, this involves making sure that the web server user (typically apache or apache2 or possibly httpd on CentOS machines I think) has permission to write this file. You'll also need to consider configuring logrotate or something similar to make sure the file doesn't get too big.

    But if you are developing code, the best way by far is to run it on your workstation locally, either on the machine itself or as a virtual machine using something like VMWare if you need to mimic other server setups. My workstation runs linux and I just run apache/php locally. Most of the sites I maintain run in the cloud so I can usually replicate the production server at some other subdomain and test the code there first.

    If by "debug" you mean you want to step thru the code using your IDE, I've never managed to get that working remotely, and only locally for short bursts before some update breaks everything.

      Write a Reply...