LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-06-2011, 07:24 PM   #1
casperdaghost
Member
 
Registered: Aug 2009
Posts: 349

Rep: Reputation: 16
Installing php - running php scripts.


I wrote this php script, and chmod +x the script.

[CODE]
more php_script
<?php
print_r (phpinfo());
?>
[\CODE]

I get these errors
[CODE]
./php_script
./php_script: line 1: ?php: No such file or directory
./php_script: line 2: syntax error near unexpected token `phpinfo'
./php_script: line 2: `print_r (phpinfo());'
[\CODE]

when I try to the the version of php that i am running, I get this

<?php phpinfo() ?>
bash: syntax error near unexpected token `('



really do not know how to get started with php.
 
Old 11-07-2011, 12:03 AM   #2
nidhinmd
Member
 
Registered: Aug 2007
Location: Cochin, Kerala, India
Posts: 32

Rep: Reputation: 3
Hi
For phpinfo page just give below code and check
<?php phpinfo(); ?>

Last edited by nidhinmd; 11-07-2011 at 12:08 AM.
 
Old 11-07-2011, 03:01 AM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 15,738

Rep: Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753Reputation: 1753
There are two methods to running scripts from the command line whether its bash, perl, php etc. You need to either specify the required interpreter via the first line (shebang) or by running it directly:

user@computer$ php my_php_script.php

Add this as first line
#!/usr/bin/php
<?php
...
?>
to run directly
user@computer$ ./my_php_script.php

In the second case the file must have execute permissions set.

FYI php5-cli must be installed before you can run scripts from the command line. To run php from the webserver requires the proper apache modules and well as setting up the conf files. Ubuntu package manager makes this easy.

Last edited by michaelk; 11-07-2011 at 03:02 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Running PHP scripts on CLI ksushants Linux - Newbie 4 10-22-2011 03:10 AM
Use PHP to read cron launched php scripts? wh33t Programming 2 04-22-2011 06:32 PM
running test scripts with php PhilTR Linux - Server 11 09-12-2006 01:13 PM
Running PHP Scripts in SuSe Linux 9.3 w/o a server. elliotfuller Linux - Software 3 06-18-2005 06:27 PM
Apache not running php scripts Seventh Linux - Newbie 3 01-08-2004 08:35 PM


All times are GMT -5. The time now is 09:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration