Installing WordPress on Raspberry Pi

Just a novice guide for running WordPress with nginx on Raspberry Pi.

Download the Raspbian Lite image from https://www.raspberrypi.org/downloads/raspbian/

screen-shot-2016-10-12-at-4-01-37-pm

At the time of writing this, we’re having Raspbian Jessie Lite released on 2016-09-23.

Unzip Raspbian Lite image that we’ve downloaded

Write it to your sdcard using the following commands(these commands are for MacOS)

Change directory (cd)  to the folder where that unzipped image file is.

  1.  sudo diskutil list 
  2. sudo diskutil unmountDisk disk2
  3. sudo dd bs=5m if=2016-09-23-raspbian-jessie-lite.img of=/dev/rdisk2

After the image is written to the sdcard, eject it from the system, then place it in Raspberry Pi

Connect ethernet cable to the Raspberry Pi, and power it on by connecting the MicroUSB power cable (you don’t need to connect any keyboard or display to this device yet).

You’ll get the IP address of the Pi from your router, just SSH to it using :

ssh [email protected]

The default password will be “raspberry”

First things we want to do on that new installation is, expand the filesystem(in case not expanded by default)

sudo raspi-config

screen-shot-2016-06-16-at-9-44-05-pm

Select the first option

1 Expand Filesystem

screen-shot-2016-06-16-at-9-44-27-pm

Then goto Advanced Options and select “Memory Split”

screen-shot-2016-06-16-at-9-44-44-pm

screen-shot-2016-06-16-at-9-44-56-pm

Change the value to 16(we’re not running any graphical interface on the device, so we’re changing this value to ensure most of the RAM is available for our web server.

screen-shot-2016-06-16-at-9-45-07-pm

Now go to “Internationalisation Options” and select “Change Locale”

Select “en_US.UTF-8 UTF-8”

Unselect any other locales there are selected.

screen-shot-2016-06-16-at-9-45-27-pm

screen-shot-2016-06-16-at-9-45-37-pm

screen-shot-2016-06-16-at-9-45-55-pm

screen-shot-2016-06-16-at-9-46-09-pm

After this is done, press “Finish” (right arrow key twice) from the menu, and it will ask for a restart,

screen-shot-2016-06-16-at-9-46-52-pm

screen-shot-2016-06-16-at-9-47-36-pm

Now to avoid perl giving error messages about the LANGUAGE not set, we’ll need to modify one file, you can use nano editor but I like using vim only, so thats the first thing I install on a server.

sudo apt-get install vim

Now edit the file /etc/environment using vim

sudo vim /etc/environment

and add the following lines:


LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8

Now exit the shell using

exit

and SSH again to RPi

Make sure there are no errors listed when you type

perl

command(press ctrl+c to exit)

Now we’ll need to deb package to install latest PHP and NGINX on the server

Adding stretch release for latest PHP and NGINX(as read on https://getgrav.org/blog/raspberrypi-nginx-php7-dev)

sudo vi /etc/apt/sources.list

Add this line under the first jessie line:

deb http://mirrordirector.raspbian.org/raspbian/ stretch main contrib non-free rpi

If you don’t want all packages to be downloaded from stretch release you can add following code in apt preferences

vim /etc/apt/preferences.d/stretch

and paste the following:

Package: *
Pin: release n=jessie
Pin-Priority: 600

Now we’ll upgrade all packages on the system

sudo apt-get update
sudo apt-get upgrade

When the upgrade is complete lets install NGINX, PHP5-FPM server and MySQL server on RPi

sudo apt-get install -t stretch php7.0 php7.0-curl php7.0-gd php7.0-fpm php7.0-cli php7.0-opcache php7.0-mbstring php7.0-xml php7.0-zip php7.0-mysql nginx-extras mysql-server-5.6 

and for some other needed tools(we’re not using -t stretch as we want other apps to be fetched from stable repo):

sudo apt-get install htop git

The installation will ask you to add root password for MySQL server, so wait for it before going anywhere, once you enter the password, check the status of installation after 10-15 minutes(this can take some time depending upon your internet speed and the speed of memory card you’ve used, I had issues with SanDisk’s memory cards, though they work fine on phones and laptop, the speed was way too low on Raspberry Pi somehow, currently using Strontium Nitro UHS-1 card, which is performing well with RPi)

Now that we have PHP, Nginx and MySQL running on Raspberry Pi, lets get started with WordPress

First step would be to install wp-cli, which is quite the easy thing

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Now enter this command to see if its working

wp --info

 

Leave a Reply

Your email address will not be published. Required fields are marked *