Make Your Own BiblePress!

What You Will Need

A Raspberry Pi, available at several sites online.
A case for it
A 5V microUSB power supply
A microSDHC (class 10 recommended, 8GB minimum)
An SD card reader
A USB Keyboard and Mouse
An HDMI cable and monitor/TV
An Internet connection
6-8 hours to install, although it can be broken up into segments.

Optional extra is the USB antenna, which boosts the broadcast range significantly.

Install an Operating System

  • Download the image from https://ubuntu-pi-flavour-maker.org/download/
  • Follow the instructions on the same page for making a MicroSDHC 
  • Insert the MicroSD card into the Rpi 
  • Connect to your tv/monitor via HDMI port 
  • Connect a keyboard and mouse 
  • Plug in the power 
  • Choose a user name, device name, and password. For the sake of this walk-through 
    • Name: BibleAdmin 
    • Computer Name: BiblePress 
    • User Name: bibleadmin 
    • Password: biblepassword 
  • At the welcome screen, select “Rasberry Pi Information” 
  • On the menu which appears, select “Resize Now” 
  • Once done, restart your RPi. This could take some time on this instance, as it is setting everything up.

Install Software

Now we are going to configure the RPi to be able to use all of the packages installed, and install some more packages (software) to make this project work. To do this, you will need an internet connection, so connect the RPi to your WiFi (top right side of your monitor), or plug into your router with an ethernet cable.

Next, we are going to open up a terminal emulator. To do this, hold down "CTRL+ALT", and hit "t". Inside the terminal, you should see
bibleadmin@biblepress:~$
Before we can install anything, we need to configure any packages which have not been configured yet. Without delving into the technicalities, it will suffice to say that you will not be able to proceed any further without completing this step, so in the terminal, enter the command:
sudo dpkg --configure -a
Once this is done, we want to update to all of the latest packages (as Ubuntu continues to evolve, updates are released to fix any issues which are found, and to improve on performance where possible). To do this, enter the command:
sudo apt-get update && sudo apt-get -y upgrade
Once the packages are all updated (and it is likely to be a long process), we are ready to install the extra software we will need to make our RPi capable of hosting a WordPress site.
sudo apt-get -y install openssh-server nginx php7.0 mysql-server php7.0-fpm php7.0-mysql php7.0-curl php7.0-gd php7.0-json php7.0-mcrypt php7.0-opcache php7.0-xml php7.0-mbstring php7.0-xmlrpc htop dnsmasq hostapd
During this process, MySQL will ask you for a root user (administrator) password. You can enter anything you like, but for the sake of simplicity, let's keep it the same as our user password in this guide. When prompted, type
biblepassword
Re-enter the same password to confirm it.


Configure MySQL

Now  we are ready to configure MySQL for our webserver. To Do this, we need to access the root user account for MySQL
mysql -u root -p
and enter your password
biblepassword
If done correctly, your command line will change from "bibleadmin@biblepress:~$ " to "mysql>". Now it is time to create a database for our WordPress site.


mysql> CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Make sure, in these commands, that you do not miss the ; at the end of the line.
Next, we will give our user pemissions on the database.
mysql> GRANT ALL ON wordpress.* TO 'bibleadmin'@'localhost' IDENTIFIED BY 'biblepassword';
Then, we flush the privileges, so that mysql becomes aware of the changes we have made.
mysql> FLUSH PRIVILEGES;
and we exit the MySQL configuration.
mysql> EXIT;

Configure nginx 

To configure nginx, we need to edit some configuration files. First of all, we will edit the "hosts" file.
sudo nano /etc/hosts
At the top of the file, you will see a list (probably quite short) of IP addresses followed by names. Below this list, we are going to add the domain for our website, which will be biblepress.com. For mine, I used the address 192.168.0.1, but any valid IP will work just fine. The resulting list in the file will look like this:
127.0.0.1        localhost
127.0.0.1        biblepress
192.168.0.1    biblepress.com
 Now we save the file and close by hitting "CTRL+x" to exit, "y" to save the changes we made, and "enter" to write over the file we opened.

Next, we are going to edit the file nginx reads when it is handling our WordPress site.
sudo nano /etc/nginx/sites-available/default
First of all, we want to change the server name for our website, so locate the line
server_name _;
and edit it to read
server_name biblepress.com;
Then, we want to change which file(s) the webservice tries to serve to the user. Locate the line
index index.html index.htm index.nginx-debian.html;
and edit it
index index.php index.html index.htm;
Directly under the index line, we are going to add a few lines which speed up the server by refusing to log requests from /favicon.ico and /robots.txt
location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}
Then we want to find the control which would normally show the error "404: File Not Found" in some circumstances, and instruct it to load our default file. To do this, find the line
try_files $uri $uri/ =404;
and change it to read
try_files $uri $uri/ /index.php$is_args$args;
 Now we want to make sure that nginx is going to handle PHP properly, which is vital for WordPress. Find, and uncomment (remove the #) these lines
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}
The resulting file should look like this
##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.php index.html index.htm index.nginx-debian.html;

server_name biblepress.com www.biblepress.com;

location = /favicon.ico { log_not_found off; access_log off; }
location = /robots.txt { log_not_found off; access_log off; allow all; }
location ~* \.(css|gif|ico|jpeg|jpg|js|png)$ {
expires max;
log_not_found off;
}

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
#try_files $uri $uri/ =404;
try_files $uri $uri/ /index.php$is_args$args;
}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
include snippets/fastcgi-php.conf;
#
# # With php7.0-cgi alone:
# fastcgi_pass 127.0.0.1:9000;
# # With php7.0-fpm:
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
# listen 80;
# listen [::]:80;
#
# server_name example.com;
#
# root /var/www/example.com;
# index index.html;
#
# location / {
# try_files $uri $uri/ =404;
# }
#}

Now we close and save the file with a "CTRL+x", "y", and "enter".

The configuration of nginx should be complete at this point, but we will check that it is all done right with the command
sudo nginx -t
If no errors have occurred, we are ready to restart ngnix.
sudo service nginx restart
Next, we need to also edit one more file.
sudo nano /etc/nginx/nginx.conf
Add the line
client_max_body_size 100m;
Save and exit, with "CTRL+x", "y", and "enter"

Configure PHP 

Because of the defaults which come with PHP, we will need to edit a couple of files to allow us to upload and post large files on our WordPress site. For my own, I chose a limit of 100MB (see also the limit we just set in nginx.conf), but I see no reason why you couldn't choose a higher limit, so long as you increase the memory limit to allow for it.
sudo nano /etc/php/7.0/fpm/php.ini
Because of the sheer size of the file, it would be difficult to find specific single lines which we need to edit. Fortunately for us, nano has a search function, so hit "CTRL+W" and then search for the line
memory_limit
Edit it to read
memory_limit = 128M
Then do the same for
post_max_size = 100M
and
upload_max_filesize = 100M 
Save and exit the file.


Install WordPress

Now that we have configured our LEMP stack (Linux, (E)nginx, MySQL, PHP), we are ready to download and install wordpress. We will first put it into a temporary location.
cd /tmp
 Now we download it with the command
curl -O https://wordpress.org/latest.tar.gz
and extract it with the command
tar xzvf latest.tar.gz
Next, we copy the sample configuration file, to make an operational configuration file.
bibleadmin@biblepress:/tmp$ cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php
 And then we move the directory
bibleadmin@biblepress:/tmp$ sudo cp -a /tmp/wordpress/. /var/www/html
Now we want to set permissions so that only certain users, groups, and the web interface can write to our directory.


sudo chown -R bibleadmin:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod g+s {} \;
sudo chmod g+w /var/www/html/wp-content
sudo chmod -R g+w /var/www/html/wp-content/themes
sudo chmod -R g+w /var/www/html/wp-content/plugins
And now we want to add some security to our installation. For this, we will use a purpose built key generator from WordPress. Run the command
curl -s https://api.wordpress.org/secret-key/1.1/salt/
and copy the output from the command line.
DO NOT COPY THE VALUES FROM THIS GUIDE
The output should look something like
define('AUTH_KEY', '1jl/vqfs<XhdXoAPz9c_j{iwqD^<+c9.k<J@4H');
define('SECURE_AUTH_KEY', 'E2N-h2]Dcvp+aS/p7XKa(f;rv?Pxf})CgLi-3');
define('LOGGED_IN_KEY', 'W(50,{W^,OPB%PB<JF2;y&,2m%3]R6DUth[;88');
define('NONCE_KEY', 'll,4UC)7ua+8<!4VM+#`DXF+[$atzM7 o^-C7g');
define('AUTH_SALT', 'koMrurzOA+|L_lG}kf07VC*Lj*lD&?3w!BT#-');
define('SECURE_AUTH_SALT', 'p32*p,]z%LZ+pAu:VYC-?y+K0DK_+F|0h{!_xY'); define('LOGGED_IN_SALT', 'i^/G2W7!-1H2OQ+t$3t6**bRVFSD[Hi])-qS`|');
define('NONCE_SALT', 'Q6]U:K?j4L%Z]}h^q71% ^qUswWgn+6&xqHN&%');
Now, open the file we need to edit
sudo nano /var/www/html/wp-config.php
Find the section where we need to put our keys, which will look something like
define('AUTH_KEY', 'put your unique phrase here');
define('SECURE_AUTH_KEY', 'put your unique phrase here');
define('LOGGED_IN_KEY', 'put your unique phrase here');
define('NONCE_KEY', 'put your unique phrase here');
define('AUTH_SALT', 'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT', 'put your unique phrase here');
define('NONCE_SALT', 'put your unique phrase here');
Remove these lines, and paste the output from earlier
define('AUTH_KEY', 'VALUES COPIED FROM THE COMMAND LINE'); define('SECURE_AUTH_KEY', 'VALUES COPIED FROM THE COMMAND LINE'); define('LOGGED_IN_KEY', 'VALUES COPIED FROM THE COMMAND LINE'); define('NONCE_KEY', 'VALUES COPIED FROM THE COMMAND LINE'); define('AUTH_SALT', 'VALUES COPIED FROM THE COMMAND LINE'); define('SECURE_AUTH_SALT', 'VALUES COPIED FROM THE COMMAND LINE'); define('LOGGED_IN_SALT', 'VALUES COPIED FROM THE COMMAND LINE'); define('NONCE_SALT', 'VALUES COPIED FROM THE COMMAND LINE');
Now also want to edit the file so that it is using the right database, user, and password. find and edit


define('DB_NAME', 'wordpress');
define('DB_USER', 'bibleadmin');
define('DB_PASSWORD', 'biblepassword');
Also add the following line
define('FS_METHOD', 'direct');
 Exit and save the file.


Finalise WordPress Installation

It is now time to open up your internet browser (if you have not changed anything outside of this guide, Mozilla Firefox is installed already. Find it under the menu "Applications>Internet>". In the address bar, navigate to 
http://localhost
and follow the prompts to complete the installation. When asked for a user name and password, use the ones we have specified earlier: "bibleadmin" and "biblepassword".

At this point, you may also choose to install plugins (such as hit counters), and themes. After this point, you will lose your internet connection to the RPi, and would need to download them on another computer, and then upload over the WiFi network we are going to create.

Navigate to the "settings" tab, and change the Site Title to
BiblePress
You may choose to add a tagline. I have cleared this field on my own.
Next, change both the wordpress address, and the site address to
http://biblepress.com
Save the changes.

You may create content at this point, but it is not necessary. Whenever you are ready, logout, and close the browser.


Configure dnsmasq 

Dnsmasq is a powerful little program which will serve a few purposes for our project.
  1. It will be or DHCP server, giving IP addresses to everyone who connects to our network
  2. It will be a DNS server, telling the client connections which address they need to visit
  3. It will redirect all traffic to our website
To do all this, we need to edit a single file
sudo nano /etc/dnsmasq.conf
Find, uncomment, and edit the following lines (or simply add them at the top of the file)
no-resolv
listen-address=192.168.0.1
address=/#/192.168.0.1
dhcp-range=192.168.0.50,192.168.0.150,1h
Save and exit.
There is currently a bug with dnsmasq, which means that it may not always start when the RPi is powered up. To fix this
sudo nano /lib/systemd/system/dnsmasq.service
and under the heading "Unit", add the two lines
After=network-online.target
Wants=network-online.target
Then save and exit.


Configure HostAPD 

HostAPD is the package in charge of creating an access point for people to connect to. The first thing we need to do is find out the logical name of our WiFi antenna. If you are choosing to use the built in antenna, it will likely be named "wlan0". If you are using an external (USB) antenna, it will more likely be named something along the lines of "wlxe84e061f5cab". To find out the logical name of your WiFi interface (with the external antenna plugged in at this point), use the command
ifconfig
and copy the logical name. Write it down if you have to. For the sake of this guide, I am going to use the name [wifi]. When you see this name, replace it with the logical name of your interface.

Next, we are going to configure a static (unchanging) IP address for our wifi interface.
sudo nano /etc/network/interfaces
Edit the file as follows
auto lo 
iface lo inet loopback
iface eth0 inet dhcp 
auto [wifi]
iface [wifi] inet static
address 192.168.0.1
netmask 255.255.255.0
broadcast 255.0.0.0
Save the file and exit.
Now we are going to create the Access Point configuration file.
sudo nano /etc/hostapd/hostapd.conf
Enter the following lines:
interface=[wifi]
driver=nl80211
ssid=BiblePress
hw_mode=g
channel=6
auth_algs=1
wmm_enabled=0
Save and exit.
Finally, we want to make hostAPD use the configuration file we created,


sudo nano /etc/init.d/hostapd
Find the line
#DAEMON_CONF
and change it to
DAEMON_CONF=/etc/hostapd/hostapd.conf
making sure you remove the # from this line, or it will not call the configuration file we wrote.


Test

At this point, your RPi should be completely ready, and operational. To test this, restart it with the command
sudo shutdown -r now
and wait while it resets. Once the login screen has loaded, see if you can connect to a wireless network named "BiblePress" from your phone, or another PC. If you cannot find this network, you need to chek your configuration of HostAPD.

If you can find the network, connect to it, and wait. On some phones (Android in particular), a warning may appear that no internet connection is found on this network. Ignore the warning (we are not providing an internet connection), and proceed. Open up an internet browser, and try to browse. Does it redirect you to biblepress.com?

There is an small issue here for which I am trying to find a solution - a lot of browsers have a built in search function, where if you type the search request in the address bar, it goes directly to the search results page. As this puts a "/" into the address, dnsmasq will not redirect it. For example, typing "asdf" into the search/address bar, will not redirect, but will come up with a "not found" page. however, if you type "asdf.com", it should redirect you to "biblepress.com.

If you see that your phone is stuck trying to connect to the network, and comes up with "Trying to obtain IP address", or if redirection does not occur, you need to check your dnsmasq configuration.

If all is well, then you are ready to shut the RPi down, using the command
sudo shutdown now
Disconnect all of the periphery, and relocate it to where it is going to be used.

Congratulations; you built a BiblePress!

If you have any questions, or are having problems with troubleshooting, please do not hesitate to leave a comment below.

Dave.

No comments:

Post a Comment

Please add to the discussion here.

Be aware that comments are moderated, and may take some time to appear on this page.