Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am new to php programming and i have installed it on Ubuntu server, the server is a LAMP server. As i was doing my introductory lecture, i created first.php file but i understand it cannot be compiled and run like c or java. I would want to know what i must do to see that my program is working. The Ubuntu server that i am working on does not have GUI installed so i would want to know if i can still use it successfully.

share|improve this question

3 Answers 3

up vote 2 down vote accepted

as you mentioned you dont have a GUI you can try out CLI browsers. many browsers are there among them I always choose lynx and you can install it by using

sudo apt-get install lynx-cur

make sure that you have placed your first.php file in the proper location.

then check with your .php file.

I mean I have tested it like this

jai@frank-Jai:~$ lynx 127.0.01
Looking up  '127.0.01' first

there 127.0.0.1 indicates the local server.

then it will display output as enter image description here

for example if you have written a .php script then you execute it as

php script:

root@frank-Jai:~# cat /var/www/ho.php 
<html>
<body>

<?php
echo "My first PHP script!";
?>

</body>
</html>
root@frank-Jai:~# 

Then I am placing it in the /var/www/ directory with some name. in my case it is po.php . then you cane execute it as

lynx 127.0.0.1/ho.php

and output will be

enter image description here

hope that helps you too understand how to execute a php script.

share|improve this answer

In fairness to the other answers, PHP is most commonly hosted on a webserver and run through mod_php or php-cgi but you can also write command-line and graphical PHP scripts and applications.

sudo apt-get install php5-cli
php -f file.php

That will run and output the PHP file to the terminal. If you've got a ton of HTML in the php file or it relies on various $_SERVER variables, this just isn't going to work. Just Install lamp and work out of /var/www:

sudo apt-get install lamp-server^

(Note: The ^ is not a mistake — it's how apt-get knows to install a task)

share|improve this answer
    
It worked and i got my output in terminal, My server is already a lamp server , i would want to know how i can work out of /var/www –  sosytee Aug 9 '13 at 8:47

PHP does not need compilation.

The default site is under /var/www

Put your test file there and get access with browser http://example.com/first.php

Also if you want to test directly in console you just write

php /path/to/file.php
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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