WordPress on Raspberry Pi

The raspberry Pi is running a WordPress installation of teawea, browser used is chromium

Is it possible to run an existing WordPress site on a raspberry Pi?  Theoretically yes since we have Apache, PHP and MySQL working under Raspbian. This goes under the term of LAMP (Linux, Apache, MySQL or MariaSQL, PHP) As you can see above, it is possible and works quite well.

Overview

  • Install raspbian via NOOBS on a 32GB SD card, see my other post
  • Install some required Software
  • Setup Database
  • Copy files
  • Configure Software

Install some required Software

First we run the terminal program
As always, we update the current installation
$ sudo apt update
$ sudo apt upgrade
$ sudo rpi-update

Now we install the 3 requirements for WordPress
$ sudo apt install apache2 -y
$ sudo apt install php -y
$ sudo apt install mysql-server php-mysql -y

Setup DB

$sudo mysql -uroot -p
>create database mydatabase;
>create user mydatabase identified by ‘secretpassword’;
>grant all privileges on mydatabase.* to ‘mydatabase’@localhost identified by ‘secretpassword’;
>flush privileges;

Backup and Import DB:
First create a backup of your current site and copy the sql file to /home/pi/Desktop
$ cd ~/Desktop
$ sudo mysql -umydatabase -p mydatabase < mydatabase.sql

Make your installation more secure:
$ sudo mysql_secure_installation
$ sudo a2enmod rewrite

Minor modifications to the DB

Get hostname, meaning the IP address:
$ sudo hostname -I
–> (I got 10.1.0.42)

$ sudo mysql -uroot -p
>use mydatabase;
>select * from wp_options where option_name=’siteurl’ or option_name=’home’;
>update wp_options set option_value=’http://10.1.0.42′ where option_name=’home’;
>update wp_options set option_value=’http://10.1.0.42′ where option_name=’siteurl’;
>exit

Lets restart the DB and webserver:
$ sudo service mariadb restart
$ sudo service apache2 restart

Copy Files

Lets copy all files from your existing WP installation to /home/pi/Desktop/temp (depending on the size, this can take a couple of hrs)
$ cd /var/www/html
$ sudo rm -rf *
$ cd ~/Desktop/temp
$ sudo mv * /var/www/html
$ cd /var/www/html
$ sudo mkdir tmp (in order to upgrade your installation later, in config file)
$ sudo chown -R www-data: .

Configure Software

In case you have the Google Recaptcha plugin, we need to disable it: (in order to login to admin pages)
$ cd /var/www/html/wp-content/plugins
$ sudo mv google-captcha google-captcha-old

Lets modify the webservers config file, I use geany as an editor. If you don’t have Geany installed, just install it.
$ sudo apt install geany
$ cd /etc/apache2/sites-available
$ sudo geany 000-default.conf
(after line 1)
<Directory “/var/www/html”>
AllowOverride All
</Directory>
(save and exit)

Now restart the DB and webserver again:
$ sudo service mariadb restart
$ sudo service apache2 restart

Test it

launch chromium an test your setup
URL: http://10.1.0.42

Login to your site:
URL: http://10.1.0.42/wp-admin

Print Friendly, PDF & Email