Megaleecher.Net

Making technology work for you...

Get Your Free Subscription By Email:

Easiest Method To Install Webserver On Raspberry Pi With PHP Support

The wonderful, multi-utility, mini-computer Raspberry Pi can also be used as an web-server. While you can't expect it to handle massive traffic, it can easily handle decent amount of static web-page traffic and can also be used as an web or mobile front-end for controlling RPi connected devices, services and GPIO for home automation. We have quite a few choices of web-servers to install on Debian, amongst the contenders we have apache, nginx, lighthttpd, Monkey web-server and quite a few others suitable on limited resources of Raspberry Pi. We will be installing the light, fast and well-supported nginx webserver with PHP support on Raspberry Pi as it behaves well with the mini-computer and takes only 5 minutes to get installed and working using the tutorial shared below.

nginx server on Raspberry Pi

How to install nginx with PHP and Sql-lite support on Raspberry Pi running Raspbian install :

  1. Use the below command in terminal to download and install nginx.
  2. sudo apt-get install nginx

  3. We now need to add user and usergroups for nginx to work. These should get auto-created but we will just make things sure.
  4. sudo useradd www-data
    sudo groupadd www-data
    sudo usermod -g www-data www-data

  5. We are now setupped, you can make changes as per your need to nginx server by editing /etc/nginx/sites-enabled/default
  6. To start nginx use sudo service nginx start, now open your Raspberry Pi IP in a web-browser and you should see the "Welcome to nginx" page as shown above.
  7. If you want to use PHP, install it using following.
  8. sudo apt-get install php5-fpm php5-cgi php5-cli php5-common

    Install PHP
  9. We need to make configuration changes so nginx can use PHP files, use sudo nano /etc/nginx/sites-enabled/default to edit the file and make changes so the php handler section looks like this :
  10. location ~ \.php$ {
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    # With php5-fpm:
    fastcgi_pass unix:/var/run/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    }

  11. Use sudo service nginx restart to restart nginx with new changes.
  12. We can also add SqlLite (or MySQL) database support to our installation if needed using appropriate ap-get install command. For Sqllite it would be :
  13. sudo apt-get install sqlite3

Add new comment

This is just one of the many helpful tips we have posted, You can find more stories here,
Do subscribe to updates using your favorite RSS feed reader or using the secure FeedBurner email update form on top of this post.