Open In App

How to Install WordPress on Raspberry Pi?

WordPress is a useful tool for managing websites. You can set it up on a Raspberry Pi, and I’ll give you a step-by-step tutorial on how to install a working WordPress on a Raspberry Pi. There are several Raspberry Pi models available. You may have one, a few, or none at all. But which one is the best ideal for operating WordPress.

Happily, every version of the Raspberry Pi can be used to host a WordPress site. However, I advise using a Raspberry Pi 2 or later to get the best results. Furthermore, make sure you’re using a bigger SD card, preferably one with at least 16GB of capacity, as this is a crucial need for web servers.



You must configure a Raspberry Pi as a LAMP server in order to install WordPress on it. Your Pi will be able to run WordPress after having Linux, Apache, MySQL, and PHP installed. 

The rest of this guide is dependent on your Raspberry Pi being turned on and connected to your local network. For remote command line access, you should also have SSH set up. SSH is a secure remote connection technology that enables you to give commands from another computer on the network. I strongly recommend using SSH for the rest of this guide, as it will be much simpler to copy commands, test, etc. from your usual computer.



On a Raspberry Pi, the service doesn’t start by default. So, before moving on, let’s enable SSH and connect to it.

GUI

To enable SSH from Graphical User Interface go to applications menu then Preferences > Raspberry Pi Configuration > Interfaces. Click on Enable for the SSH.

Terminal

You can also launch the terminal and type this command to enable SSH:

sudo service ssh start

Autorun on Boot

When the Raspberry Pi is started, the SSH service is not launched automatically. You can type the following code to enable SSH after reboot:

sudo crontab -e

And adding this line:

@reboot /usr/sbin/service ssh start

Downloading and Installation of WordPress on Raspberry Pi

Follow the further steps to install WordPress on Raspberry Pi

Step 1: Setting 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.

 

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.

sudo apt install php -y

Installing PHP

cd /var/www/html/

sudo rm index.html

sudo nano index.php

<?php echo “hello world \n”; ?> <?php echo date(‘Y-m-d H:i:s’); ?> <?php phpinfo(); ?>

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

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: Installing Database Server on Raspberry Pi

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.

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.

sudo mysql -uroot

CREATE USER ‘wordpress’@’localhost’ IDENTIFIED BY ‘password’;

CREATE DATABASE wordpress;

GRANT ALL ON wordpress.* TO ‘wordpress’@’localhost’;

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.

mysql -u wordpress -p

SHOW DATABASES;

quit

If you can at least see the WordPress database, you can move on to the actual 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.

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

sudo unzip wordpress.zip

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:

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.

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

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:

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.

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.

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.

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. 


Article Tags :