Raspberry Pi as a web server - how it works
Related Videos: Raspberry Pi Web Server Tutorial (May 2024).
The single-board computer Raspberry Pi is versatile and can be used as a web server, for example. This practical tip shows you how to set up your Raspberry Pi as a web server and which software you need.
How to set up your Raspberry Pi as a web server
There are several different web servers for the Raspberry Pi. In this practical tip, we present the web server NGINX. Despite the low system performance, this runs very stable. To install NGNIX on your system, you have to do the following:
- Bring your system up to date first. First run "sudo apt-get update" and then "sudo apt-get upgrade".
- Then install the package for the web server with "sudo apt-get install nginx".
- After the server has been installed, you can start it with the command "sudo /etc/init.d/nginx start".
- You can now call up the test page generated by NGINX in the browser of the Raspberry Pi with "// localhost /". If you want to access the website from another computer in the network, enter "// IP-Adresse-des-Raspberry /" in the browser.
- You can find out the IP address of your Raspberry by entering "hostname -I" in the console.
- If you want to change the website, navigate with "cd / usr / share / nginx / www" into the directory of the website and replace the index.html with your own page.
How to install PHP on your web server
In order to be able to provide dynamic websites on your web server, the installation of PHP is necessary. To do this, proceed as follows:
- Install the PHP package with "sudo apt-get install php5-fpm".
- Then you have to activate PHP in NGINX. To do this, change to the directory of NGINX with "cd / etc / nginx".
- Open the configuration page with the NANO editor. To do this, enter "sudo nano sites-enabled / default" in the console.
- In this document, replace "index index.html index.htm;" by "index index.php index.html index.htm;".
- Then look for "# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000" below in the document.
- Remove the diamond at the following 6 lines (points seven to twelve):
- location ~ \ .php $ {
- fastcgi_split_path_info ^ (. + \. php) (/.+) $;
- fastcgi_pass unix: /var/run/php5-fpm.sock;
- fastcgi_index index.php;
- include fastcgi_params;
- }
- Then save the configuration and restart NGINX with "sudo /etc/init.d/nginx reload".
- Navigate back to the folder of the standard website by entering "cd / usr / share / nginx / www /" in the console.
- Replace the existing "index.html" with "index.php" and fill it with the desired content.