DIY Raspberry Pi Web Server Wordpress

How to Host a WordPress Site on Raspberry Pi

Want a web server to host your WordPress site, but don’t have the funds? Perhaps you simply need to test some plugins or themes before rolling them out on the live site? Whatever the case, you can use a Raspberry Pi!

Here’s how to set up Apache, MySQL and PHP on your Raspberry Pi and host websites locally (on your own network) or on the web.

Why Use WordPress?

If you’re looking for a way to host a website with the minimum of fuss, WordPress isn’t the obvious solution. We’ve already looked at how to configure the Pi to host a static or dynamic website

Host Your Own Website On Your Raspberry Pi

Host Your Own Website On Your Raspberry Pi

Need to run a website but can’t afford the hosting costs? One way around this is with the low-powered Raspberry Pi, which is more than capable of running basic web server software.
Read More

(that is, one that relies on standard, prewritten pages, or a site that uses a database to populate pages).

Indeed, you might not even need a web server at all. The Itty Bitty project lets you create a web page

How to Create a Hosting-Free Website With Itty Bitty

How to Create a Hosting-Free Website With Itty Bitty

Need to create a web page but can’t afford web hosting? With Itty Bitty websites, you don’t need any hosting at all!
Read More

that is contained within its own URL.

But if you really need to use WordPress, or you’re developing a theme or plugins for a WordPress site, then having a Raspberry Pi with the web application installed and ready to use is a great option.

Which Raspberry Pi Should You Use?

To install WordPress on a Raspberry Pi, you’ll need to set it up as a LAMP server. With Linux, Apache, MySQL, and PHP installed, your Pi will then be able to handle WordPress (and other website software).

Raspberry Pi 3 and Raspberry Pi 3B+

Several models of Raspberry Pi are available. You might have one, several, or none. But which one is the most suitable for running WordPress?

Happily, any version of the Raspberry Pi can be used to host a WordPress site. However, for the best results, we recommend you use a Raspberry Pi 2 or later. Additionally, ensure you’re using a larger SD card—at least 16GB—as storage space is a key requirement for web servers. (Also consider some external storage for the Pi!)

The rest of this tutorial assumes that your Raspberry Pi is powered on and connected to your local network. You should also have SSH configured, for remote command line access.

Step 1: Set Up Apache Web Server

Start off by installing the Apache web server. This is software that lets you serve any type of webpage to any browser. It’s all you need to serve a HTML page, static or dynamically created with PHP.

sudo apt install apache2 -y

Once installed, Apache will drop a test HTML file into the web folder on your Pi. You should test this from another computer (or smartphone) on your network. You’ll need to enter the IP address of the Pi in the address bar of your browser. If you’re using SSH, you’ll know this already; otherwise, enter

hostname -I

This displays the IP address of your Raspberry Pi. The page you see should be something like this:

Apache server installed on Raspberry Pi

You can also check the web page works from your Raspberry Pi using the http://localhost address.

Step 2: Install PHP on Raspberry Pi

Next, it’s time to install PHP. This is a software pre-processor that enables the serving of server-generated web pages rather than static HTML pages. While an HTML page might be written in its entirety, a PHP page will feature calls to other pages, and the database, to populate it with content.

While other server-side platforms are available (such as ASP), PHP is vital here as it is required for WordPress because WordPress itself is written in PHP.

Install with:

sudo apt install php -y

Once this is done, you should test that PHP works. Change directory to /var/www/html/:

cd /var/www/html/

Here, delete the index.html file (the web page you viewed earlier):

sudo rm index.html

Next, create a new file, index.php with your text editor (nano is installed by default).

sudo nano index.php

Here, add any (or all) of the following code:

<?php echo "hello world"; ?>

<?php echo date('Y-m-d H:i:s'); ?>

<?php phpinfo(); ?>

In order, these commands display:

  • The phrase “hello world”
  • The current date and time
  • PHP info for the installation

Save the file, then restart Apache:

sudo service apache2 restart

Refresh the page to see the results.

PHP installed and working on Raspberry Pi

PHP and Apache are both working. Now it’s time to install the database software, MySQL.

Step 3: Install MySQL on Raspberry Pi

WordPress (and other dynamically generated website software) requires a database in order to store the content, links to images, and manage user access (among many other things). This project uses a fork of MySQL, called MariaDB:

sudo apt install mysql-server php-mysql -y

Once this is installed, you will once again need to restart Apache:

sudo service apache2 restart

As noted, other database options are available for this type of project. However, for the best results, especially if this is your first time configuring a web server, stick with MySQL.

Step 4: Install WordPress on Raspberry Pi

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

cd /var/www/html/
sudo rm *

The asterisk wildcard (*) deletes everything in the directory thanks to the rm (remove) command.

Download WordPress with wget

Next, use wget to download the latest version of WordPress:

sudo wget

Once downloaded, extract the contents:

sudo tar xzf latest.tar.gz

The wordpress directory should be created, but you want the contents of it in html. While you might move these manually using the desktop user interface, it’s simple to do this from the command line:

sudo mv wordpress/* .

Be sure to include the space and period at the end, which refer to the current directory!

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

Move the contents of the WordPress directory

Before proceeding, tidy things up a bit, discarding the downloaded file and the wordpress directory:

sudo rm -rf wordpress latest.tar.gz

Next, set the Apache user as the owner of the directory:

sudo chown -R www-data: .

Step 5: Configure MySQL

To set up the database, you’ll first need to run the installation command:

sudo mysql_secure_installation

You’ll shortly be prompted to set a root password. Follow the onscreen instructions, making sure you keep a note of the password, as it will be required later.

Once this is one, the following prompts will appear:

  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database and access to it
  • Reload privilege tables now

For each of these, tap Y to confirm. When done, the “All done!” message will be displayed.

Step 6: Create the WordPress Database

To install WordPress, you’ll first need to configure the database. Begin by running the mysql command, entering the password from earlier.

sudo mysql -uroot -p

This opens the MariaDB monitor. At the prompt, create the database:

create database wordpress;

Note how all commands within the MariaDB monitor end with a “;”. Next, the root user needs database privileges. Use your own password in place of PASSWORD.


Follow this by flushing previous database privileges:


Exit the MariaDB database management tool with Ctrl + D.

Step 7: Install and Configure WordPress

Installing WordPress is simple; if you’ve already done it on an existing website, you should know what to do.

Open the website in your browser (as described above). You should see the WordPress Setup screen. Select your language, then Continue, and make a note of what is required: the database name, username, password, host, and the table prefix (this is for the database tables).

If you made it this far, you should have named the database “wordpress”, and have a note of the password. The Username is root, and the host localhost. The Table Prefix is wp_.

Click Submit, then Run the install, and input the Site Title, along with the Username, and Password for your administrator account. Click Install WordPress, and wait as WordPress is (quickly) set up.

To login to your WordPress installation, go to http://localhost/wp-admin.

Installed WordPress site on a Raspberry Pi

At this stage, you have a site you can start using. Blog, or use as a more static website, using the options you’ll find in the settings screen. Our guide to getting started with WordPress

Set Up Your Blog With WordPress: The Ultimate Guide

Set Up Your Blog With WordPress: The Ultimate Guide

Want to start your own blog, but don’t know where to start? You should really look into WordPress, the simplest and most powerful blogging platform available today.
Read More

will help here. Don’t forget to choose a theme, and a few useful plugins. You’ll also need a method to access the site from the internet.

Access Your WordPress Site From the Internet

As things stand, you’ll probably only be able to access the site from within your home network. To change this, you’ll need a static IP address, and manage port forwarding from your router to your Raspberry Pi.

Static IP addresses are expensive, however, but you can use a dynamic DNS provider instead. This basically links a custom URL to your Raspberry Pi, although such services are often paid. Check our list of the best dynamic DNS providers

5 Best Dynamic DNS Providers You Can Lookup for Free Today

5 Best Dynamic DNS Providers You Can Lookup for Free Today

DynDNS was always a top mention when free dynamic DNSes were brought up. But now that it’s gone, are there any good alternatives? There sure are.
Read More

for full details.

Host a WordPress Site on Raspberry Pi: Success!

You’re all done now, and a WordPress site is running on your Raspberry Pi. As long as the computer remains powered up, the site will continue to be accessible. The process is straightforward too, requiring you to simply:

  • Install Apache, PHP, and MySQL
  • Download and install WordPress
  • Configure the MySQL database
  • Create your WordPress database
  • Configure WordPress
  • Launch the site and access it locally or via the web

Of course, you don’t have to use a Raspberry Pi for this. You might have a spare PC or laptop you can use to host a website. Meanwhile, if it’s simply for test services, you can install WordPress on your PC with Bitnami

How To Try Out WordPress, Joomla & More Quickly & For Free In a Virtual Machine With Bitnami

How To Try Out WordPress, Joomla & More Quickly & For Free In a Virtual Machine With Bitnami

We’ve talked about setting up a local server before, but the process is still fairly complicated and there’s lots of quirks and incompatibliities if you’re trying to run it on Windows, leading to nothing but…
Read More


Source link