Raspberry Pi Home Server: Part 13, WordPress

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:
(http://www.pluralsight.com/courses/raspberry-pi-home-server)
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

Install WordPress

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

image

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:

image

Configure WordPress

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”

image

WordPress will do some initial configuration in the background, and let you know when it has finished.

image

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.

image

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:

image

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

image

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.

What’s next?

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.

Advertisement
This entry was posted in Computers and Internet, Home Server, Raspberry Pi and tagged . Bookmark the permalink.

15 Responses to Raspberry Pi Home Server: Part 13, WordPress

  1. Pingback: Raspberry Pi Home Server: Index | MelGrubb.ToBlog()

  2. Pingback: Raspberry Pi Home Server: Part 12, The LAMP Stack | MelGrubb.ToBlog()

  3. Joel Sundberg says:

    Great tutorial/Howto =) You’re very good at explaining parameters etc, which makes it a lot easier to troubleshoot if something goes wrong. I’ve followed this guide from start to here and everything works just as you’ve described.

    One note about this step (13) the symbolic link should be “sudo ln -s /usr/share/wordpress /var/www/blog” (as in your screen shot. In the text you left out “/blog”.

    If you do take requests about bells and whistles I’d like to have the possibility to start XBMC as well;
    My Pi is attached to my TV via the HDMI and the original plan was to have XBMC (RaspBMC/OpenELEC/or-similar) always up and running and also use the Pi as a backup/media server. Reason for me ending up at your blog was the lousy speed when backing files up (solution = start from external HDD->Your step 6 ). Perhaps I can use that step with RaspBMC. But now I’ve so much other fun stuff installed and activated on the Pi… 😉

    Thank you so much for sharing your knowledge.
    Have a great 2015!

    • Mel Grubb says:

      Thanks. I’ll update the text when I can. I have played some with xbmc, but not on the same Pi. This series was specifically about making a home server. For xbmc, I haven’t really gotten anything dialed in just yet, and it’s pretty well covered elsewhere.

  4. Stephen Wass says:

    When i get to the part of your tutorial and it says enter your hostname followed by /blog i get the error

    Not Found

    The requested URL /blog was not found on this server.

    Apache/2.2.22 (Debian) Server at 192.168.1.6 Port 80

    Any idea whats going on? I also got open vpn to work and i gave up on crashplan

    • Mel Grubb says:

      It’s been quite a while since I did the article on WordPress, and it’s possible that something in the installer has changed, but I think the problem is most likely with the symbolic link. Double check that the link was set up correctly, and that listing the contents of /var/www showed the contents from /usr/share/WordPress. ________________________________

    • bobcrables says:

      I got the same problem. To fix this, run these magic words:

      sudo mv /var/www/wordpress /var/www/html/wordpress

  5. gilad says:

    This does not seem to work.
    I did the symbolic link as mentioned in the remark above, and when I do:
    ls /var/www/blog
    I see the contents of /usr/share/wordpress
    also
    ls -l /var/www
    shows that blog is a symlink to /usr/share/wordpress

    However I get a “not found” error when trying http://serverip/blog.

    (Doing http://serverip/ gives me the Apache welcome screen)

    • gilad says:

      Problem solved.
      It seems that the www root for apache is not /var/www but rather /var/www/html (this is where its index.html file located)
      Changing the symbolic link to:
      sudo ln -s /usr/share/wordpress /var/www/html/blog
      solved the problem

      • Mel Grubb says:

        It’s possible that this has changed in a more recent release than when I wrote the article. The last time I rebuilt the server (before Jessie was released), the instructions still worked for me. Most recently, I built a nearly-complete server as a check, but did not do the LAMP or WordPress steps. Maybe this coming weekend I’ll pick it back up and try to complete the whole thing and see if my results match yours. The whole series needs revisited since Jessie came out. Hopefully the added notes at the top can hold people over until then.

  6. gilad says:

    I know this is not a WordPress tutorial, but maybe you could help me with something.
    I want to install a theme or a plugin – a screen comes up and asks for the FTP credentials. I assume that WP needs to upload the theme/plugin files from its repository to my PI
    If I followed your series then there is no FTP server installed yet – how do you suggest continuing in order to be able adding themes/plugins to WP?

    • gilad says:

      No FTP server yet but I solved it temporarily – instead of using the WP control panel to load themes and plugins I browse to the WP site, download what I need and install it.

  7. Pongsak says:

    Very good indeed, 2 thumbs up.
    Waiting for a new What’s next?.

  8. zraju25@gmail.com says:

    I am fan of your blog; man o man you explain so much details!! Thanks for sharing love of Raspberry Pi!

  9. Pingback: Raspberry Pi Home Server v2: Introduction | MelGrubb.ToBlog()

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s