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.
How to install nginx with PHP and Sql-lite support on Raspberry Pi running Raspbian install :
- Use the below command in terminal to download and install nginx.
- We now need to add user and usergroups for nginx to work. These should get auto-created but we will just make things sure.
- We are now setupped, you can make changes as per your need to nginx server by editing /etc/nginx/sites-enabled/default
- 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. - If you want to use PHP, install it using following.
- 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 : - Use
sudo service nginx restart
to restart nginx with new changes. - 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 :
sudo apt-get install nginx
sudo useradd www-data
sudo groupadd www-data
sudo usermod -g www-data www-data
sudo apt-get install php5-fpm php5-cgi php5-cli php5-common
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;
}
sudo apt-get install sqlite3
Add new comment