How to Setup WordPress on the Raspberry Pi

For those who do not know, WordPress is a content management system that is used by over 60 million websites. It is very popular amongst bloggers, but is also used by large websites such as TechCrunch.

I currently have WordPress running on my Raspberry Pi to act as a development server as it’s faster than using something like XAMPP.

Setting up WordPress on the Raspberry Pi is not hugely complicated. Once you have Apache, PHP and the MYSQL server set up, it is smooth sailing.

Before you go too far ahead in this tutorial, make sure that you have your MYSQL root password ready. We will be running through the steps to setting up a database for WordPress and showing you how to set up an SQL user to interact with the database all by using the MYSQL Command line.

If you’re interested then now is the time to set up WordPress on the  Raspberry Pi.

Equipment List

Below are all the bits and pieces that I made use of for this Raspberry Pi WordPress tutorial.

Recommended

Optional

  • Raspberry Pi Case
  • USB Keyboard
  • USB Mouse
  • HDMI Cable
  • Monitor

Setting up WordPress on a Raspberry Pi

Before you start this tutorial make sure you have setup Apache and PHP. You will also need to have a MYSQL server running and accessible. As I mentioned earlier, you will need to have your MYSQL root password ready.

1. To start, we need to download and extract WordPress to our “/var/www/your_domain/public_html” directory on our Raspberry Pi.

We will also need to take ownership of the “/var/www/your_domain/public_html” folder with the www-data” user and group. Doing this will allow PHP to process WordPress without running into any permission errors.

To achieve all of this, we will run a few commands, just type each line below into the terminal.

cd /var/www/your_domain/public_html

sudo wget http://wordpress.org/latest.tar.gz

sudo tar xzf latest.tar.gz

sudo mv wordpress/* ./

sudo rm -rf wordpress latest.tar.gz

sudo usermod -a -G www-data user

sudo chown -R -f www-data:www-data /var/www/your_domain/public_html

Now that WordPress is downloaded and extracted to our Raspberry Pi, we will also need to set up a database within MYSQL for WordPress to store its information.

We need to first use the MySQL command to login. Use the “–p” flag for the password and “–u” for the username. Make sure your password is written right next to the “-p tag with no space.

Note: Replace password with the one you set up for the root user when you setup MySQL

sudo mysql -u root -p

Now that we have logged into the MYSQL server, we can issue a command to create a database for WordPress using this simple line:

CREATE DATABASE wordpress;

Now we will create a separate user for this database, this is far safer from a security perspective.

While still in MYSQL issue the following command:

CREATE USER ‘new_user’@’localhost’ IDENTIFIED BY ‘new_password’;

Note: Make sure you replace new_user and new_password with details of your choosing, just remember what you choose as you will need to know both when we setup WordPress.

5. Once we have a new user, we will need to give it permissions to manage our new database.

We can do that with the command below, make sure you swap new_user, with whatever you entered in the previous step.

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

Now we have created our database and our user that we want to interact with it. We need to quit out of the MYSQL command interface.

We can do that by pressing CTRL + D.

 With that all done, we can now finally finish setting up WordPress, we can start this process by going to your Raspberry Pi’s IP address in a web browser.

You will now need to enter various details so that WordPress can connect to the MySQL database we setup.

  • Database Name – This is the database WordPress will connect to. Earlier in this tutorial we created a database called wordpress.
  • Username – This is the user we created in step 4, make sure you get this detail correct as it needs to connect to the above database.
  • Password – This is the password we set while creating the MYSQL user in step 4, again make sure you enter this correctly as it’s needed to connect to the database.
  • Database Host – Keep this to the default setting, we only need it to connect locally.
  • Table Prefix – Keep this to the default setting as well, there is no real need to change this

Assuming you entered all the correct details, you will now be able to press “Submit” to successfully install the software, follow the rest of the prompts to finalize the installation.

There is quite a bit more to learn about WordPress such as installing a WordPress theme or setting up plugins. Using a Raspberry Pi is a great way to learn all the basics without investing in an expensive web server.

You should now have WordPress setup on the Raspberry Pi and accessible.