Self-hosted WordPress server using Raspberry Pi 4B, Nginx, MariaDB, and PHP.
This project demonstrates how to set up a web server on a Raspberry Pi 4B for hosting WordPress. It uses Nginx as the web server, MariaDB as the database server, and PHP for backend processing.
- Raspberry Pi 4B
- Sandisk 128GB microSD card
- Raspberry Pi OS Lite 64-bit
- Nginx (Web Server)
- MariaDB (Database Server)
- PHP (Backend)
- WordPress (CMS)
- Flash Raspberry Pi OS Lite 64-bit onto the microSD card.
- Connect via Ethernet and enable SSH for headless operation.
- Update the system:
sudo apt update && sudo apt upgrade -y
$ sudo apt install nginx -y
$ sudo apt install mariadb-server -y
$ sudo apt install php-fpm php-mysql -y
$ cd /var/www/
$ sudo wget https://wordpress.org/latest.tar.gz
$ sudo tar -xvzf latest.tar.gz
$ sudo rm latest.tar.gz
$ sudo chown -R root:root wordpress/
Edit the Nginx configuration:
upstream wp-php-handler {
server unix:/var/run/php/php8.2-fpm.sock;
}
server {
listen 80;
server_name _;
root /var/www/wordpress/;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass wp-php-handler;
}
}
$ sudo mysql
$ create database wordpress default character set utf8 collate utf8_unicode_ci;
$ create user 'username'@'localhost' identified by 'password';
$ grant all privileges on wordpress.* TO 'username'@'localhost';
$ flush privileges;
$ exit
- Access the Raspberry Pi’s IP address in a web browser.
- Enter database credentials and complete the setup.
This setup was done for testing purposes. The web server will be moved to a different machine, and the Raspberry Pi will be repurposed for other projects.