*UPDATED* December 2017 for Raspbian Stretch. The Pi’s low power consumption makes it well suited to the role of always-on web server. This post describes how to install WordPress on the Raspberry Pi and get a blog going. Hosting your own blog means you keep ownership of your own data, and you are not dependant on blogger.com or whoever.
If you have already installed WordPress and just want to upgrade it, perhaps because a new version has been released, please see my article How to Upgrade WordPress on Linux
This procedure is designed for Pis running Raspbian 9 (“Stretch”), released in Summer 2017, and has been tested on the 29th November 2017 release.
Install the Apache web server with these commands. It might take 10 minutes or so to complete. A few other packages will also be installed.
pi@raspberrypi ~ $ sudo apt-get update pi@raspberrypi ~ $ sudo apt-get install apache2
Now install PHP by typing:
pi@raspberrypi ~ $ sudo apt-get install php7.0
A number of dependant and associated packages will also be installed.
Install the MySQL Database
WordPress keeps all of your posts and other data in a MySQL database. Install MySQL. We will use the “-y” flag this time, to automatically answers “yes” to the yes/no install question.
pi@raspberrypi ~ $ sudo apt-get install -y mysql-server
Be patient while the database installation completes. It can take about 10 minutes.
Increase MySQL Security
Now secure the MySQL installation. Run the script /usr/bin/mysql_secure_installation. It will first ask you to enter the “current password for root”. No password has been set yet, so just press return to log in. Next, it asks you if you want to set a root password. Answer “y“, choose a sensible password and make a note of it. Then answer “y” to all of the remaining questions, as below.
pi@raspberrypi:~ $ sudo /usr/bin/mysql_secure_installation Enter current password for root (enter for none): OK, successfully used password, moving on... Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Remove anonymous users? [Y/n] y Disallow root login remotely? [Y/n] y Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y ... Thanks for using MariaDB!
Test the Database
Test the MySQL installation by logging into MySQL and out again. It will ask for the password chosen earlier:
pi@raspberrypi:~ $ sudo mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 12 Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> exit Bye
Create the Database
Create the database and create a user for WordPress. Again you must enter the password. In the example I have called the wordpress user “wpfred” with a password of raindrop. For your own installation, choose a different user name and password. Don’t forget to take a note of both.
pi@raspberrypi:~ $ sudo mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 14 Server version: 10.1.23-MariaDB-9+deb9u1 Raspbian 9.0 Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]> create database wordpress; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> create user wpfred; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> set password for wpfred = password("raindrop"); Query OK, 0 rows affected (0.01 sec) MariaDB [(none)]> grant all PRIVILEGES on wordpress.* to wpfred@localhost identified by 'raindrop'; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> exit; Bye
That does it for the database.
Proceed as follows.
pi@raspberrypi ~ $ sudo apt-get install -y wordpress
WordPress will install, along with many associated packages.
Now, restart the Apache web server so that it will work properly with the WordPress packages just installed. Use the command:
pi@raspberrypi ~ $ sudo service apache2 restart
Note that this command does not print any messages to the terminal.
Create a link from your Apache installation to the WordPress directory. Here, I have called the link “myblog”.
pi@raspberrypi ~ $ sudo ln -s /usr/share/wordpress /var/www/html/myblog
Copy the default configuration file into place and edit it:
pi@raspberrypi ~ $ sudo cp /usr/share/wordpress/wp-config-sample.php /etc/wordpress/config-default.php pi@raspberrypi ~ $ sudo vi /etc/wordpress/config-default.php
(many thanks to Gene Shiau for the above commands. For more info, see /usr/share/doc/wordpress/ README.debian)
Change the lines for DB_NAME, DB_USER and DB_PASSWORD near the top of the file. In the example I have entered the user and password defined above.
So this part of the config-default.php file changes from
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'database_name_here'); /** MySQL database username */ define('DB_USER', 'username_here'); /** MySQL database password */ define('DB_PASSWORD', 'password_here');
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wpfred'); /** MySQL database password */ define('DB_PASSWORD', 'raindrop');
Save the file.
Fill in the WordPress Welcome Form
Now start a web browser and surf to http://<ip address of your Pi>/myblog
For example, my Pi’s IP address is 192.168.1.90, so I surf to http://192.168.1.90/myblog
Note: If you see an error message in the browser like this: “Neither /etc/wordpress/config-pi.php nor /etc/wordpress/config-pi.php could be found. Ensure one of them exists, is readable by the webserver and contains the right password/username”.
… then please check again that you copied the default wordpress configuration file from /usr/share/wordpress/wp-config-sample.php to /etc/wordpress/config-default.php, as instructed above. Just check it by running more on the file now:
pi@raspberrypi ~ $ more /etc/wordpress/config-default.php
…and you should see the contents of the file.
Fill out the form, entering a title for your blog, and entering a name for the admin user. (Note: do not choose “admin”, as it is easy to guess. Choose something else, perhaps your own name, say followed by a number, like “mike382”). Enter a secure password and keep a note of it, or use the password already filled in. Enter an email address where indicated.
Next, click the “Install WordPress” button, and wait a couple of minutes while WordPress completes the installation.
Log in to WordPress
You will see a page saying “Success!” and a button to log in. Click that, and log in, with the user name and password you chose earlier.
The WordPress Dashboard will appear. Congratulations! You have successfully installed WordPress on your Raspberry Pi.
A Note on Speed
When a user visits your blog, a large post will load into their browser in about 2 seconds, if you are running WordPress on a Raspberry Pi 2 or 3. In order to make posts load faster, I would recommend using the wp-super-cache plugin for WordPress. Wp-super-cache will create and serve cached copies of each post, which will load into the visitor’s browser in less than a second. Even if you decide not to use caching, a load time of 2 seconds will still make your blog faster than many Internet sites.
A Note on Security
If you plan on making the blog internet-facing, make sure that the WordPress user and password is properly secure and hard to guess. There are many guides on the Internet offering more WordPress security tips.