embeded php code not activating
Joe Curtis
nginx-forum at forum.nginx.org
Sun Aug 14 15:48:01 UTC 2016
I have a weather station website running successfully under apache2 on a
fedora based server. I am in the process of transferring it to run on a
raspberry pi 3 under nginx. This has transferred without a problem with the
exception of a small section of PHP code which loads a graphic of the moon
phase selected by date.
The html code calling the graphic is:-
/var/www/html/weather/index.htm excerpt
<td rowspan="3"><img src="moonphase.php" alt="Moon" width="64" align="left"
border="0" height="64" hspace="10" /></td>
moonphase.php calculates which image is required depending on parameters
passed in moonphasetag.php.
/var/www/html/weather/moonphase.php
<?php
error_reporting(E_ALL);
require "moonphasetag.php";
function int($s){return(int)preg_replace('/[^\-\d]*(\-?\d*).*/','$1',$s);}
$mp = int($MoonPercent);
$lat = substr($latitude, 0, 1);
$file1 = 'moon/back.jpg';
$file2 = 'moon/moon.jpg';
$img = @imagecreatetruecolor(64, 64);
$imgFinal = @imagecreatetruecolor(64, 64);
if ($lat == "N") {
if ($mp == 0) {
$file1 = 'moon/new.jpg';
copy ($file1, $file2);
} elseif ($mp >= 1 AND $mp < 49) {
$file1 = 'moon/waxing_crescent.jpg';
copy ($file1, $file2);
} elseif ($mp == 49 OR $mp == 50) {
$file1 = 'moon/first_quarter.jpg';
copy ($file1, $file2);
} elseif ($mp > 50 AND $mp < 99) {
$file1 = 'moon/waxing_gibbous.jpg';
copy ($file1, $file2);
} elseif ($mp == 99 OR $mp == 100) {
$file1 = 'moon/full.jpg';
copy ($file1, $file2);
} elseif ($mp >= -99 AND $mp <= -51) {
$file1 = 'moon/waning_gibbous.jpg';
copy ($file1, $file2);
} elseif($mp == -50 OR $mp == -49) {
$file1 = 'moon/last_quarter.jpg';
copy ($file1, $file2);
} elseif ($mp >= -49 AND $mp <= -1) {
$file1 = 'moon/waning_crescent.jpg';
copy ($file1, $file2);
}
} else {
if ($mp == 0) {
$file1 = 'moon/new.jpg';
copy ($file1, $file2);
} elseif ($mp >= 1 AND $mp < 49) {
$file1 = 'moon/swaxing_crescent.jpg';
copy ($file1, $file2);
} elseif ($mp == 49 OR $mp == 50) {
$file1 = 'moon/sfirst_quarter.jpg';
copy ($file1, $file2);
} elseif ($mp > 50 AND $mp < 99) {
$file1 = 'moon/swaxing_gibbous.jpg';
copy ($file1, $file2);
} elseif ($mp == 99 OR $mp == 100) {
$file1 = 'moon/full.jpg';
copy ($file1, $file2);
} elseif ($mp >= -99 AND $mp <= -51) {
$file1 = 'moon/swaning_gibbous.jpg';
copy ($file1, $file2);
} elseif ($mp == -50 OR $mp == -49) {
$file1 = 'moon/slast_quarter.jpg';
copy ($file1, $file2);
} elseif ($mp >= -49 AND $mp <= -1) {
$file1 = 'moon/swaning_crescent.jpg';
copy ($file1, $file2);
}
}
$img = imagecreatefromjpeg($file2);
imagecopyresampled($imgFinal, $img, 0, 0, 0, 0, 64, 64, 64, 64);
header('Content-Type: image/jpeg');
imagejpeg($imgFinal, null, 100);
imagedestroy($imgFinal);
imagedestroy($img);
?>
As far as I can tell I have set all the nginx parameters correctly:-
/etc/nginx/sites-enabled/weather
server {
listen 80;
listen [::]:80;
server_name www.craythorneweather.info;
root /var/www/html/weather;
index index.html index.htm index.php;
access_log /var/log/nginx/weather.access_log;
error_log /var/log/nginx/weather.error_log info;
location / {
try_files $uri $uri/ =404;
}
location ~* \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi.conf;
include /etc/nginx/fastcgi_params;
}
}
The code works perfectly under apache but I am keen to have it operating
under nginx on the RPI.
Any pointers as to where I am going wrong would be appreciated.
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,268949,268949#msg-268949
More information about the nginx
mailing list