Archive for August, 2015

I’m playing with consoles or dashboards for use with OpenHAB. OpenRemote is good as a remote, but the ability to display status info is better suited to a dashboard. Earlier attempts have used the Tomcat server to display simple HTML/JS/CSS web pages, but occasionally I need a ‘proper’ web server so I can try out things like PHP.

Normally I’d insert Apache between the browser and Tomcat to allow it to handle redirects and routes when other page types are encountered, but the hassle of installing a memory hog like Apache for playing with the odd PHP page seems pointless.

nginx is a lightweight alternative that is more efficient & faster than Apache in serving requests, but at the cost of less bells & whistles. Given the nature of the work, simplicity is the key here.

So install nginx:

sudo apt-get update
sudo apt-get install nginx

Then MySQL:

sudo apt-get install mysql-server

Then php:

sudo apt-get install php5-fpm php5-mysql

We need to modify PHP to prevent path fixing by changing a flag. Edit the .ini file

sudo nano /etc/php5/fpm/php.ini

Replace the

;cgi.fix_pathinfo=1

with

cgi.fix_pathinfo=0

and then save the .ini file and restart PHP with

sudo service php5-fpm restart

Finally configure nginx to work with PHP. Edit the config

sudo nano /etc/nginx/sites-available/default

We need to modify the server file to use PHP and to prevent bad PHP requests being passed around:

server {
 listen 80 default_server;
 listen [::]:80 default_server ipv6only=on;
root /usr/share/nginx/html;
 index index.php index.html index.htm;
location / {
 try_files $uri $uri/ =404;
 }
location ~ \.php$ {
 try_files $uri =404;
 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 fastcgi_params;
 }
}

Finally, restart nginx

sudo service nginx restart