In this Raspberry Pi WordPress tutorial, you will learn how to set up the popular CMS on your 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
--------------------------------------------------
Raspberry Pi 2, 3 or 4
Micro SD Card
Power Supply
Ethernet Cord or Wifi dongle (The Pi 3 and 4 has WiFi inbuilt)
Setting up WordPress on a Raspberry Pi
--------------------------------------------------
Before you start this tutorial make sure you have set up Apache and PHP. You will also need to have an 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/html” directory on our Raspberry Pi.
We will also need to take ownership of the “/var/www/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/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 pi
sudo chown -R -f www-data:www-data /var/www/html
2. 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
3. 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;
4. 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 set up 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';
6. 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.
7. 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 be greeted with the following screen asking for you to select a language.
8. The next page will explain the details you need to have handy to install WordPress. You can just press “let's go” to get to the important screen.
9. 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
10. 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 set up on the Raspberry Pi and accessible. If you run into any issues, then be sure to let us know by leaving a comment.
cd /var/www/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 pi
sudo chown -R -f www-data:www-data /var/www/html
sudo mysql -u root -p
create database wordpress;
CREATE USER 'new_user'@'localhost' IDENTIFIED BY 'new_password';
GRANT ALL ON wordpress.* TO 'new_user'@'localhost';
Comments
Post a Comment