FlightAware Discussions

How to PHP "alongside" PiAware

Sorry if this is off topic, but I was wanting to do some coding to grab and interpret data from my Pi running 3.8.0~bpo9+1 just for a bit of fun, e.g. a local web page showing the closest aircraft, height heading etc (so when you hear something going past nearby you can quickly see what it is).

I’ve done some JavaScript coding around this but I want to use a grown-up language, well, an adolescent one perhaps, in the form of PHP.

I have setup 3 Pis before and every time setting up PHP has been a total nightmare/“journey of discovery” (not helped by The Pi Foundation’s own instructions not working - 3 separate times) . I managed to get PHP working on my Pi running FlightAware, only it killed PiAware (well the User Interface, as I think it upset lighttpd and Apache had stomped on it).

I actually have PHP is installed but then I get the dreaded “forbidden” when trying to run a “Hello world” script (the same on thing every time I tried to set up PHP). I’ve changed permissions until I’m blue in the face but nothing I have seen suggested online has worked. I’m very reticent to make changes to that Pi as I don’t want to have too restore the image if I can help it.

Does anybody have any suggestions please, I’m at my wits end with Raspberry Pis - they are supposed to be a learning tool: not learning to hate what is actually a great little device.

Thanks in anticipation; if I get something working I’ll post the results online (if anybody cares for that)

1 Like

BTW. My experience is as a web developer PHP/MySQL and WordPress - hence Linux is on the edge of my knowledge and the frustration of just getting the basics done so I can get on to something my grey cells are more used to handling

I’ll watch this with interest, as that would be a useful and fun feature. It can kind of already be done using the “Auto select aircraft… closest to” option in Virtual Radar Server, for example, but that requires messing around with VRS and of course your approach is much lighter weight and has the more important learning experience and integration aspect.

I was looking to interpret the data file that the software generates and then just do something with that.(pick out the lat longs and work out distance (pick out closest) and heading from home location - bit of a hack really).

http://192.168.0.XYZ/dump1090-fa/data/aircraft.json

PHP is my language of choice; I despise Javascript. An alternative would be to use Node (JavaScript again but at least running on the server so it isn’t hamstrung by client side security) and I know I can get a Node server working on Pi readily (having built a “split flap” (departure board) display for a few people’s flight sims), and that would also be constantly updated guess - maybe I’ll address that after a PHP test of it working.

Did you get to the bottom of displaying Hello World or is it still a mystery? Your virtual split flap departure board sounds great, it would make a good display hack for parts of SkyAware; a future separate project perhaps as long as it’s not going too far down the .js rabbithole.

Still a mystery: it’s all to do with folder permissions and rights I think. I have one iron left in the fire to investigate: setting some extra config values in lighttpd for PHP, we shall see.

I don’t know how you’d drive the “slit flap” from the Pi data (we use it via form entered data to generate a list of flights our charity sim is flying when it is flying on charity events - a full cockpit based 737 sim in Peterborough used for flight experiences and real world pilot training). I’m doing further development work on it but here is how it looks today on test (statically - it usually “flaps” around between entries, which is kind of the point of having a “split flap”)

Your departure board looks fantastic, really nice. I bet even more so in action.

I tried adding a phpinfo.php file containing

<?php phpinfo( ); ?>

to both /usr/share/dump1090-fa/html (to view from the SkyAware page) and to /var/www/html (to view off the main page). Neither worked, both 403 Forbidden. I was just curious if the different html locations caused different behaviours.

Same whatever the location :frowning:

This looked like the last hope article on lighttpd setup:

Steps 8 through 10 are what I need to do but am reticent in case it tanks the FlightAware setup (which I very much doubt it will, it’s just mine is in the loft so a right pain if things go wrong!)

On other PIs I never got lighttpd working with PHP (I didn’t try the above, but just threw Apache on there which worked just fine!)

I’m blowing my setup away later for a reinstall so will have a play first. Meanwhile could you try using Docker or something to keep a new instance separate from the FA main instance?

Not used docker before - I’ll look at that, thanks. It’s been a long time since I did what I’d consider proper programming, not this new fangled web stuff (when every machine cycle mattered - programming XGA display driver at IBM, which dates me to the start of the 90s :frowning: )

For guidance, please see these 3 posts linked below, in which I have installed PHP to serve my file gain.php which I located in folder /usr/share/dump1090-fa/html/. This method did not disturb SkyView.

Any file (.php or .html) located in folder /usr/share/dump1090-fa/html can be served in a browser without disturbing Piaware SkyView. If the file name is myFile.php, the url will be
IP-of-Pi/dump1090-fa/myFile.php

File gain.php served stand alone

gain.php

File gain.php served embeded in SkyView

Splendid, I shall run through your procedure asap and report back. Thanks for taking the time to help.

No need to run through the procedure, it may be confusing. Just in brief do this:

If you have Raspbian Jessie:
sudo apt install php5-cgi

If you have Raspbian Stretch:
sudo apt install php7.0-cgi

If you have Raspbian Buster:
sudo apt install php7.3-cgi

After installing correct version of php-cgi as above, enable module fastcgi-php:

sudo lighty-enable-mod fastcgi-php  
sudo /etc/init.d/lighttpd force-reload  

TEST

Create a test file myfile.php in folder /var/www/html/

sudo nano /var/www/html/myfile.php

Copy paste some php code in the blank file

<!DOCTYPE html>
<html>
<head>
<title>Hello, World! Page</title>
</head>
<body>
<?php
	echo 'Hello, World!';
?>
</body>
</html>

Save file, and exit nano.

Now go to your browser and type following address:
IP-of-Pi/myfile.php

.

Alternatively you can create a folder inside /var/www/html/ to hold all your files.

sudo mkdir /var/www/html/myFolder
sudo nano /var/www/html/myFolder/myfile.php

Copy-paste above noted php code, save & close the file.

To see this file in browser, use this address:
IP-of-PI/myFolder/myfile.php

Piaware NOT disturbed by PHP

.

.

sudo apt install php7.3-cgi
sudo lighty-enable-mod fastcgi-php
sudo /etc/init.d/lighttpd force-reload

and then I can get this

It’s alive (AND running PHP).
Thanks everybody… I’ll see where I can get with my PHP “nearest plane” and post back.

1 Like

## Create a blank file "php-info.php
## I assume you have already created the folder /var/www/html/myFolder
pi@piaware:~ $ sudo nano /var/www/html/myFolder/php-info.php 

## Copy-paste following code, and save file
<?php
phpinfo();
?>

.

Now go to following address in your browser:
IP-of-Pi/myFolder/php-info.php

This is what you get. :slight_smile:
It is a long page with lot of info if you scroll down.

Cautionary Note:

Remember, dont try to edit following three files unless you fully understand what you are doing. Editing these files may result in breakdown of Piaware Status & SkyView pages:

/etc/lighttpd/lighttpd.conf
/etc/lighttpd/conf-enabled/89-dump1090-fa.conf
/etc/lighttpd/conf-available/89-dump1090-fa.conf

Even if you fully understand what are you doing, and decide to edit these files, make backup copy of the file before editing it, so that you can easily restore if your modifications cause breakdown of something.

1 Like

Thanks. Now you mention them I feel strangely drawn to them :slight_smile:

I’ve used Win32DiskImager for the “ultimate” safety net, but I don’t want to have to go into the loft to swap cards if I can avoid it!

BTW. If you have the time please; when you slotted your Gain PHP script into the SkyView page how does that interact with updates? Coming from a WordPress world I’m very aware that there is a risk of making changes to a key template file (we don’t, instead WP has hooks, filters and child files) and then on update it either gets overwritten or it doesn’t get updated: neither of which are happy scenarios. I guess you try to do everything in an include file and then just include that where you want, and then on update you slot that back in again where it belongs into the new updated file. Just curious on that. Maybe SkyView doesn’t update very often?

  • The file /usr/share/dump1090-fa/html/gain.php is unaffected by piaware update/upgrade.

  • The changes I made in file /usr/share/dump1090-fa/html/index.html (to embed the file gain.php) are lost as index.html got replaced by piaware update/upgrade.

Files in folder /var/www/html (and its sub-folders) dont get affected by Piaware update/upgrade.

All makes sense thanks.

Have so far managed to pull flight data and determine nearest aircraft to home location and its bearing, plus pull other data, gs etc. So much easier to code in PHP than JavaScript (for me). Distance and bearing calculations from lat lon are ‘interesting’, and have to be careful not to overload pi with lots of trigonometry. A dynamic (continually updating display) would be fun, but with up to 160 aircraft positions that would definitely kill my pi without some seriously smart optimisation. More anon.

1 Like

You might find this page interesting for range/bearing calculations. I found it very useful when writing my heatmap scripts. There’s some example code - it shouldn’t be too heavy for a pi to run depending on how you implement it.

1 Like