WordPress is one of the most, if not the most, popular way of hosting a website today. You can setup a website using WordPress.com, but you can also host WordPress on your own Raspberry Pi. This tutorial will show you how to do exactly that.
What you will need
If you have not setup your Raspberry Pi with an operating system this tutorial will show you how that is done.
To get WordPress up and running on your Raspberry Pi you will need a few other components up and running first. These include a database, a web server and a programming language.
Apache Web Server
The most common web server which is used together with WordPress is the Apache Web Server. To install Apache on your Raspberry Pi, simply type the command.
# sudo apt install apache2 -y
In order to check that the web server has been setup correctly you can visit the site “raspberrypi.local” in your browser. It should look something like this.
WordPress uses the programming language PHP which is according to their website a general-purpose scripting language that is especially suited to web development. To install PHP on the raspberry Pi type the following command on its command line. It will install the programming language PHP on the Raspberry Pi and make it ready to be used for WordPress.
# sudo apt install php -y
To check that PHP works as expected we need to do some more things than just visit a website hosted on the Raspberry Pi.
Start by removing “index.html” placed in the folder “/var/www/html”
# rm /var/www/html/index.html
Next step is to create a file called “index.php” in the same folder with the following content.
# sudo nano /var/www/html/index.php
<?php phpinfo(); ?>
You also need to restart the Apache Web Server to verify that the PHP is working correctly.
# sudo service apache2 restart
When you now visit the same page as before you should see info about PHP instead of the Apache Web Server information.
The last component that WordPress needs in order to work properly is the database. In this case it is a database which is called MariaDB and is a fork of the more famous database Mysql.
The packages needed to install are the following.
# sudo apt install mariadb-server-10.0 php-mysql -y
When the database has been installed the Apache Web Server needs to be restarted once more to know about the changes.
# sudo service apache2 restart
Now when all the components needed by WordPress it is finally time to actually install WordPress onto the Raspberry Pi. We start by downloading the latest version of WordPress in the folder “/var/www/html” and removing the “index.php”
# cd /var/www/html # sudo rm index.php # sudo wget http://wordpress.org/latest.tar.gz
The downloaded file is a .tar.gz file and needs to be extracted in order to be used. (–strip-components=1 means that you will extract all the content in the folder “wordpress” directly to “/var/www/html”). Another good thing is to do some cleanup before we forget.
# sudo tar xzf latest.tar.gz --strip-components=1 # sudo rm latest.tar.gz
Another thing that is easy to forget is to set ownership of all the newly created WordPress folders to the Apache Web user. You do that by executing the following command in the “/var/www/html” folder.
# sudo chown -R www-data: .
Configure MariaDB for WordPress
Before the MariaDB can be used one needs to configure the database properly. You start this configuration by typing the following command and follow the instructions. Below you can see the answers I used to get the MariaDB up and running. Y for Yes and n for No.
# sudo mysql_secure_installation
The last step for the MariaDB installation is to create the proper database and table structure for the WordPress Database. You do this by first open the MariaDB command prompt.
# sudo mysql -uroot -p
When you have entered the prompt you need to first create a database called “wordpress”, grant the proper access rights and as a last thing flush the last access rights. Make sure you replace “PASSWORD” with something else.
You exit the prompt by clicking Ctrl + D.
# create database wordpress; # GRANT ALL PRIVILEGES ON wordpress.* TO 'root'@'localhost' IDENTIFIED BY 'PASSWORD'; # FLUSH PRIVILEGES;
When all the commands has been executed it should look something like this.
Reloading the “rasberrypi.local” site should now show something like this.
Follow the instructions on the WordPress site and you should not be too far off before you have your very own WordPress site! When WordPress needs the Username it is “root” and the password is the password you were forced to enter in the “MariaDB configuration” stage.
In this tutorial we have successfully setup a WordPress site which is hosted on your Raspberry Pi. The next step is to configure the site to be just the way you want it to be, with plugins and themes. You can check out the community around WordPress here.
If web sites is not enough for you, maybe you should checkout how to create your very own speaker with a Raspberry Pi? You find the tutorial here.