Raspberry Pi as a local PHP web server: setup guide (plus GumCP control panel)

#php #raspberry-pi #server

No replies · 0 views · started 58 minutes ago · 3 min read

GumSlone Administrator Principal · 1,698 posts #1

Want a PHP server at home for testing, a LAN-only community, a wiki or your home-automation dashboard? A Raspberry Pi is cheap, silent, uses about 3–7 W, and is more than enough for a small site.

Which Pi?

  • Raspberry Pi 5 (4 or 8 GB): the best choice. It's fast enough for PHP, MariaDB and Redis together.
  • Pi 4 (4 GB): still fine for a small site or a dev server.
  • Pi 3 / Zero 2 W: only for very light, static or single-user use.

Storage: don't run a server from an SD card

SD cards wear out with database writes and are slow. Use one of these:

  • Pi 5: an NVMe SSD on an M.2 HAT, the best option.
  • Pi 4: a USB 3 SSD (boot from USB).

Keep a spare SD card with a fresh image as a rescue disk.

Also get: the official power supply (under-voltage causes random crashes), a case with a fan or heatsink, and wired Ethernet instead of Wi-Fi.

Software stack

  • OS: Raspberry Pi OS Lite (64-bit), with no desktop.
  • Web server:
    • Nginx or Caddy with PHP-FPM: light and fast.
    • Apache: simplest if you follow older tutorials.
  • PHP: 8.2 or newer with OPcache.
  • Database: MariaDB, or SQLite for tiny sites (no extra service, nothing to tune).
  • Cache: Redis, optional.

Quick start:

sudo apt update && sudo apt full-upgrade -y
sudo apt install -y nginx php-fpm php-mysql php-mbstring php-xml php-curl php-zip php-gd php-intl mariadb-server
sudo mysql_secure_installation

Tuning for a Pi with 4 GB

pm = dynamic
pm.max_children = 10
memory_limit = 128M
opcache.memory_consumption = 128
innodb_buffer_pool_size = 512M

Also turn on log2ram or reduce logging to spare the disk.

Making it reachable

  • LAN only: give the Pi a fixed IP in your router and use it as http://pi.local.
  • From outside, without opening ports: Cloudflare Tunnel or Tailscale. This is safer than port forwarding and works behind CGNAT.
  • Port forwarding 80/443: only with HTTPS (Let's Encrypt), a firewall and fail2ban.
  • A changing home IP: use a dynamic DNS service such as DuckDNS.

Security basics

  • Users and SSH: change the default user and password, use SSH keys only, and turn off password logins.
  • Firewall: ufw allowing only 22, 80 and 443.
  • Updates: unattended-upgrades for security patches.
  • Backups: back up the database and files to another machine or cloud storage. SD cards and SSDs do die.

Managing it from the browser: GumCP

If you don't want to SSH in for every little thing, try GumCP, a free, open-source web control panel built for the Raspberry Pi. It's a lightweight alternative to Webmin and Cockpit, written in PHP, so it fits right in with this stack:

  • Dashboard: live CPU, temperature, memory, disk, network and power or throttling status.
  • Services and processes: start or stop services (Nginx, PHP-FPM, MariaDB…) and kill runaway processes.
  • Package updates: apt update and upgrade from the browser.
  • System tools: logs (journal, dmesg, /var/log), cron jobs and Docker containers.
  • Command buttons: one-click buttons for your own commands (clear cache, restart PHP, run a backup), with an optional HTTP API for Home Assistant or curl.
  • Hardware: GPIO control and raspi-config options.
  • Scripts: a script editor with output tiles on the dashboard.
  • Security and safety: alerts to your phone via ntfy or Telegram for high temperature, under-voltage or a full disk; two-factor login; backup and restore.

Install:

wget https://raw.githubusercontent.com/gumslone/GumCP/master/installer.sh && bash ./installer.sh

Keep GumCP on your LAN or behind Tailscale or Cloudflare Access; a control panel should never be open to the whole internet.

What can a Pi 5 handle?

A Pi 5 with an SSD comfortably serves a small forum or blog with dozens of people online at once, and it's a perfect dev or staging server. For a public community with real traffic, move to a €5–10 VPS (see the web server requirements checklist).

Running a Pi server at home? Share your setup below.

Advertise your mobile site for FREE with AdTwirl

External image (may be gone)

Write your reply now; next you create a free account (or sign in) and it is posted right away. Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close