Open In App

How to Install WordPress on Raspberry Pi?

Last Updated : 17 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Installing WordPress on a Raspberry Pi is a fantastic way to create a low-cost, energy-efficient web server for your blog or website. This guide will walk you through the process, making it simple even if you’re new to WordPress and Raspberry Pi.

Prerequisites

Before we begin, ensure that you have the following:

  1. Raspberry Pi: Any version will work, but Raspberry Pi 2 or later is recommended for better performance.
  2. SD Card: Use an SD card with at least 16GB capacity.
  3. Local Network Connection: Your Raspberry Pi should be connected to your local network.
  4. SSH Access: Set up SSH for remote command line access.

Steps to Install WordPress

Follow the further steps to install WordPress on Raspberry Pi

Step 1: Set Up Apache Web Server

The most used web server on the internet is Apache. Its function is to offer website users HTML files, which browsers will then interpret.

sudo apt install apache2 -y

It'll just take a minute and it will be done. After everything is set up, Apache will upload a sample HTML file to your Pi's web folder. Test this from a different computer (or smartphone) connected to your network. You must type the Pi's IP address into your browser's address bar.

Apache2 Default Page
 

Step 2: Installing PHP on Raspberry Pi

This software pre-processor makes it possible to provide dynamic web pages from the server rather than static HTML pages. A PHP page uses calls to other pages and the database to fill it with content, whereas an HTML page may be generated entirely from scratch.

  • Install PHP with the following command:

sudo apt install php -y

Installation of php
Installing PHP
  • After this let's test PHP works. Change directory to /var/www/html/ like this:

cd /var/www/html/

  • Here, let's delete the index.html file (the web page that you viewed earlier):

sudo rm index.html

  • Now, create a new file called index.php (nano is installed by default in linux):

sudo nano index.php

  • Here, add the following code:

<?php echo "hello world \n"; ?> <?php echo date('Y-m-d H:i:s'); ?> <?php phpinfo(); ?>

  • Save and close the file.

Now go back the localhost and refresh the page to see the result.

PHP successfully installed
PHP Installed

It should now display only “Hello World!”. If so, everything works fine and you can move on. If not then try restarting Apache by the following command:

sudo service apache2 restart

PHP and Apache are both working now. It's time to install MySQL, a database software.

Step 3: Install MySQL

A database is necessary for WordPress (and other dynamically generated website software) to store the content, links to images, and control user access (among many other things). This project makes use of MariaDB, a fork of MySQL. To install it let’s use again apt:

sudo apt install mariadb-server

It will just take just a little bit longer than the previous ones.

MariaDB Server Installation
Installing MariaDB-Server

Configuring MariaDB

A password, which may be different from the other users is required to access the database. Only the root user has access by default and doesn't require a password from their account. Therefore, we will connect to it and set up a new WordPress account.

  • Establishing a MySQL CLI connection:

sudo mysql -uroot

  • Set up a new user:

CREATE USER 'wordpress'@'localhost' IDENTIFIED BY 'password';

  • Create a new database:

CREATE DATABASE wordpress;

  • Give WordPress user all privileges on the new database that we just created:

GRANT ALL ON wordpress.* TO 'wordpress'@'localhost';

  • Now we can quit the MySQL CLI:

quit

MySQL Package

A final little package needs to be installed in order for PHP to connect to MySQL:

sudo apt install php-mysl -y

Now again restart the Apache server:

sudo service apache2 restart

Testing Connection

Let's check that the connection is functional.

  • Connect to MySQL

mysql -u wordpress -p

  • Enter the password. If you didn't change the command earlier then it will be "password" otherwise enter your own.
  • Check if you can view the new database:

SHOW DATABASES;

quit

If you can at least see the WordPress database, you can move on to the actual WordPress installation.

WordPress installation
 

Step 4: Installing WordPress on Raspberry Pi

To install WordPress, you'll first need to download it. Before doing this remember to delete the contents of the /html/ directory:

cd /var/www/html/

sudo rm *

The rm (remove) command allows the wildcard asterisk (*) to delete the entire directory.

  • Let's use the wget to download the latest version of WordPress:

sudo wget https://wordpress.org/latest.zip -O /var/www/html/wordpress.zip

  • Unzip the file:

sudo unzip wordpress.zip

  • Move the content of the unzipped folder to the current folder which is /var/www/html/:

sudo mv wordpress/* .

Make sure to add the space and period that correspond to the current directory at the end.

Enter "ls" to confirm the directory is full of WordPress folders and PHP files:

unzip files of word press
WordPress files after unzip

Clean up a little before continuing by deleting the downloaded file and the WordPress directory:

sudo rm wordpress.zip

sudo rm wordpress -r

Set the Apache user as the owner of the directory:

sudo chown -R www-data: .

Configuring WordPress

The WordPress installation is now in place with everything done. We just have to configure it now. If you've already done it on a website then you already know what to do now. For those who haven't you have to follow just a couple of steps.

  • Configure the connection to the database.
  • Create a login for the admin of WordPress. 

You can access the WordPress installation wizard by entering your Raspberry Pi IP address in any browser on the same local network.

WordPress configuration
Configuring WordPress

Click the Let's Button.

On the next screen, fill the form with the MySQL user we created before. If you followed this tutorial's every command then your filled form should look something like this:

Database connection of Word Press
WordPress Database Connection

After entering everything Submit the form and the wizard will ask you to run the installation.

Next you will be asked to enter the information needed like Site Title, Username, Password, and Email. After entering everything click on the Install WordPress button.

WordPress information needed
Enter the Information needed

It will most likely take just a few moments.

Step 5: Installing WordPress on Raspberry Pi: Success!

The configuration of WordPress is successful. To login to your WordPress, go to http://localhost/wp-admin.php. After entering the username and password you will be logged in into your WordPress account.

AdminPage of WorldPress
WordPress Admin Page

If you want to visit your website now just enter the Raspberry Pi IP address and now your WordPress website will appear.

Word Press website
WordPress Website

At this time, it appears that you will be limited to using your home network to access the website. You'll need a static IP address and manage port forwarding from your router to your Raspberry Pi in order to access your WordPress website from the Internet.

However, dynamic DNS providers can be used in their place if you can't afford the pricey static IP address. In essence, this connects your Raspberry Pi to a unique URL, albeit these services are usually paid. But there are free DNS providers as well that you can check out to.

You're done, and your Raspberry Pi is now hosting a WordPress website. The website will stay available for as long as the computer is on. 

SEO Tips for Your WordPress Site

To make your WordPress site SEO-friendly, consider the following tips:

  • Use an SEO Plugin: Plugins like Yoast SEO can help optimize your content.
  • Optimize Images: Compress and use alt text for images.
  • Use Clean URLs: Ensure your permalink structure is SEO-friendly.
  • Write Quality Content: Regularly post valuable content relevant to your audience.

Next Article

Similar Reads