49

members

Easy Raspberry basics: Project 24a Raspberry PI Zero W board - Apache web server

of Acoptex.com in Raspberry Pi Zero W

Raspberry basics: Project 24a

Project name: Raspberry PI Zero W board - Apache web server

Tags: Raspberry, Raspberry PI Zero W board, vers 1.1, v 1.1, Apache web server, local html server, intranet web server using Apache, Appache2, PHP7, php7, MySQL

In this project, you needed these parts (Dear visitors. You can support our project buy clicking on the links of parts and buying them or donate us to keep this website alive. Thank you):

1. Raspberry PI Zero W board 1 pc

2. Micro SD card with NOOBS and SD card adapter 1 pc

3. Micro USB power supply (2 A 5V or 5V 3A) 1 pc

4. USB keyboard 1 pc

5. USB mouse 1 pc

6. TV or PC monitor 1 pc

7. HDMI cable 1 pc

8. T-Cobbler Breakout and GPIO Cable 1 pc

9. Micro USB 2.0 OTG Cable 1 pc

10. Mini HDMI to HDMI Adapter (HDMI to Mini HDMI Adapter) 1 pc

11. 4-Port USB 2.0 Hub 1 pc

General

We will learn how to build a local html server with Raspberry PI Zero W board. We will build our own local intranet Apache web server to display basic or professional internal websites.

A Raspberry Pi Zero W board is an ideal Apache web server for small websites that don’t require the capacity or server-side processing power of a more powerful computer, and it’s an ideal development environment if you’re to use HTML.

Understanding the Raspberry PI Zero W board

You can read more about it here.

Signals and connections of the Raspberry PI Zero W board


Step by Step instruction

We recommend using a high-performance SD card for increased stability as well as plugging your device into an external display to see the default application booting up.

1. Setup and preparation

We assume that you have Windows 10 installed on your PC and Raspbian OS installed on your Raspberry Pi Zero W board. 

  1. Do wiring.
  2. Insert your micro SD card with Raspbian OS into the TF card slot on the Raspberry Pi Zero W board. It will only fit one way.
  3. Connect Raspberry PI Zero W board mini HDMI port to your TV or Monitor HDMI (DVI) port (use HDMI cable and mini HDMI to HDMI adapter and/or HDMI to DVI adapter).
  4. Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI/DVI,  etc).
  5. Plug in micro USB 2.0 OTG Cable to USB data port of Pi Zero and 4-Port USB 2.0 Hub to micro USB 2.0 OTG Cable. 
  6. Plug in your USB mouse and USB keyboard to 4-Port USB 2.0 Hub.
  7. If you intend to connect your Raspberry Pi Zero vers 1.2 or vers 1.3 to the internet, connect a WiFi dongle to one of the 4-Port USB 2.0 Hub ports.
  8. Connect Micro USB power supply to Raspberry PI Zero board micro USB input.
  9. The Raspberry PI desktop will start up.
  10. Open Terminal window and type the command: sudo apt-get update
  11. Then type the command: sudo apt-get upgrade -y
  12. Adding -y to the end of apt-get commands instructs the program to automatically answer yes to any questions rather than waiting for you to type Y or N.
  13. We will need to know our Raspberry Pi Zero W board IP address to access it. Type this command: hostname -I As you can see we have 192.168.0.117.
  14. Using obtained IP address you can remote login to Raspberry Pi Zero W board with SSH.
  15. Open the Raspberry Pi Configuration tool from the main menu. Go to Raspberry icon-> Preferences -> Raspberry PI configuration

  16. Select Interfaces and make sure that all settings are enabled so you will not need to come back to these configuration tool again.

  17. Click on OK button.
  18. We need to reboot our Raspberry PI. If it will not reboot automatically go to Terminal. Type this command in the Terminal: sudo reboot

2. Install Apache web server

  1. After restart of Raspberry Pi set up the remote access to your Raspberry Pi Zero W board. You can read how to do it here.
  2. Type this command to  install new Apache web server: sudo apt-get install apache2 -y
  3. Check whether the Apache is installed properly by running http://raspberrypi_IPaddress (we have http://192.168.0.117) in your browser on PC or http://localhost/ in the Chromium browser of your Raspberry Pi. It will display the Apache Debian default page on successful installation.

3. Installing PHP

  1. Many websites use content management systems, such as WordPress. These require PHP and MySQL, so if you want to experiment with CMS-driven sites further down the line, this is an ideal time to add the software you’ll need to render them.
  2. Once Apache web server installed type this command to install PHP to run the PHP files and projects on this server: sudo apt-get install php libapache2-mod-php -y
  3. The default web page is just an HTML file on the filesystem. It is located at /var/www/html/index.html.
  4. Type this command to access root: sudo su
  5. Go to the folder /var/www/html/ by typing the command: cd /var/www/html/
  6. Delete index.html, because it takes precedence over index.php by typing this command: rm index.html

  7. To test PHP create the file index.php by typing this command: leafpad index.php
  8. Put some PHP content in it: 
  9. Go to File->Save to save the file and close the window.
  10. Refresh your browser. You should see “hello world”. This page is not dynamic, but it is still served by PHP.

4. Installing MySQL

  1. MySQL (pronounced My Sequel or My S-Q-L) is a popular database engine. Like PHP, it’s widely used on web servers, which is why projects like WordPress use it, and why those projects are so popular.
  2. Install the MySQL Server and PHP-MySQL packages by entering the following command into the terminal window:
    MySQL (pronounced My Sequel or My S-Q-L) is a popular database engine. Like PHP, it’s widely used on web servers, which is why projects like WordPress use it, and why those projects are so popular.
  3. Install the MySQL Server and PHP-MySQL packages by entering the following command into the Terminal window: sudo apt-get install mysql-server php-mysql -y

  4. Now restart Apache by typing this command: sudo service apache2 restart

5. Changing the web page

  1. Run the following command to make /var/www/html/ folder accessible to the default user pi: sudo chown -R pi /var/www/html

  2. You can delete the index.php file found there by typing this command: sudo rm index.php and upload your new intranet site to that folder. Your new site will be accessible from your local network at http://raspberrypi_IPaddress (we have http://192.168.0.117) or http://localhost/ in the Chromium browser of your Raspberry Pi.
  3. Your Raspberry Pi is an ideal environment for web development, so you can simply drop the HTML files you’re working on into your web server directory.  You can also install a CMS such as WordPress, which you’ll be able to access from a browser on your local network to create content-rich websites.
  4. While this is strictly a local web server project, the same software and processes go into an internet-facing server, although that will require firewall configuration and extra security measures that are beyond the scope of this tutorial.

Summary

We have learnt how to create a file server using Raspberry PI Zero W board. 

Libraries in use

  • no libraries used

Script

  • none


Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019

« Go back to category
Is this project fake? Report it!   
Recommend to a friend
Published at 05-01-2019
Viewed: 745 times