PDA

View Full Version : coding php on knoppix



mrobertson
06-02-2005, 03:59 PM
I am having trouble coding php on the knoppix live cd distro. I tried to wirte a simple php server progrm and got an error in the first line......(ie <?) saying no such file or directory. Is there some type of set up procedure that need to be done before programming php. Where do you program the php.....console? I have tried to follow some online instructions but I keep getting the error root permmissions denied...what does this mean and how do I fix it?

maxIT
06-02-2005, 07:27 PM
This would be the right way to code php:
-open root terminal and type apache to run apache
-cd in /var/www and put in it your file.php
-open web browser and adress to http://127.0.0.1/file.php

have fun and let me know 8)

markpreston
06-02-2005, 07:49 PM
http://www.knoppix.net/forum/viewtopic.php?t=18105&highlight=

http://www.knoppix.net/forum/viewtopic.php?t=18851&highlight=

http://www.knoppix.net/forum/viewtopic.php?t=16303&highlight=

http://www.knoppix.net/forum/viewtopic.php?t=16375&highlight=

Are a few links that should help you out.
Regards,
Mark

mrobertson
06-03-2005, 02:15 PM
I got appache running an got into the www directory. How do I put my .php file into that directory. Also, I dont have internet access on the pc that I am running knoppix. How can I run my code from the console? Would I be able to address from another pc using the ip address of the computer running knoppix instead of using 127.0.0.1? Also what do I need to add to the beginning of my code. #!/usr/bin/php, #!/bin/bash, etc.......What is the syntax that needs to be added to the code?

mrobertson
06-03-2005, 02:17 PM
Also, do I have to be logged in as root....if so how exaclty do I do this?

maxIT
06-03-2005, 05:49 PM
Once in /var/www with a simple text editor create this test file test.php:
<?php
phpinfo();
?>

Then open an your choice browser and adress to: http://127.0.0.1/test.php
You would see a long list of php parameters.
127.0.0.1 is a a conventional standardized localhost ip address to referr to your current working machine and no to other networked machines (seems to me).

>Also what do I need to add to the beginning of my code. #!/usr/bin/php, #!/bin/bash, etc.......What is the syntax that needs to be added to the code?
Do you have this kind of dubts? It's look like you need a good online simple php tutorial, I will suggest this one to you:
http://www.w3schools.com/php/default.asp

bye, max

mrobertson
06-03-2005, 06:16 PM
I used the following command:

$ sudo cat > /var/www/PHPServer1.php
<?php phpinfo(); ?>

$ lynx http://127.0.0.1/PHPServer1.php
and got the following errors:

Warning: Unknown (/UNIOFS/var/www/PHPServer1.php):failed to open stream. Permission denied in unknown line 0

Warning: (null)(): Failed opening '/UNIOFS/var/www/PHPServer1.php' for inclusion (include_path = '.:/usr/share/php : /usr/share/peak) in unknown on line 0

I do not have internet access on the computer that I am running linux on. Do I need to get that? Is it possible to access it from a computer with internet access. Also here is the code that I am using in the mean time:

<?
while (1);
//Attempt to read string from socket
//For now let's pretend it's been read successfully
//and is called "stuff"
$stuff = "1,2.2,3.245,.546";

if ($stuff != "") {
$array_of_stuff = explode(',', $stuff); //Now it's an array
//Display them:
print ($array_of_stuff[0]);
print ($array_of_stuff[1]);
print ($array_of_stuff[2]);
print ($array_of_stuff[3]);
$stuff = "";
}
?>


As you can see I just defined a fixed string. What do I need to change in my code so that it accepts the dynamically changing string passed from my client as opposed to this "dummy" string that I have made up?

markpreston
06-03-2005, 10:30 PM
Also, do I have to be logged in as root....if so how exaclty do I do this?

To do this as the default user knoppix open a knoppix terminal window (console). This should give you
knoppix@tty0[knoppix]#
Then type
su followed by [enter]
There is no password required.
The terminal should change to
root@tty0[knoppix]#
You are now logged in as root and can issue commands and run programs as root.

I find writing php code in a text editor works for me.
At the root prompt type
nedit followed by [enter]
Then, as previously suggested write

<?php phpinfo(); ?>
and save the file in the /var/www directory as suggested by MaxIT.
Then visit the file with a browser as he also suggests.
Once this works you can then test out perl and bash scripts.
Use whatever text editor you prefer out of those available (nedit, kate, kwrite, emacs and vim).
Create a file as root with the following.


#!/bin/bash

printf "Content-type:text/html\r\n\r\n";
printf "<html>hello world</html>\r\n";

This bash script should be saved as hello.cgi and saved in the /usr/lib/cgi-bin directory.
It also needs to be made executable for all users:
At the root prompt type
chmod 755 /usr/lib/cgi-bin/hello.cgi
Then visit the file with a browser e.g. mozilla
http://127.0.0.1/cgi-bin/hello.cgi

Once this works you can do the same for perl. This time saving the file as hello.pl
and using the following code:

#!/usr/bin/perl

print "Content-type:text/html\n\n";
print "<html>hello world</html>\n";

Once you have got these three programs going then you have a wide choice to start open source web programming under Knoppix Debian/Gnu/Linux.
Regards,
Mark

maxIT
06-04-2005, 11:02 AM
>Warning: Unknown (/UNIOFS/var/www/PHPServer1.php):failed to open stream. Permission denied in unknown line 0

>Warning: (null)(): Failed opening '/UNIOFS/var/www/PHPServer1.php' for inclusion (include_path = '.:/usr/share/php : /usr/share/peak) in unknown on line 0

This would be appen maybe because of the default permission assigned to new created file only read/write (not execute), so give your file full permissions in this way : chmod 777 PHPServer1.php

bye, max