Install a complete WordPress host in a Raspberry Pi

5
(1)

Creting a personal blog can give a lot of satisfaction for all, but not all the times you can have enough money to afford the very first costs. With a WordPress on Raspberry PI you can start with the cost of a cheap boar

When I received my first Raspberry PI Model A+, I was excited to test it by building up my home-made new WordPress host on it. And peppe8o.com started its very first days from an RPI hosting at home.

You can also create your own blog starting with a cheap investment. In order to reach and publish your website on Internet, you will also need:

  • you will need a public IP from your provider and a domain name (also dynamic domain names are good)
  • also to be able to setup your local network to forward ports 80 (for http) and 443 (for https)

My NoIP guide can be helpful also for this stuff.

This tutorial will provide a step-by-step guide to installing a complete WordPress host in a Raspberry Pi. Even if it is created on Raspberry PI 3 Model A+, the same procedure applies also to other Raspberry PI computer boards.

What we need

As usual, I suggest adding from now to your favourite e-commerce shopping cart all needed hardware, so that at the end you will be able to evaluate overall costs and decide if continue with the project or remove them from the shopping cart. So, hardware will be only:

Check hardware prices with the following links:

Amazon raspberry pi boards box
Amazon Micro SD box

Step by step guide

Prepare Operating System

First of all, we’ll install Raspberry PI OS Lite. Make sure that your OS is up to date. From your terminal, please issue the following command:

sudo apt update -y && sudo apt upgrade -y

Next step is installing the so-called LAMP stack (Linux + Apache + MariaDB + PHP). For this task, you can use my LAMP server on Raspberry PI tutorial.

Now let’s face the required packages. WordPress requires the following PHP extensions:

  • json: MANDATORY
  • mysql: MANDATORY (alread installed following my LAMP tutorial)
  • curl > we’ll install it
  • dom: included in php-xml > we’ll install it
  • exif: already included in php-common
  • php-fileinfo: already included in php-common
  • hash: already included in RPI OS
  • imagick > we’ll install it
  • mbstring > we’ll install it
  • openssl: already included in RPI OS
  • pcre: not located in apt
  • xml > we’ll install it
  • zip > we’ll install it

Moreover, the following PHP extensions can be helpful in some cases:

  • bcmath > we’ll install it
  • filter: not located in apt
  • gd > we’ll install it
  • iconv: already included in php-common
  • intl > we’ll install it
  • mcrypt > we’ll install it
  • simplexml: already included in php-xml
  • sodium: not located in apt
  • xmlreader: already included in php-xml
  • zlib: not located in apt

You can install all the missing PHP extensions with the following command:

sudo apt install php-json php-curl php-imagick php-mbstring php-xml php-zip php-bcmath php-gd php-intl mcrypt -y

After these installations please restart Apache Web server:

sudo systemctl restart apache2

Installing WordPress

Download the latest WordPress version:

wget https://wordpress.org/latest.zip

extract the zip archive

sudo unzip latest.zip

move the extracted directory (“wordpress”) and all its content to Apache web root (replace example.com with your real domain name)

sudo mv wordpress/ /var/www/example.com

Configure MariaDB for your WordPress Site

Log into MariaDB shell as root

sudo mariadb -u root

create a database for WordPress (I called it wordpress, but you can name it as you prefer):

create database wordpress;

grant all privileges of WordPress database to the user that you will configure in WordPress in next steps:

grant all privileges on wordpress.* to wpuser@localhost identified by 'your-password';

Flush the privileges table for the changes to take effect and then exit

flush privileges;
exit;

Configure WordPress

Go to your WordPress directory and copy the sample configuration file

cd /var/www/example.com/
sudo cp wp-config-sample.php wp-config.php

edit the new config file

sudo nano wp-config.php

Find the following lines and replace the red texts with the database name, username and password you created in the previous step (Configure MariaDB for your WordPress Site).

/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

Save and close the file.
Set the Apache user (www-data) as the owner of the WordPress site directory:

sudo chown www-data:www-data /var/www/example.com/ -R

Create an Apache Virtual Host file for WordPress (change “example.com” with your domain name)

Create a virtual host file for your WordPress site

sudo nano /etc/apache2/sites-available/example.com.conf

Paste the following text into the file:

<VirtualHost *:80> 
  ServerName example.com
  ServerAlias www.example.com
  DocumentRoot /var/www/example.com
  #This enables .htaccess file, which is needed for WordPress Permalink to work. 
  <Directory "/var/www/example.com">
    AllowOverride All
  </Directory>
  ErrorLog ${APACHE_LOG_DIR}/example.com.error.log
  CustomLog ${APACHE_LOG_DIR}/example.com.access.log combined
</VirtualHost>

Save and close.

Save and close the file. Test configurations:

sudo apache2ctl configtest

If you see “Syntax OK” (even if after the “Could not reliably determine the server’s fully qualified domain name” warning), then enable rewrite and the virtual host, reload Apache for the changes to take effects:

sudo a2enmod rewrite
sudo a2ensite example.com.conf
sudo systemctl reload apache2.service

Now we can start the WordPress Wizard setup in our browser.

Here you must set port forwarding rules in your home router (at least for ports 80 and 443). But you can also test your installation by making your local PC aware that example.com (or the domain we set in previous steps) link to our raspberry. For this reason, once known our raspberry local IP, you can set our host file redirecting to it. You can find the hosts file in:

  • C:\Windows\System32\drivers\etc\hosts for windows-based PC
  • /etc/hosts for linux based PC

by adding (via notepad) the following row to the end (please change <<Your.Raspberry.IP.Here>> with the IP address of your raspberry):

<<Your.Raspberry.IP.Here>> example.com

Finally, you can launch the final WordPress wizard: browse “http://example.com/wp-admin/install.php”. The wizard will ask you to select your language:

wordpress installation language

Select your one and press “Continue”. The following page will require you to set:

  • Site title
  • WordPress administration user
  • WordPress administration password
  • WordPress administration email
wordpress installation admin credentials

Again, set it according to your preferences and click the “Install WordPress ” button. A final page will confirm the successful installation:

wordpress installation complete confirm

Use the “Log in” button to go to the login page:

wordpress login page

Use the admin credentials above defined to enter your WordPress dashboard:

wordpress dashboard

What’s Next

Interested in more cool ways to use your RPI? Take a look at peppe8o Raspberry PI computer tutorials!

Enjoy!

How useful was this post?

Click on a star to rate it anonymously!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?