Nginx and WordPress on a Raspberry Pi

This how to assumes you have completed the tutorial

Maria DB on a Raspberry Pi

This can be done on a second Pi, or on the one you are now working on.

Conventions

Red is a variable that you will need to change to fit your environment

Italics is a command that can be copied and run

Entity in a config file

Prerequisites

This assumes the setup of wordpress on the nginx site. Hence it includes the PHP config for it.

Note that without the php-apc package, your performance will be rather poor, since there is not a lot of power available on a Pi.

I used the following version of Raspbian

2014-09-09-wheezy-raspbian

Boot and expand the rootfs, set the local system time, and overclock if you want to, and set a password.

I normally over clock mine to 800mhz 2 volts over.

Update the system to the current state

  • apt-get update
  • apt-get upgrade

Set the host name and IP address

 

  • nano /etc/hostname
www.example.com

 

  • nano /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet static
       address 192.168.1.5
       netmask 255.255.255.0
       gateway 192.168.1.1

 

Download and install PHP and nginx

  • apt-get install nginx
  • apt-get install php5-fpm php5-mysql

Secure the PHP install

  • nano /etc/php5/fpm/php.ini

Search for the variable “cgi.fix_pathinfo”

It will look like this by default

;cgi.fix_pathinfo=1

You will want to change it to this

cgi.fix_pathinfo=0
  • service php5-fpm restart

Setup the nginx default site

nano /etc/nginx/sites-available/default

server {
        #listen   80; ## listen for ipv4; this line is default and implied
        #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

        root /var/www/html;
        index index.html index.php index.htm;

        # Make site accessible from http://localhost/
        server_name localhost www.example.com;

        location / {
                try_files $uri $uri/ /index.html /index.php?q=$uri&$args;
        }
        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi_params;
        }
}

 Maria DB setup

Note that this assumes that you have a working database already setup. If you need one you can follow Maria DB on a Raspberry Pi

  • mysql -p
  • [none]> USE mysql;
  • [mysql]> CREATE DATABASE databasename;
  • CREATE USER databaseuser@webserveripIDENTIFIED BY ‘yourpasswordhere‘;
  • [mysql]>GRANT ALL PRIVILEGES ON databasename.* TO wordpressuser@webserverip;
  • [mysql]>FLUSH PRIVILEGES;
  • [mysql]>exit

 

 Wordpress setup

You can ignore this if you are running a different PHP application.

  • cd ~
  • wget http://wordpress.org/latest.tar.gz
  • tar xzvf latest.tar.gz
  • cd ~/wordpress
  • cp wp-config-sample.php wp-config.php

Setup the database settings for wordpress

  • nano wp-config.php

Find the section in the config file under the comment

// ** MySQL settings - You can get this info from your web host ** //

You will want to change the settings as follows

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'databasename');
/** MySQL database username */
define('DB_USER', 'databaseuser');
/** MySQL database password */
define('DB_PASSWORD', 'yourpasswordhere');
/** MySQL hostname */
define('DB_HOST', 'databaseserverip');

 

Configure Nginx to host wordpress

Quick note

I normally put my web root in /var/www/html

This is because I have a background in apache, and redhat.

If you want to use the default folder you can.

Just remember to change the following line in the

/etc/nginx/sites-available/default file

        root /var/www/html;

Configure Nginx to host wordpress

  • mkdir -p /var/www/html
  • rsync -aP ~/wordpress/ /var/www/html/
  • cd /var/www/html/
  • chown -R www-data:www-data /var/www/html/*
  • mkdir wp-content/uploads
  • chown -R www-data:www-data /var/www/html/wp-content/uploads

 Restart nginx and hit your site

  • service nginx restart

Open your web browser and go to the following URL

http://www.example.com

 

 

Maria DB on a Raspberry Pi

Conventions

Red is a variable that you will need to change to fit your environment

Italics is a command that can be copied and run

Entity in a config file

Prerequisites

I used the following version of Raspbian

2014-09-09-wheezy-raspbian

Boot and expand the rootfs, set the local system time, and overclock if you want to, and set a password.

I normally over clock mine to 800mhz 2 volts over.

Update the system to the current state

  • apt-get update
  • apt-get upgrade

Set the host name and IP address

 

  • nano /etc/hostname
hostname.example.com

 

  • nano /etc/network/interfaces
auto lo

iface lo inet loopback
iface eth0 inet static
       address 192.168.1.2
       netmask 255.255.255.0
       gateway 192.168.1.1

 

Download Maria DB

  • cd ~
  • wget https://downloads.mariadb.org/f/mariadb-10.0.14/source/mariadb-10.0.14.tar.gz

Extract the files

  • tar -xvf mariadb
  • mv mariadb-5.5.29 maria

Install the build dependencies

  • apt-get install cmake libncurses5-dev bison

Build the source

  • cd maria/BUILD
  • ./autorun.sh
  • cd ..
  • cmake .
  • make   (note that this step takes up to 8 hours to run on a Pi)
  • make install

Create the user

  • adduser mysql

Setup the directories and scripts

  • chown -R mysql /usr/local/mysql
  • cd /usr/local/mysql
  • scripts/mysql_install_db –user=mysql
  • cp support-files/mysql.server /etc/init.d/mysqld
  • /etc/init.d/mysqld start

Secure the database install

This is because the default install options are highly insecure.

  • ./bin/mysql_secure_installation

Setup the config file

  • cp /usr/local/mysql/support-files/my-medium.cnf /etc/mysql/my.cnf
  • service mysqld restart
  • update-rc.d mysqld defaults

Setup access from a workstation

This step is entirely optional, I did it because I like running the SQL client on my PC

  • mysql -p
  • [(none)]> use mysql
  • [mysql]> GRANT ALL ON *.* to root@’192.168.1.5‘ IDENTIFIED BY ‘yourpasswordhere‘;
  • [mysql]> FLUSH PRIVILEGES;
  • exit

My notes on Linux and sound projects