I am new in ubuntu. So i am facing some problem with terminal command.So please help me. can i execute my php code in my terminal not my browser as like using localhost?
-
no i think this is not like that answer. we r using localhost to view php output in browser but i want to see my output in terminal. – Arman H Mar 14 '17 at 12:41
-
1http://askubuntu.com/q/207265/158442 then, since you just want to open a URL – muru Mar 14 '17 at 12:50
-
its not downloading from a website. please try to understand – Arman H Mar 14 '17 at 13:51
1 Answers
It is hard to understand the question because the final output of PHP web sites is HTML code, which can be interpreted from the web browser but can't be interpreted from the terminal itself. This article sheds more light on this subject.
Let's assume we have pretty simple PHP program, called test.php
, which looks like that:
$ cat /var/www/html/test.php
<?php
print "\n";
echo "<h1>Hello World!</h1>";
print "\n";
$a = '5';
$b = '10';
echo "<code>The result is: " . $c = $b / $a . "</code>";
print "\n";
print "\n"; # we need these lines to align the output into the terminal
?>
We can display the output of this code in several ways:
When we open this program in the web browser - as a web page - the result will looks like:
The actual result of our PHP program - page's source code is:
If test.php is executed as PHP program into the terminal, then we will get identical result -
php test.php
:If we want to execute the same program into the terminal through the web interface we can use
curl
in this way -curl http://mysite.dev/test.php
:Or we can use
wget
in this way -wget -O - -q http://mysite.dev/test.php
:If we want to see the result of the interpretation of the HTML code into the terminal, we must use some text-based web browser like as Lynx -
lynx http://mysite.dev/test.php
:

- 29,831
-
thank you so much. i got it. this is what i actually want to know. @spas Spasov – Arman H Mar 17 '17 at 11:19
-
yes grant it. thanks a lot.can you please tell me if i do a big project which output will show in terminal like this. is it better way for me? – Arman H Mar 17 '17 at 11:26
-
@Arman I think there is no difference between these three approaches (php/curl/wget). But, I'm not sure how much readable will be the output of big project into a terminal. You can make
test.php
which contains<?php phpinfo(); ?>
and "curl" it to see the result. – pa4080 Mar 17 '17 at 11:37