In the past, I’ve dabbled a bit with hosting my own server on a spare outdated box that likely should have been thrown out. My least favourite thing to do is sit down and tinker with trying to get services and such configured so that they all work together… But once it’s working, it’s glorious. Enter the Raspberry Pi.
Earlier this year I decided I wanted to get a Pi. Why? I wasn’t too sure… But they’re cheap and nothing bad could come of it 🙂 Once I got the thing up and running I was reading about how people were using them. Hosting a WordPress site was definitely one of the uses, so I figured I’d try my hand at that. There are other guides on The Internet about how to do this, but this is what got me up and running.
Disclaimer: A *lot* of this is taken from IQ Jar where there’s been an absolutely amazing outline posted. Although I am repeating a lot of the same steps here, I wanted to post what I felt was a complete install guide. I found myself going back and forth between a few resources, so hopefully this will reduce that issue for you. I do very highly recommend you have a look at IQ Jar though.
Raspberry Pi: What & Where To Buy?
This part is pretty open ended. Let’s start with the “what” portion of things.
The Raspberry Pi is just the board. If you’re totally content with buying a board without a case that you can’t even power up, then you’re all set. Although, if that’s the case, you probably don’t need to read anymore of this! It’s common to pick up the following to get your Raspberry Pi working:
- Raspberry Pi
- Case
- Power Adapter
- SD Card
But once you’ve got those things, you still can’t do too much with your Raspberry Pi aside from powering it up. Some other things you’ll likely want:
- USB Wireless Adapter
- USB Keyboard
- HDMI Cable
NOTE: Pay special attention to what wireless adapters and SD cards can be used with a Pi out of the box. You’ll want to save yourself the headache if others have confirmed the parts you’re looking at purchasing are compatible.
So now that you have an idea what things you’ll need to pickup, where do you get them? If you search The Googles for where to buy any of this stuff, you’ll probably get a ton of hits. Maybe that’s not totally useful for you. I’d suggest the following sites:
- Amazon: I got everything I needed off of Amazon in one fell swoop. You can even find some combo deals that include the Raspberry Pi and a case. Heck, some even come with the SD card too!
- ModMyPi: A great resource… There’s tons of options on this site and it’s specifically for the Pi. Probably can’t go wrong by looking here.
- Ebay: Ol’ Faithful. Lots of options here too, just like Amazon. Bound to find something that fits the bill.
- Newark: There are a great deal of product offerings and resources on Newark. Check them out for full packages, accessories, and additional guides/walk-throughs.
The Walkthrough
First thing: there are a million ways to do this. I’m not going to explore all the options here because I’m not an expert and because I want to provide you with my own steps that worked for me. As soon as I deviate from that… Things will get messy and complicated 🙂
- Download a Raspbian “Wheezy” image from the Raspberry Pi website. This is the image of the operating system your Pi will use.
- Download Win32 Disk Imager. You’ll need this to get the image of the operating system onto your SD card.
- Once both downloads have completed, run Win32 Disk Imager and use it to write the image to your SD card. You’ll need a card reader/writer in your computer, but this is pretty standard these days.
- Take your card out of your computer and pop it into your Pi. You should have your Pi all setup now with power, USB keyboard, USB WIFI adapter, and an HDMI cable plugged into your TV/monitor.
- When you power up your Pi, you should be taken to an initialization/configuration menu. If it ain’t working, there are a million and one trouble shooting guides.
- Some things I suggest you get going while you’re here:
- Reduce graphics memory to the minimum (16). Should help with performance.
- Give yourself a modest overclock. Not sure what’s deemed safe, but I went somewhere in the middle.
- Enable SSH. Later on you’ll never even need to be near your Pi. I can actually control my Pi from my phone with this sweet app.
- Once you’ve got things how you want, expand the file system and reboot your Pi.
- When the Raspberry Pi is back up and running, you need to login to your credentials and then type “startx” and press enter. This will get you into the GUI portion of things.
Anyone well versed in *nix may not need or want to do this, but I found it easiest this way. At this point, get your wifi and everything setup. Your blog won’t be very useful if your Pi isn’t on the internet. Having the GUI portion of Raspbian will also let you quickly search the net and pull up articles if you’re running into any oddities with the components you bought.
Continuing onto the Terminal!
Anyway, now that your Raspberry Pi is working with all the parts you purchased, on with the rest of it:
- Open up a terminal. You’re going to need it for basically everything else in this guide. We’re going to start by turning your Raspberry Pi into a LAMP server.
- Type “sudo apt-get update” to update the various packages on your Pi.
- “sudo apt-get install apache2” to download and install the Apache web server. You’ll want to say yes when it asks for confirmation (and same whenever this happens for the other packages we need to install).
- “sudo nano /etc/apache2/apache2.conf” to open up the apache configuration. You’ll want to stick “ServerName localhost” at the very end of this file and then save and exit the editor. This will get rid of warnings about determining the server’s domain name.
- Restart apache by using “sudo service apache2 restart“. Amazing. You now have a web server.
- You’ll need to take care of any port forwarding to make sure your router does it’s job to get to your Pi.
- Next is installing PHP: “sudo apt-get install php5“
- Type “ls /usr/lib/php5/” and take not of the entry that looks like “20100525+lfs“. Yours might be slightly different.
- “sudo nano /etc/php5/apache2/php.ini” to open up the PHP configuration. Find the line that starts with “extension_dir” and change it so it looks like: extension_dir = “/usr/lib/php5/20100525+lfs/” (except with the name of the entry you have if it was different!)
- “sudo nano /etc/apache2/apache2.conf” to open up the apache configuration. You want to verify you have this line in there: Include conf.d/*.conf
- Next up, you’re going to need to make a config file for Apache. This can be done by typing: “sudo nano /etc/apache2/conf.d/php.conf” and then putting the following text inside of the file:
# PHP is an HTML-embedded scripting language which attempts to make
# it easy for developers to write dynamically generated webpages.
LoadModule php5_module modules/libphp5.so
#
# Cause the PHP interpreter to handle files with a .php extension.
AddHandler php5-script .php
AddType text/html .php
#
# Add index.php to the list of files that will be served as
# directory indexes.
DirectoryIndex index.phpSave and close nano when you’ve finished. - To improve the performance of PHP, install APC by typing “sudo apt-get install php-apc“
- Now that you’ve finished that, restart Apache: sudo service apache2 restart
Next we need to get MySQL up and running. This is going to serve as the backend for your WordPress installation.
- sudo apt-get install mysql-server mysql-client
- Follow up with the MySQL plugin for PHP: “sudo apt-get install php5-mysql“
- Now that you’ve finished that, restart Apache: sudo service apache2 restart
Next we’re actually going to install wordpress!
- In your terminal: “sudo wget http://wordpress.org/latest.tar.gz“
- Then extract the whole thing: “sudo tar -zxvf latest.tar.gz“
- From here, you can either follow along with the official WordPress Setup instructions, or just do what I did. If you want to do what I did, just keep following here!
- We need to make a user in MySQL:
- In the terminal: “mysql -u <YOUR_ADMIN_USERNAME> -p” and hit enter.
- (Obviously where it says <YOUR_ADMIN_USERNAME> you should replace with the database admin username you picked)
- Enter your password as the prompt suggests and press enter.
- Next up: “CREATE DATABASE wordpress” to make the database named wordpress.
- And now we set privileges: “GRANT ALL PRIVILEGES ON wordpress.* TO “wordpress”@”localhost” IDENTIFIED BY “<YOUR_PASSWORD>”;” and press enter.
- (Again, it’s hopefully obvious to replace <YOUR_PASSWORD> with your password)
- “FLUSH PRIVILEGES“
- And then finally “EXIT“
- For my install, I put WordPress right at the root of my website. To do this, we need to copy the contents of the wordpress directory to your /var/www/ directory, but we’re *NOT* copying the wordpress directory itself there: “cp -a wordpress/. /var/www/“
- And now, we run the install script! Since we installed WordPress to the root of the website, we go to http://127.0.0.1/wp-admin/install.php in a browser. Follow the few simple steps there and you should be up and running!
- Remember to check the troubleshooting section on the WordPress site if something seemed to go wrong!
That’s it! You should be up and running.
What’s Next?
You might find your site is a little slow. That’s somewhat expected on your little Rapsberry Pi. Don’t fret. There are lot’s of methods for optimizing your site.
- Check out WP Super Cache, or specifically, the guide over at IQ Jar for more information on tweaking this (it’s near the bottom of the post).
- There’s minifying plugins for javascript and CSS files. This can do a nice job compressing the files and reducing how much data has to be transferred.
- You can look at something like Smush.it to help with compressing your images that you serve. Again, smaller means faster.
- Finally, you might want to test your site on GTmetrix to see if it can recommend any other optimizations to you.
Summary
To wrap up, I hope you found this guide informative. I thought a Raspberry Pi was a great way to start a little DIY project at home and it was fun to get a blog up and running on it.
References
I’m sure I consulted a million and one guides on the Internet, but the following that stick out to me (and I highly recommend you look into them):
- IQ Jar: Crucial for getting me up and running. Specifically, these two guides here and here.
- WordPress.com: The detailed guide here for installing WordPress once you have all the prerequisites was definitely necessary.
- GTmetrix: Serving content was relatively new to me. Once I was analyzing my page with this site, I was lead down a rabbit hole of different things to try and optimize. I highly recommend it!
If you are looking for a dynamic DNS service to make your site available by a rememberable name. Take a look at http://www.duckdns.org
Pingback: WordPress on Raspberry Pi | 0ddn1x: tricks with *nix