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
My Raspberry Pi was purchased from New It in the UK and runs Debian 7 (“Wheezy”).
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
PHP should install automatically at the same time. If not, install it by typing:
pi@raspberrypi ~ $ sudo apt-get install php5
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.
pi@raspberrypi ~ $ sudo apt-get install mysql-server
Note: You will be prompted to enter a password for the MySQL ‘root’ database user. Choose a suitable password and make a note of it.
Be patient while the database installation completes. It can take half an hour.
Test the MySQL installation by logging into MySQL and out again. It will ask for the password chosen earlier:
root@raspberrypi:~$ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 42 Server version: 5.5.28-1 (Debian) Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> quit Bye
Increase MySQL Security
Now secure the MySQL installation. Run the script /usr/bin/mysql_secure_installation. It will ask for the password chosen earlier. Answer “yes” to all of the questions, except the first one about changing the root password. I have removed much extraneous output from the example:
pi@raspberrypi ~ $ sudo /usr/bin/mysql_secure_installation Enter current password for root (enter for none): Change the root password? [Y/n] n 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 MySQL!
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.
root@raspberrypi:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 44 Server version: 5.5.28-1 (Debian) Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. mysql> create database wordpress; Query OK, 1 row affected (0.00 sec) mysql> create user wpfred; Query OK, 0 rows affected (0.00 sec) mysql> set password for wpfred = password("raindrop"); Query OK, 0 rows affected (0.00 sec) mysql> grant all PRIVILEGES on wordpress.* to wpfred@localhost identified by 'raindrop'; Query OK, 0 rows affected (0.00 sec) mysql> exit Bye
That does it for the database.
Proceed as follows.
pi@raspberrypi ~ $ sudo apt-get install wordpress
WordPress will install, along with many associated packages.
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/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 ~ $ 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, if your Pi’s IP address is 192.168.1.90, 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 leaving the user name as “admin”. Enter a secure password and keep a note of it. Enter an email address where indicated.
Next, click the “Install WordPress” button.
You will see a page saying “Success!” and a button to log in. Click that, and log in as user admin, using the password you chose earlier.
The WordPress Dashboard will appear. Congratulations! You have successfully installed WordPress on your Raspberry Pi.
A Note on Speed
In order to make your blog posts load with acceptable speed, I would recommend using the wp-super-cache plugin for WordPress. That would be true whatever hardware you were using, but it is especially important with the Pi, which has limited CPU power to process the MySQL database. With wp-super-cache, your blog will be plenty fast, with pages loading in just a couple of seconds.
A Note on Security
If you plan on making the blog internet-facing, I would recommend removing the “admin” user and replacing it with am administrative account with a less guessable name. And with a properly secure password that cannot be easily guessed. There are many guides on the internet offering more WordPress security tips.