In this post, creating a web server and running PHP script on it using Raspberry Pi will be discussed.
Web Servers are basically simple computer programs that dispense the web page when they are requested using the web client. The machines on which this program run are usually called as a server, with both the names web server and server almost used interchangeably.
Steps to create a web server and run PHP script on it using Raspberry Pi:
- Change to root directory and run a update :
sudo -i apt-get update
- Now install each of the packages which will be necessary for the following process,
apt-get install nginx php5-fpm php5-cgi php5-cli php5-common
- Then start the server
service nginx start
- Now run the following command:
ifconfig // it tells the ip address
Now paste this ip address to computer’s browser. If everything above went well, then it will show the following text/window on the browser window.
Welcome to nginx!

To run PHP script on this web server:
- Enter the config directory:
cd /etc/nginx
- Now navigate to sites-available directory.
cd sites-available
- There will be a single file present having name default, open it and edit it by typing
nano default
-
Now find below lines and uncomment them.
location=\.php5 { fastcgi_split_path_info "(.*\.php)(/.*)5; fastcgi.pass unix:/var/run/php5-fpm. fastcgi_index index.php; include fastcgi_params; } location=/\.bt{ } -
Also, change below line,
index index.html index.htm;
to
index index.php index.html index.htm; //to use PHP we added index.php
Now to save and exit, press Ctrl+x then press Y.
-
Now lets restart the server, to collect the changes that have been done:
service nginx restart
- Now we have to create a index.php file in our www directory
cd/user/share/nginx/www nano index.php
- Write this script here:
<HTML><HEAD><TITLE> hello world<TITLE></HEAD><BODY><?phpprint("Hello from GeeksforGeeks");?></BODY></HTML>chevron_rightfilter_none - Now save it and then test everything in the browser using that IP address or type youripaddress/index.php e.g 192.168.182.1/index.php
Recommended Posts:
- Run Python script from Node.js using child process spawn() method
- Run Python Script using PythonShell from Node.js
- Difference Between Web server and Application server
- Difference between Apache Tomcat server and Apache web server
- Difference between Web Browser and Web Server
- How to choose Web Hosting Server and Web Domain ?
- Web 1.0, Web 2.0 and Web 3.0 with their difference
- How do you run JavaScript script through the Terminal?
- Why PHP script does not create a directory with 777 permissions ?
- Web Server and Its Type
- How to import config.php file in a PHP script ?
- Difference between Web Scraping and Web Crawling
- Difference between Web Designer and Web Developer
- Differences between Web Services and Web API
- Progressive Web App - A Combination of Native and Web App
- 10 Web Development and Web Design Facts That You Should Know
- Build a Simple static file web server in Node
- Node.js | Web Server
- How to run JavaScript from PHP?
- How to Run Synchronous Queries using sync-sql Module in Node.js ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

