Raspberry Pi3(Raspbian/Ubuntu) as Webserver – Complete Guide-Installing (NGINX,CLOUDFLARE,WORDPRESS)

In order setup our own web hosting server, we hereby taking Raspberry pi as the hardware component. The system actually looks to be on par in most cases as it lined up in the slim margin of both “can be or cannot be”.

The advantage of using Raspberry pi:

Low cost web hosting(One time payable) – Rs.2100
Control over the website
Knowledge on doing by own
There are few disadvantages too:

With your internet it reflects on downtime
performance drop on high traffic of more than 1 lakh ping
Only static and limited dynamic websites can be made due to hardware process speed

Make raspberry pi ready with raspbian stretch or ubuntu mate change password for root and pi user.

Here we go!

Let’s start with Nginx(Engine X), a webserver with high potential for low processor and also helps in getting many traffic sources.

Install it via terminal

sudo apt-get install nginx

Now time to start the server

sudo service nginx start

Generally the Nginx performance is automated on its own but since the hardware is raspberry pi, we need to configure it.edit the file.

/etc/nginx/nginx.conf, you can copy  and replace with paste.
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768;
multi_accept on;

http {

# Basic Settings

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 10;
types_hash_max_size 2048;
server_tokens off;
client_max_body_size 64M;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;

include /etc/nginx/mime.types;
default_type application/octet-stream;

# SSL Settings

ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
ssl_prefer_server_ciphers on;

# Logging Settings

access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;

# Gzip Settings

gzip on;
gzip_disable "msie6";

gzip_vary on;
# gzip_proxied any;
gzip_comp_level 5;
# gzip_buffers 16 8k;
gzip_http_version 1.1;

# Virtual Host Configs

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
Time to test and restart nginx, run the commands

sudo nginx -t

sudo service nginx restart

Thus, Nginx is ready for our work and /var/www/html is our root directory serving the contents. now, Switch to php installation.

install it with the following,

sudo apt-get install php7.0-fpm php7.0-mysqlnd php7.0-xmlrpc php7.0-curl php7.0-gd php-imagick php7.0-imap -y

now we need enable php inside nginx hence,we need to edit the file,


To do this, edit the file “/etc/nginx/sites-available/default“, for example via the command:

sudo nano /etc/nginx/sites-available/default
And look for the line

index index.html index.htm index.nginx-debian.html;
To replace it by the line

index index.html index.htm index.php;
This will add an automatic redirection to the “index.php” files for the site folders, Apache’s default behavior.

We will now activate php-fpm for Nginx. To do this, look for the  lines

#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
# # With php5-cgi alone:
# fastcgi_pass;
# # With php5-fpm:
# fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
And modify them in order to obtain the following result:

location ~ \.php$ {
include snippets/fastcgi-php.conf;
 fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
All that remains is to modify the rights of the folder “/ var / www / html” in order to manage our sites more easily. To do this, simply run the following commands:

sudo chown -R www-data:pi /var/www/html/
sudo chmod -R 770 /var/www/html/
Finally, we will add an “index.php” file to verify that PHP is working. To do this, run the following command:

echo "<?php phpinfo(); ?>" > /var/www/html/index.php
Once all this is done, you must restart Nginx, in order to apply the changes, always with the command:

sudo /etc/init.d/nginx restart
All you have to do is verify that the server is functioning properly, as before. You should get a page displaying PHP information.

Post a Comment