Where is the PHP executable on Ubuntu?

10

4

I have installed Apache and PHP. I know PHP works as I have tested a simple PHP file on an Apache server.

I'm writing a simple webserver which should be able to process PHP files. So once I get a request for a PHP file, I want to do something like 'exec php test.php' and get the output and pass it to the client.

As I'm not much into Ubuntu, I don't know where the PHP executable is (should be in \bin right?) to do it. But there is no PHP file inside \bin or \usr\bin.

When I run 'which php' it shows nothing. How do I do this?

samsamara

Posted 2012-11-03T08:06:51.930

Reputation: 325

1What happened is most likely that you got php in apache as php module (technically - a library not an executable binary that gets called externally), that's why you couldn't find the binary. This comment is meant to complete the answer, which tells you what needs to be done to get the php binary in your system but doesn't provide any reasons why it was missing. – AnonymousLurker – 2012-11-03T09:32:05.967

If you are really running Ubuntu 8.10 like your tags suggest, you should understand Ubuntu 8.10 is extremely out of date. You really should upgrade ASAP. There is no security support for that release. – Zoredache – 2012-11-03T09:49:08.460

@Zoredache yeah I know it's very old. But I'm not a Ubuntu user. I had the CD and I installed it, just for my assignment! :D – samsamara – 2012-11-03T11:16:38.603

Answers

10

You need to install the php5-cli or php5-cgi package.

sudo apt-get install php5-cli
# OR
sudo apt-get install php5-cgi

As Zoredache noted in the comment. cli version doesn't process headers nor dos output them - it's sort of clean PHP interpreter completely unaware of HTTP.

If you want version capable of above mentioned, use the CGI version.

Kamil Šrot

Posted 2012-11-03T08:06:51.930

Reputation: 281

1ok, installed, still question: where is the executable? – Andrew – 2017-04-26T19:10:50.857

1yeah I just learned I need php-cli..:) – samsamara – 2012-11-03T08:20:25.433

1Since he is writing a web server, he probably doesn't want the CLI version since that isn't going to be able to get the GET/POST data. – Zoredache – 2012-11-03T09:50:04.450

11

I found the executables in /usr/bin/

eg:

  • /usr/bin/php
  • /usr/bin/php7.0
  • /usr/bin/php7.1

Andrew

Posted 2012-11-03T08:06:51.930

Reputation: 322

11

Type the following in your terminal

whereis php

Robert Sinclair

Posted 2012-11-03T08:06:51.930

Reputation: 210

I got this php: /usr/bin/php7.1 /usr/bin/php7.0 /usr/bin/php /usr/bin/php7.2 /usr/lib/php /etc/php /usr/include/php /usr/share/php7.1-opcache /usr/share/php7.2-zip /usr/share/php7.0-intl /usr/share/php7.1-common /usr/share/php7.0-gd /usr/share/php7.2-common /usr/share/php7.1-gd /usr/share/php7.1-xmlrpc /usr/share/php7.2-intl /usr/share/php7.2-mysql – abu abu – 2020-01-12T10:37:43.423

1

If you are writing your own web server you almost certainly want to install or build the CGI version of the PHP binary, and you will want to implement the CGI protocol in your web server. The CGI version has the required facilities to capture the GET/POST data.

See:

Zoredache

Posted 2012-11-03T08:06:51.930

Reputation: 18 453

I'm writing a simple web server with PHP and CGI support. For parsing php files, what I'm gonna do is 'exec /usr/bin/php file.php'. And you can run CGI scripts by parsing them to perl. Am I right? feasible? – samsamara – 2012-11-03T11:41:35.373

1Uhm, no CGI hasnothing to do with perl. You really should read at least the wikipedia article. – Zoredache – 2012-11-03T20:16:56.523