Turris as a webserver

There is possibility to run nginx with PHP 5 on Turris. We're going to set it up in this tutorial.

Nginx and PHP

First of all, you need to update your package list

opkg update

and then install packages required to run webserver with PHP

opkg install nginx php5-fastcgi

Usually, there is lighttpd webserver for Foris and LuCi configured to ports 80 and 443. We need to reconfigure lighttpd so we can use ports 80 and 443 for nginx. You can do that in file /etc/lighttpd/lighttpd.conf by changing the port to 81 from 80. All you need to change are those two lines below.

server.port = 81
$SERVER["socket"] == "[::]:81" {  }

Now, just restart lighttpd, and Foris & LuCi will be available on port 81 instead of 80.

/etc/init.d/lighttpd restart

Port 80 is free and we can configure nginx.

Default nginx root is /www, which is already used by lighttpd for Foris and LuCi. If you don't mind where you want to have web files, create directory /usr/share/htdocs, which is used in example configuration below. If you want to have web files somewhere else, don't forget to change nginx root in configuration file.

We'll change content of file /etc/nginx/nginx.conf as follows

user nobody nogroup;
worker_processes 1;

error_log logs/error.log;

events {
    worker_connections 1024;
}


http {
	include mime.types;
	index index.php index.html index.htm;
	default_type text/html;

	sendfile on;
	keepalive_timeout 65;
	gzip on;

	gzip_min_length 1k;
	gzip_buffers 4 16k;
	gzip_http_version 1.0;
	gzip_comp_level 2;
	gzip_types text/plain application/x-javascript text/css application/xml;
	gzip_vary on;
	server {
	        listen 80;
		fastcgi_connect_timeout 300;
		fastcgi_send_timeout 300;
		fastcgi_read_timeout 300;
		fastcgi_buffer_size 32k;
		fastcgi_buffers 4 32k;
		fastcgi_busy_buffers_size 32k;
		fastcgi_temp_file_write_size 32k;
		client_body_timeout 10;
		client_header_timeout 10;
		send_timeout 60;
		output_buffers 1 32k;
		postpone_output 1460;

		root /usr/share/htdocs; # Root folder

		location ~ \.php$ {
			fastcgi_index  index.php;
			include        fastcgi_params;
			fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

			if (-f $request_filename) {
				fastcgi_pass 127.0.0.1:1026;
			}
		}
	}
}

Now we can move to file /etc/php.ini where we need to find and edit following lines

doc_root = "/usr/share/htdocs" ; Replace this path with the path to your nginx root
cgi.force_redirect = 1
cgi.redirect_status_env = "yes"

Restart nginx and content of your web root is now available over HTTP.

/etc/init.d/nginx restart