0

I have written a simple mock API in apache (httpd, CentOS 7) web server using php. test.php which is located in /var/www/html is as below.

<?php
       $age = '{"Peter":"Good", "Ben":37, "Joe":43}';
       header('Content-Type: application/json');
        sleep(5);
        echo $age;
?>

When I call the API (http://<server_IP>:80/test.php) in postman, it returns the exact same php code back.

When I run the php code on the server using php test.php, it gets compiled correctly and returns expected output.

{"Peter":"Good", "Ben":37, "Joe":43}

Why don't I get this output when the API is invoked? How can I resolve this?

Pradeep Sanjeewa
  • 1,911
  • 1
  • 14
  • 25
  • Does this answer your question? [Enable PHP Apache2](https://stackoverflow.com/questions/42654694/enable-php-apache2) – Dmitry Leiko Jul 01 '20 at 12:03
  • 1
    Having the `php` command-line tool available in your shell doesn't mean that Apache will automatically parse files as PHP scripts. They're different tools with different settings and, in Linux, typically different packages as well. – Álvaro González Jul 01 '20 at 14:22
  • Then how can I come up with a simple mock API in apache? – Pradeep Sanjeewa Jul 01 '20 at 14:57

0 Answers0