PHP / uhttpd

Hello,

after I searched for hours for a solution, I now turn directly to the forum.

I try using the Arduino Yun to build a PHP webserver.

As described in Yun-Playground, I have installed PHP using SSH.
As I found out now, I have to change the uhttpd-file, that the Yun recognizes the ".php" files.

But how should this be done?
How can I get access to this file, and what do I need to change?
Do I need to make further changes so that my PHP server works?

Sorry for my bad english, I'm from Austria.

Thanks in advance.
waelder

A minimal php5 installation includes php5, php5-cgi.

opkg update
opkg install php5 php5-cgi
opkg install nano
nano /etc/config/uhttpd

Ensure that you uncomment the extension interpreter line for PHP in the main section of the uHTTPd config file:

list interpreter ".php=/usr/bin/php-cgi"
/etc/init.d/uhttpd restart
nano /www/phpinfo.php
<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>

Using browser http://arduinoip_address/phpinfo.php to confirm php is installed.

http://wiki.openwrt.org/doc/uci/uhttpd

Worked wonderful :slight_smile:
Thank you so much.

Now I have another question.
If i access my Yun via the IP, the Configuration Page is loaded. Is there an possibility to change this value, so that my Yun forward me to the sd dictionary and not to the configuration page?

uhttpd forward page to phpinfo.php:

cp /www/index.html /www/index.html.bk
nano /www/index.html

change following string

url=/cgi-bin/luci/webpanel/homepage => url=/phpinfo.php

href="/cgi-bin/luci/webpanel/homepage" => href="/phpinfo.php"

/etc/init.d/uhttpd restart

clear browser cache (at Firefox Clear All History), reload page.

The phpinfo has following error:

Warning: phpinfo(): It is not safe to rely on the system's timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /www/phpinfo.php on line 4

The fix:

opkg update
opkg install zoneinfo-core
opkg install zoneinfo-europe

http://playground.arduino.cc/Hardware/Yun#get_time_work_php

Sorry for the ress.... But when I use:

nano /etc/config/uhttpd

I get:

Error opening terminal: cygwin.

I'm using git bash on windows 7.

What can I do now?

Windows: PuTTY is a third-party application that acts as a terminal emulator that supports SSH (see below for details).

http://www.arduino.cc/en/Tutorial/LinuxCLI

Use PuTTY :

http://internal.math.arizona.edu/services/computing/remote-access/shell/putty

Thanks, that solved it. But after following your instructions I still get:

404: Not Found!
MIME-TYPE not known

When accessing from the browser (both chrome and firefox) :confused:

EDIT: I should probably give a quick explanation of what I'm trying to do... I'm using mjpg-streamer to start streaming on boot on port 8081. I can access it outside the local network but so can everyone with internet. To make it more secure I made a .html life to input login credentials and a .php file to check those credentials and allow or deny access to the stream. Something like:

if(($_POST['username'] == "username") && ($_POST['password'] == "password"))
<img src="/?action=stream" />

But can't seem to get the Yun to recognise the .php file...

Hasr:
...
EDIT: I should probably give a quick explanation of what I'm trying to do... I'm using mjpg-streamer to start streaming on boot on port 8081. I can access it outside the local network but so can everyone with internet. ...

Smart move!

Setup mjpg-streamer with password authentication for Yun:

http://forum.arduino.cc/index.php?topic=308745.msg2143894#msg2143894

Followed your instructions on that thread but the stream.html isnt asking me for a password when I access it internally or externally network-wise. Do I need to change anything else?
Didn't know if I should reply here or in the other thread xD

Oh and for curiosity sake, what can I be missing to get the .php files working? Never know when I might need to make it work :stuck_out_tongue:
EDIT: Ok, the phpinfo.php file is working fine! But the /www/webcam/test.php file isn't... Any idea why? I'm confused with this.
2EDIT: The test.php file works fine in the /www/ folder. Problem is, I can't (more like I don't know) how to make the stream wacthable in that folder... In /www/webcam/ folder I can watch the stream but in the /www/ folder I can't. Any way to work around this?
Tried this but no luck:

config mjpg-streamer core
        option enabled          "1"
        option device           "/dev/video0"
        option resolution       "640x480"
        option fps              "15"
        option www              "/www/webcam"
        option port             "8081"

Thanks for all the help :smiley:

No need uhttpd web server and php, use mjpg-streamer with build in web server and password authentication will do the trick.

http://arduino.local:8081/ will ask password.

Yeah, it works :slight_smile: Thanks for the help. I'm using usernam and password with the mjpg-streamer :stuck_out_tongue:

I'm having trouble with sonnyyu's instructions. Using PuTTY, PHP seems to install just fine and that line previously mentioned is already commented out as it should be. However "phpinfo.php" does not exist in that directory. I followed all the instructions, so I'm confused why the file isn't there. Obviously, I can't navigate to it with the browser either. I've played around with this for a while. Any suggestions on what I might be doing wrong or on how to get feedback as to what is going on?

sonnyyu:

nano /www/phpinfo.php

....

Using browser http://arduinoip_address/phpinfo.php to confirm php is installed.

echo "<?php phpinfo(); ?>" > /www/phpinfo.php

sonnyyu:

echo "<?php phpinfo(); ?>" > /www/phpinfo.php

I'm sorry, my email stopped updating me with replies for some reason.

Where is this snippet supposed to go?

The "phpinfo.php" file isn't in the /www directory.

Can I just create that file with the snippet you gave me in that directory?

I tried adding the phpinfo.php file in the /www directory with the code you posted 3 different ways (although, I'm probably misunderstanding what you were telling me to do).

echo "<?php phpinfo(); ?>" > /www/phpinfo.php
echo "<?php phpinfo(); ?>" >
<?php phpinfo(); ?>

xcfreek58:
I tried adding the phpinfo.php file in the /www directory with the code you posted 3 different ways (although, I'm probably misunderstanding what you were telling me to do).

echo "<?php phpinfo(); ?>" > /www/phpinfo.php

This is a command you enter at the Linux command line. It echos the string "<?php phpinfo(); ?>" to the file /www/phpinfo.php, essentially creating that file named phpinfo.php in the /www folder, with a PHP script that calls phpinfo(). This is the easiest way to create a simple file without needing an editor application.

echo "<?php phpinfo(); ?>" >

What do expect this to do? I can't make sense of it in any context.

<?php phpinfo(); ?>

This is the actual PHP code to call the phpinfo() function. This is what you would enter into /www/phpinfo.php, if you were to create/edit the file directly using a text editor application. This command is only useful as the contents of a PHP file, it has no meaning if you type it at the Linux command prompt.

ShapeShifter:
This is a command you enter at the Linux command line. It echos the string "<?php phpinfo(); ?>" to the file /www/phpinfo.php, essentially creating that file named phpinfo.php in the /www folder, with a PHP script that calls phpinfo(). This is the easiest way to create a simple file without needing an editor application.

So I used this command at the Linux command line (via Putty) to create that file in that directory. I also ran all the php install commands again just to ensure that PHP was installed

opkg update
opkg install php5 php5-cgi
opkg install nano

It told me:

Package php5 (5.4.5-3) installed in root is up to date.
Package php5-cgi (5.4.5-3) installed in root is up to date.
Package nano (2.2.6-1) installed in root is up to date.

So I would think that I could create an HTML file like this one and it would display the line that is being echoed in the PHP:

<!doctype html>
<html>
	<head>
	</head>
	<body>
		<h1>My First PHP Page</h1>
		<?php 
			echo "xcfreek58 is awesome with PHP";
		?>
	</body>
</html>

I would expect "xcfreek58 is awesome with PHP" to show up below "My First PHP Page", but it doesn't. For some reason only "My First PHP Page" is there.

What am I missing?

sonnyyu:
A minimal php5 installation includes php5, php5-cgi.

opkg update

opkg install php5 php5-cgi
opkg install nano






nano /etc/config/uhttpd




Ensure that you uncomment the extension interpreter line for PHP in the main section of the uHTTPd config file:



list interpreter ".php=/usr/bin/php-cgi"






/etc/init.d/uhttpd restart






nano /www/phpinfo.php






<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>




Using browser http://arduinoip_address/phpinfo.php to confirm php is installed.

http://wiki.openwrt.org/doc/uci/uhttpd

xcfreek58:
What am I missing?

I don't know, it works for me.

What did you name the file? You call it an HTML file, not a PHP file. If you have the extension .html or .htm, then the web server will serve it up like a static html file. The PHP code will be sent through the the web browser, which won't understand it, and will simply ignore it.

If you have the extension .php on the file, then the web server on the Yun knows it's a PHP file that needs to be processed before serving up the file. It will be sent through the PHP processor, which will recognize the PHP code in the file, and perform the code, substituting any output for the PHP code. The page served up to the web browser will actually have the entire block of PHP code removed, and it will appear as if the "awesome" text was always in the file.

If your HTML file has any extension other than .php, that is your problem. If it has a .php extension, then you probably have a configuration problem. You say you created the phpinfo.php file, but you don't say what happened when you ran it? If it didn't work, don't bother trying anything else until it does. If it did work, and your HTML file has a .php extension, then you have a strange situation...

ShapeShifter:
I don't know, it works for me.

What did you name the file? You call it an HTML file, not a PHP file. If you have the extension .html or .htm, then the web server will serve it up like a static html file. The PHP code will be sent through the the web browser, which won't understand it, and will simply ignore it.

If you have the extension .php on the file, then the web server on the Yun knows it's a PHP file that needs to be processed before serving up the file. It will be sent through the PHP processor, which will recognize the PHP code in the file, and perform the code, substituting any output for the PHP code. The page served up to the web browser will actually have the entire block of PHP code removed, and it will appear as if the "awesome" text was always in the file.

If your HTML file has any extension other than .php, that is your problem. If it has a .php extension, then you probably have a configuration problem. You say you created the phpinfo.php file, but you don't say what happened when you ran it? If it didn't work, don't bother trying anything else until it does. If it did work, and your HTML file has a .php extension, then you have a strange situation...

I did have it named as index.html, but it doesn't work when I name it index.php because whenever I load the file, it is automatically downloaded by my browser to my Downloads folder and not rendered. Does that mean that I don't have PHP installed correctly? I believe that I followed all the steps above that sonnyyu reposted.

I'm using an SD card in my Yun. Could that make any difference as to whether the PHP processor will process the file?