Hosting A Website On Raspberry Pi Using WordPress & Docker – Episode 10

21, Feb 2021 | Raspberry Pi 4 Series | 4 comments

Today we are going to be hosting a website on Raspberry Pi Using WordPress & Docker. We are also going to use NGINX Proxy Manager to make our WordPress website accessible from the Internet.

This is episode 10 in our Raspberry Pi Series. If you have not seen our other episodes It would benefit you greatly to go through them all so you have everything installed and configured the same as our system.

If you chose to go it alone that is also fine. We will outline below what you will need to save you some time.

Difficulty=Medium

Some considerations to self-hosting a website on Raspberry Pi.

A Raspberry Pi 4 should have plenty of resources to host a small to medium website to the outside internet. With its improved RAM capacity and overall hardware improvements, it should handle basic hosting ok.

Every network and setup is different but there may be a few areas that could cause bottlenecks.

Network speed plays a big part in delivering a fast response to your website viewers. A slow connection will also struggle to serve simultaneous connections. It is very important to make sure if you are going to self-host a WordPress website that your Internet speed is up to par.

Installing your Raspberry Pi OS on an SD Card is not the best idea for this setup. Instead Installing your Raspberry Pi OS on an SSD or USB Flash drive would be much faster at serving web pages. It will also be more reliable as an SD card is prone to data write limitations and could corrupt at any time. (A ticking time bomb?).

Prerequisites:

You will need to have followed our previous episodes in our Raspberry Pi Series but if you just want to follow this guide we will give an overview of what you should already have:

Hosting a website on Raspberry Pi 4

Lets get started.

Step 1 – Create a Cloudflare Domain/Subdomain

Navigate to your Cloudflare and log in with your account details.

Click on your “domain name” and then on the “DNS” tab.

If you want to use your main Domain name you can add this to NGINX Proxy Manager but in our example we are going to create a subdomain to point to our WordPress container.

Click on “Add record“.

Under “Type” select “CNAME

Under “Name” type “wordpress“.

Under “Target” type “@“.

Under “Proxy status” select the icon so it goes grey and says “DNS only“.

Click “Save“.

Step 2 – Create WordPress data folders using Openmediavault 5.

Log into your Openmediavault interface and go to “Shared Folders“.

Confirm you have a shared folder added to store your docker containers. You can name this folder anything you like. In our example, we call the folder “Appdata“. If you would like to know how to create this folder we have covered this in our previous Raspberry Pi series episode.

Step 3 – Create A Stack & Deploy WordPress Containers in Portainer.

Go to your Portainer interface and log in. Click on “Stacks” then “Add Stack

Name your Stack “wordpress” and copy and paste the following docker-composed data into the “Web editor” field

version: '2.1'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8383:80
    environment:
      PUID: 1000
      PGID: 100
      WORDPRESS_DB_HOST: db
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: changeme
      WORDPRESS_DB_NAME: wordpress
    volumes:
      - /PATH TO FOLDER/wordpress:/var/www/html

    links:
      - db:db

  db:
    image: ghcr.io/linuxserver/mariadb
    environment:
      - PUID=1000
      - PGID=100
      - MYSQL_ROOT_PASSWORD=changeme
      - TZ=Europe/London
      - MYSQL_DATABASE=wordpress
      - MYSQL_USER=wordpress
      - MYSQL_PASSWORD=changeme #Must match the above password
    volumes:
      - /PATH TO FOLDER/Wordpressdb:/config
    ports:
      - 3333:3306
    restart: unless-stopped

volumes:
  wordpress:
  db:

Edit the fields to match your requirements. Be sure to change the PUID and GUID to match your pi user account, as well as folder locations.

Also, change the “changeme” password fields to something more secure.

Note: Make sure the user names and passwords match in both parts of the stack.

Once you have set all the required fields with your values you can navigate to the bottom of the stack page and click on “Deploy the stack“.

Click on Containers to confirm that two new containers have been added once for WordPress Application files and the other for the WordPress MariaDB database.

Click on the log icon to check both container logs to make sure they are all running ok. You should see the following in wordpress_db (Mariadb).

Also your WordPress docker logs should look similar to this.

If your logs look similar to ours then you are good to move on to the next Step.

Step 4 – Creating WordPress Proxy Host entry in NGINX Proxy Manager.

Navigate to your NGINX Proxy Manager interface. Click on “Proxy Hosts“.

Then click on “Add Proxy Host“.

Add your domain or subdomain to “Domain Names“.

Add your Pi IP address to “Forward Hostname/IP

Add your WordPress port to “Forward Port“.

Click “Block Common Exploits

Your “New Proxy Host” should look like this.

Click on the “SSL” tab.

Under “SSL Certificate” click “Request a new SSL Certificate“.

Then make sure “Force SSL” , “HTTP/2 Support” and “I Agree to the Let’s Encrypt Terms of Service” are green ticked and click “Save“.

Due to a bug in NGINX Proxy Manager, you will need to click the hamburger menu and check the “SSL” settings were saved correctly. If not re-tick the same buttons and then “Save” again.

Step 5 – Installing WordPress.

You can now use your fully qualified domain name (FQDN) to access your WordPress installation page. You should also see that you have successfully added a TLS/SSL certificate to your website.

Select your language and click “Continue“.

Add a “Site Title“, “Username“, “Password”, “Confirm Password“, “Your Email“, and tick the “Search engine visibility” checkbox.

Notice: Use secure unique username and passwords.

Click on “Install WordPress“. This may take a little while to complete.

Once the installation process has completed you should be taken to the Administrator log in page.

Enter your “Username” and “Password” and press “Log In

You should now have a working WordPress website.

Step 6 – Finalizing Cloudflare settings.

You will now need to do two final things in Cloudflare to complete the domain setup.

Navigate to Cloudflare and log in using your account details.

When in the Clouldflare dashboard click on the “DNS” tab.

Go to your domain or subdomain name and click on “DNS only” under “Proxy status“. Make sure that you change the grey cloud logo to an orange color and that the status says “Proxied“.

Once done click “Save“.

Troubleshooting any problems

The final thing to do and it is to prevent a redirection loop from happening when trying to access your WordPress website. If you ever see the following you will need to make this extra change in Cloudflare.

In Cloudflare click on “SSL/TLS” tab.

In this section change your SSL/TLS encryption mode from “Flexible” to “Full“. It should auto-save the settings.

You can now visit your website and you should be able to access it as normal.

Hosting a website on Raspberry Pi 4

Well done you did it.

We need your support.

We hope you enjoyed this episode and that it was helpful and you got benefit out of it.

If you did, please consider supporting our channel by Subscribing to our YouTube channel, and liking and sharing our content.

You can also make a donation via Paypal or become a Patreon if you wish to do so.

You can also follow us on Facebook or Twitter.

If you have any questions or any requests please ask in the comments below or on YouTube.

4 Comments

  1. LeMaBe

    Hey,
    i have run into two problems:

    1. MariaDB reports that “Server doesn’t support dates later than 2038”

    Fix: https://docs.linuxserver.io/faq#libseccomp

    2. YML File for WebStack is incorrect and does not worke as a drop in File
    MariaDB Config does not match WordPress Credentials

    MYSQL_DATABASE=dashboard
    MYSQL_USER=dashboard

    Does not match with

    WORDPRESS_DB_USER: wordpress
    WORDPRESS_DB_NAME: wordpress

    Fix:
    MYSQL_DATABASE=wordpress
    MYSQL_USER=wordpress

    IMPORTANT: Do not use “space” between the equal sign and string

    Reply
  2. mjeshurun

    Hi,
    Can you please explain how we can increase the maximum file upload limit for wordpress?
    I followed your instructions and was able to create the wordpress website on my Raspberry Pi, but when I tried to upload a new wordpress theme, I got the following message:
    “The uploaded file exceeds the upload_max_filesize directive in php.ini.”
    Hope you can help.

    Reply
  3. ArnoOel

    Hi,
    Brilliant content, thanks a lot!

    I installed NextCloud and all working great, but when I installed WordPress, i getting page not working for both now. I tried the ‘Test Server Reachability’ from Nginx and get an error of ‘There is a server found at this domain but it returned an unexpected status code 614’
    Any idea how to fix and proceed
    Thanks

    Reply
  4. Romain

    Any advise if we want to host a static website, not a wordpress ? Where can we put the html, css, js files ?

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

<a href="https://addictedtotech.net/author/attadmin/" target="_self">Addicted2Tech</a>

Addicted2Tech

We love technology and enjoy sharing helpful FREE content for others to enjoy. We believe in community. If you like what we do please support us by sharing and liking our tutorials & Subscribing to our YouTube channel. You can also follow us on social media.

Support Our Work!

Donate Via Patreon




Raspberry Pi 4 Model B 8GB

Last update on 2024-03-28 / Affiliate links / Images from Amazon Product Advertising API

CanaKit Raspberry Pi 4 Extreme Kit – 128GB Edition (4GB RAM)

Last update on 2024-03-28 / Affiliate links / Images from Amazon Product Advertising API




We Are An Affiliate!

Just so you know, we may collect a share of sales or other compensation from the links on this page. As an Amazon Associate, I earn from qualifying purchases.

The affiliate link recommendations come at no extra cost to you.

We hope you love the products we recommend!

Thank you if you use our links; we really appreciate it!




Related Posts