Note: This article is part of a series. See the Index for more information.
Self-promotion: I’ve recorded this series as a screencast for Pluralsight:
If you have a Pluralsight subscription, please consider watching it. Thanks!
Updates: I haven’t had any reports of trouble with this post since the Jessie release of Raspbian came out, so I’m assuming it all still works until I hear otherwise.
The Raspberry Pi can do more than just share things inside your own house. It can host websites and blogs that you make available to the public. Why you’d want to do this rather than just put up a free blog on wordpress.com, well, that’s a question you’ll have to answer for yourself. I’m not judging. I’m just going to show you how to set it up.
Create WordPress database
Way back in part 4 of this series, you installed a LAMP stack. If you recall, the “M” was for “MySQL”, and while we haven’t done anything with it yet, it’s been there, waiting for someone to put it to use. The WordPress blog engine is going to use MySQL to store all of the content for a blog. Get yourself logged in as “pi”, and enter the following commands at the command prompt, replacing the highlighted passwords with something of your choice.
sudo mysql -uroot -p create database wordpress; create user wpuser; set password for wpuser = password("PASSWORD"); grant all privileges on wordpress.* to wpuser@localhost identified by 'PASSWORD'; exit sudo service mysql restart
Let’s break that down:
- Open the MySQL command-line utility, logging in as root.
- Create a brand-new database for WordPress to put stuff in.
- Create a service account WordPress will use to talk to the database.
- Set a password on that service account for WordPress to use when authenticating.
- Make the service account the owner of everything in the new database.
- Exit the MySQL command-line utilty
- Restart MySQL to apply the changes
WordPress will be installed just like everything else, using apt-get.
sudo apt-get install wordpress
Next, you’ll create a “symbolic link”, which means that all references to one address will be redirected somewhere else. Specifically, anything trying to get to http://SERVERNAME should go to the WordPress folder instead.
sudo ln -s /usr/share/wordpress /var/www
In the Linux world, almost everything maps into one unified file structure, even things that aren’t actually files, like web addresses. Just roll with it. Next, copy the provided sample configuration file into WordPress’ folder.
Note: Enter this all as one line, even though it’s wrapped here.
sudo cp /usr/share/wordpress/wp-config-sample.php /etc/wordpress/config-default.php
Edit the configuration file you just copied, replacing the DB_NAME, DB_USER, and DB_PASSWORD settings with values matching what you used in the previous step.
sudo nano /etc/wordpress/config-default.php
Exit Nano, saving your changes (ctrl-x, y, enter). Restart the Apache webserver so that it will notice the changes.
sudo service apache2 restart
The result should look something like this:
WordPress, being a web-based product, handles most of its configuration through its own web interface. Open a browser to your Raspberry Pi’s address, with an additional “/blog” on the end. That redirect you set up earlier will send the browser to WordPress, which will prompt for some initial values, and then complete its own installation.
Provide a title for your blog, a password for the admin user, and an email address that won’t work without some additional configuration anyway, and click “Install WordPress”
WordPress will do some initial configuration in the background, and let you know when it has finished.
Click the “Log In” button to go to the Log In form, where you’ll need to provide the name and password you just established.
You’ll be taken to the WordPress Dashboard page. The care and feeding of a WordPress site is beyond the scope of this article, but I would like to point out one more thing that you’ll need to check. The addresses used by WordPress for things like links and style sheets are absolute addresses which include the name of the server. That server name might be set to “localhost” or an internal IP address right now.
As it stands now, the WordPress site works for your internal network, but not for the rest of the world. If you try to look at the site from somewhere other than your home network, it may look something like this:
You need to fix the addresses so that they work from outside. You can use a static IP address, a domain name (if you own one), or a dynamic DNS service like DynDNS or no-ip.
Navigate to http://localhost/blog/wp-admin, and log in with the credentials you established above. From the navigation menu on the left, go to Settings –> General
In the “General Settings” section, replace “localhost” or your internal IP address with an externally usable name or address in the “WordPress Address” and “Site Address” fields, and click the “Save Changes” button at the bottom of the page.
You should now be able to see the full site from other computers, whether they are on your home network or not.
I’m currently working on more jobs for the Raspberry Pi to do, and will add them to the series as I complete them. When that happens, I’ll update this article to link to them. For right now, though, this is the end of the line.