Industrial manufacturing
Industrial Internet of Things | Industrial materials | Equipment Maintenance and Repair | Industrial programming |
home  MfgRobots >> Industrial manufacturing >  >> Manufacturing Technology >> Manufacturing process

Turn Your Raspberry Pi 4 Into a Web Server and Build Your Own Site

Ready to harness the power of a Raspberry Pi 4 as a lightweight, cost‑effective web server? This guide walks you through installing Apache, PHP, and creating custom HTML/CSS pages—all while keeping your setup secure and maintainable.

What You’ll Need

Step 1: Prepare Your Pi

Boot up your Pi with Raspberry Pi OS (Lite or Desktop). Open a terminal or connect via SSH to run the following commands.

sudo apt update && sudo apt upgrade -y

This ensures all packages are current before we install the web stack.

Installing Apache

Apache is a proven, open‑source web server that serves static and dynamic content. Install it with:

sudo apt install apache2 -y

Once installed, Apache automatically starts and places a default page in /var/www/html.

Installing PHP

PHP enables server‑side scripting and database integration. Install the core package and the Apache module:

sudo apt install php libapache2-mod-php -y

Restart Apache to load PHP:

sudo systemctl restart apache2

Step 2: Verify the Server Is Running

Open a web browser on the Pi and navigate to https://localhost/ or https://raspberrypi.local/. You should see the Apache welcome page. To test from another device, find the Pi’s IP address:

hostname -I

Then visit https://192.168.1.102 (replace with your actual IP) on any computer connected to the same network.

Step 3: Customize the Default Page

By default, the index.html file is owned by the root user, preventing edits. Change ownership to your own user (replace pi with your username):

sudo chown pi:pi /var/www/html/index.html

You can now edit index.html directly or use a text editor like nano:

nano /var/www/html/index.html

Refresh your browser to see updates.

Step 4: Enable Remote Editing (Optional but Handy)

For frequent changes, consider using a secure file transfer client. WinSCP (for Windows) or FileZilla (cross‑platform) let you edit files over SFTP:

After connecting, navigate to /var/www/html to modify index.html or add new pages.

Step 5: Secure Your Server (Best Practice)

• Change the default pi password: passwd. • Enable the built‑in firewall: sudo apt install ufw -y, then sudo ufw allow OpenSSH and sudo ufw enable. • Consider installing fail2ban to protect against brute‑force attempts.

Next Steps: Building Your Site

With Apache and PHP in place, you can now develop static pages with HTML/CSS or dynamic content using PHP and MySQL (install with sudo apt install mariadb-server php-mysql -y). Host your own portfolio, blog, or IoT dashboard right from your kitchen table.

Resources

Manufacturing process

  1. Efficient Web Server Solutions for Resource-Constrained Microcontrollers
  2. Raspberry Pi Unveils RP2040 MCU and $4 Pico Board
  3. Real‑Time Temperature & Humidity Monitoring via Web on Raspberry Pi 4
  4. Home Temperature & Humidity Monitor with Raspberry Pi & Web Dashboard – Real‑Time Remote Tracking
  5. Build a Professional Raspberry Pi Universal Remote with LIRC
  6. Converting RF to DC with a Raspberry Pi: Building and Troubleshooting an Envelope Detector
  7. Cycle Chaser: Transform Your Bike into a Nighttime Light Show with Raspberry Pi
  8. Wireless Node.js‑Controlled Robotic Car – Real‑Time IoT Project
  9. Build a Raspberry Pi NAS Server: Step‑by‑Step Guide to Secure, Wireless File Sharing
  10. Web Server vs. Application Server: Key Differences & How to Choose the Right One