Wordpress installation in Raspberry Pi using Nginx
Amal Satheesan
Posted on September 2, 2024
We will be continuing from were we left off. Disclaimer: You can use apache if you want. Apache is easier to setup compared to Nginx.
Keywords used in the guide:
- Raspberry Pi
- NGINX server
- WordPress
- MySQL
- PHP
Step 1: Update the Raspberry Pi
First, make sure your Raspberry Pi is up-to-date:
sudo apt update
sudo apt upgrade -y
Step 2: Install NGINX
NGINX will serve as your web server.
-
Install NGINX:
sudo apt install nginx -y
-
Start and enable NGINX:
sudo systemctl start nginx sudo systemctl enable nginx
-
Verify NGINX is running:
sudo systemctl status nginx
Check in a browser by typing your Raspberry Pi's IP address (e.g.,
http://192.168.x.x
).
Step 3: Install MySQL (MariaDB)
WordPress needs a database, so we will install MariaDB.
-
Install MariaDB server:
sudo apt install mariadb-server -y
-
Secure the installation:
sudo mysql_secure_installation
Follow the prompts to secure your database (set root password, remove anonymous users, disable root login remotely, etc.).
-
Log in to MariaDB:
sudo mysql -u root -p
-
Create a database for WordPress:
CREATE DATABASE wordpress; CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost'; FLUSH PRIVILEGES; EXIT;
Step 4: Install PHP
PHP will be used to process dynamic content for WordPress.
-
Install PHP and necessary extensions:
sudo apt install php-fpm php-mysql php-curl php-gd php-xml php-mbstring -y
Step 5: Configure NGINX to Use PHP
-
Create an NGINX server block for WordPress:
sudo nano /etc/nginx/sites-available/wordpress
-
Add the following configuration:
server { listen 80; server_name _; root /var/www/wordpress; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php/php-fpm.sock; } location ~ /\.ht { deny all; } }
-
Enable the configuration:
sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/ sudo rm -r /etc/nginx/sites-enabled/default
-
Test and restart NGINX:
sudo nginx -t sudo systemctl restart nginx
Step 6: Download and Configure WordPress
-
Install
wget
andunzip
(if not installed):
sudo apt install wget unzip -y
-
Download WordPress:
cd /var/www sudo wget https://wordpress.org/latest.zip sudo unzip latest.zip sudo mv wordpress /var/www/
-
Set correct permissions:
sudo chown -R www-data:www-data /var/www/wordpress sudo chmod -R 755 /var/www/wordpress
-
Configure WordPress to connect to your database:
cd /var/www/wordpress sudo cp wp-config-sample.php wp-config.php sudo nano wp-config.php
Update the database settings in
wp-config.php
:
define( 'DB_NAME', 'wordpress' ); define( 'DB_USER', 'wpuser' ); define( 'DB_PASSWORD', 'password' ); define( 'DB_HOST', 'localhost' );
Step 7: Complete WordPress Installation
- Open your web browser and navigate to
http://your_domain_or_IP
. - Follow the on-screen instructions to complete the WordPress installation.
After these steps, your Raspberry Pi should be hosting a fully functional WordPress site using NGINX, PHP, and MariaDB.
In the next blog, we will be hosting the site to public using a secure tunnel. Stay tuned for that....!
Posted on September 2, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.