The Making of a WordPress Server!

Recommended hardware for server setup:
Raspberry Pi Model B; either 256MB or 512MB
1A Power supply
Minimum of 4GB class 4+ SD card (RSE); recommended 8GB class 4 or better for full Raspbian install (my current install=3.7GB)

Note on Raspberry Pi:
I have seen no difference in performance between the 256MB rev. 1.0 and the 512MB rev. 2.0 boards for a web server. If you plan to install other things besides the web server on your RasPi then I would use the 512MB board. You could also install a web server on a Model A. You will have to use either a USB Ethernet or a USB Wi-Fi dongle to have Internet access. Again; 256MB is more than adequate for a web server.

SD card Note:
A lot of emphasis has been placed by some on the class of card you use for the Raspberry Pi. For a server you really do not need a real fast (Class) of SD card. Most SD cards “Read” at about the same speed. The “Class” rating really only indicates the “Write” speed. So a lower class card might take a bit longer to save information too, but it will likely read just about as fast. “Burning” a card will take longer if it is a lower class. Buying a better known, name brand card is always a good idea for your server.

The size of your card is going to depend upon what you decide to store on it. For the average WordPress server I would say use an 8GB card is best. If you intend to store a lot of pictures then you may need a bigger card. If you decide to use it as a FTP site then you may want to expand your storage size with a USB stick or even a USB HDD or a USB SSD.

Some more reading about hardware:

Recommended OS:
Raspbian full version or Raspbian server Edition (RSE).
Arch Linux will also work.
If you wish to use a Remote Desktop (RDP) connection then use a full Raspbian install.

Initial setup:
Raspbian install
At the raspi-config console
set internationalization
set time zone
set keyboard
set overclocking (900(Medium))(read note below about OC)
set memory split (16)
change password
change hostname
enable SSH
expand files system

Overclocking Note:
Overclocking on the Raspberry Pi enhances its performance somewhat. Overclocking can cause damage to the Silicon over time. If you force the turbo option, your RasPi will maintain the cpu-freq you have set all the time. I do not recommend you use the turbo setting on a web server!

If you use the settings in raspi-config, to set your RasPi speed, the overclock is dynamic. This means it will only raise the frequencies that were set when the board is put under a load. Considering that most web sites are going to spend most of their time at idle, there is not too much worry that your RasPi is going to die anytime soon. Overall you do not need to overclock your RasPi for decent web browser performance.

At this point I recommend that you try to SSH into your server. I use PuTTY from my Win7 desktop. Check your IP after login you will need this to connect. You can complete the following steps using SSH. You can also finish them while it is still connected to a keyboard and monitor! Your choice. You will probably use SSH for everything after you have your web site setup and running.

setup a server:
sudo apt-get update
sudo apt-get upgrade

Install Apache2:
sudo apt-get install apache2
When you boot your RasPi it will show you the I.P. address it was assigned. Using a browser you will enter that I.P.. A plain page that says “It works!” should appear.
You now have a basic Apache2 server. This web page is located in /var/www/index.html
That is where you would put your content for a static html web site.

Installling Lighttpd instead!:
follow supplement page

At this point I recommend that you make a backup of the SD card. Most of my failures have been with MySQL. So if you need to start over because the “failure to establish Database”, then you only need to go back to here.

PHP install without MySQL:
sudo apt-get install php5-fpm
sudo service php5-fpm restart


I also installed php-cgi originally. This caused the white screen of death known in WordPress. If you try to install the cgi you will have to edit some Apache2 config files to fix the WSD.
If you are installing MySQL then skip to the Install MySQL.

Install MySQL with PHP5:
sudo apt-get install mysql-server-5.5 php5 php5-mysql php5-gd (note: removed php5-cgi)

enter your MySQL root password, write it down.

At this point you have a LAMP (Linux, Apache, MySQL, PHP) server! Now you have to decide if you wish to run a static site that you will need an editor to run, or install something like WordPress. I chose WordPress as it is easy to use and I find that I am more willing to keep it up to date than a Static site.

Backup again at this point

You now have some options as to what can be installed.
Mediawiki. The same as Wikipedia.

Or, install WordPress:

If you installed Lighttpd start here to finish WordPress Install

Install WordPress:


extract WordPress:

tar -xvzf latest.tar.gz

Create working directory:

sudo mkdir /var/www/wordpress

Set permissions:
Change Directory

sudo chown -R www-data.www-data /var/www/wordpress

Copy the extracted files:

sudo cp -r ~/wordpress/* /var/www/wordpress

Below lines might be needed if you cannot enter the WordPress FTP when trying to install plugins or themes.

cd /var/www

sudo su
chown www-data *
chown www-data */*
chown www-data */*/*

Ignore next if using Lighttpd. jump to Step:

Configure Apache2:
sudo cp /etc/apache2/apache2.conf /etc/apache2/apache2.config.bak
sudo nano /etc/apache2/apache2.conf

Add this line to the end of the file:
AddType application/x-httpd-php .html
To save ctrlX then y then enter.

Restart Apache:
sudo /etc/init.d/apache2 restart


sudo cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php

sudo nano /var/www/wordpress/wp-config.php

Change these lines.
/** The name of the database for WordPress */
define(‘DB_NAME’, ‘wordpress‘);

/** MySQL database username */
define(‘DB_USER’, ‘user name‘);

/** MySQL database password */
define(‘DB_PASSWORD’, ‘password‘);

Configure MySQL:
mysql -u root -p
enter mysql password you create when MySQL was installed!

CREATE USER create a user name here;
SET PASSWORD FOR wordpressuser= PASSWORD('created password');

GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpressuser'@'localhost' IDENTIFIED BY 'password';
sudo reboot

Now try your site by entering the IP
example; (The IP your Raspberry Pi shows at logon)

You should see the WordPress install page.

Site Title
Username (wordpressuser)
Password (user password)
Your E-mail
Box to let your site bee added to the search engines.

Press button to Install WordPress
Then you will log-in with your user and password.

Your WordPress site is now ready to be setup. You will want to choose a theme and start adding post or pages to your site!

Now we are going to install a couple of things to make your WordPress site run faster! you will notice that it takes quite a while to update or publish in your site.

Back to your keyboard or SSH!

sudo apt-get install php-apc

Now we will install XRDP so you can use the remote desktop. This only works if you use a full install of Raspbian.
sudo apt-get install xrdp

We will now create .htaccess, this is needed to use the WP Fast Cache plugin for WordPress.

this needs to be in /var/www
cd /var/www
sudo nano .htaccess

Now copy the lines below. right click, copy then right click in nano to add them

#start_wp_fast_cache - do not remove this comment

RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(GET)
RewriteCond /var/www/wordpress/wp-content/wp_fast_cache/%{HTTP_HOST}%{REQUEST_URI}x__query__x%{QUERY_STRING}index.html -f
RewriteCond %{HTTP_USER_AGENT} !(iPhone|Windows\sCE|BlackBerry|NetFront|Opera\sMini|Palm\sOS|Blazer|Elaine|^WAP.*$|Plucker|AvantGo|Nokia)
RewriteCond %{HTTP_COOKIE} !(wordpress_logged_in) [NC]
RewriteRule ^(.*)$ /var/www/wordpress/wp-content/wp_fast_cache/%{HTTP_HOST}%{REQUEST_URI}x__query__x%{QUERY_STRING}index.html [L]

RewriteCond %{REQUEST_METHOD} ^(GET)
RewriteCond %{QUERY_STRING} ^$
RewriteCond /var/www/wordpress/wp-content/wp_fast_cache/%{HTTP_HOST}%{REQUEST_URI}index.html -f
RewriteCond %{HTTP_USER_AGENT} !(iPhone|Windows\sCE|BlackBerry|NetFront|Opera\sMini|Palm\sOS|Blazer|Elaine|^WAP.*$|Plucker|AvantGo|Nokia)
RewriteCond %{HTTP_COOKIE} !(wordpress_logged_in) [NC]
RewriteRule ^(.*)$ /var/www/wordpress/wp-content/wp_fast_cache/%{HTTP_HOST}%{REQUEST_URI}index.html [L]


Then ctrl-X then Y then enter.

Sudo reboot

Now enter your site and login and go to plugins>installed plugins.
Delete the plugins that are in there now. Then install the WP-Fast Cache Plugin.

For a little better security I also install Fail2ban. By SSH.
Sudo apt-get install fail2ban
This will stop recursive failed login attempts to your server.

I also install the “Ban Hammer” Plugin to stop the user database from being flooded by bots. And I install the Revisions Control Plugin to limit the number of “Revisions” that are stored by WordPress.

Lately I installed WP-Optimization, still evaluating whether it helps or not.

Uninstall Askimet and the Hello Dolly plugins.

useful commands
sudo /etc/init.d/mysql stop|restart
sudo /etc/init.d/apache2 restart|stop

To use RDP you need to install xrdp.

Sudo apt-get install xrdp

Some things I have tried to gain performance with WordPress:

Server Split:
Using two RasPii; one with MySQL and the other with everything else. There were measureable gains. .2 seconds better page serves and publishing pages was .3 seconds faster. Considering the higher power usage of about 1/3 not really worth the effort of 6 hours rebuilding the whole site. If I really needed every last bit of performance I might set this up again, but those gains are really quite small. php-apc was not installed at this time so it might have seen better gains.

Both of these RasPii were Rev. 1.0 boards that were back-powered from a 4 port USB hub (both of these boards have pin headers in place of the USB connectors). this is why I only saw 1/3 more power usage. If you have to use two PSU’s then it would have been double the usage.

Note on web server cluster:
My use was a distributed server solution, it was not a cluster.
I suspect that some of the cluster (Bramble) web servers are seeing more performance than can really be realized. I believe the cluster load balancer is carrying the load rather than the cluster itself!

Site moved to USB stick:
I had noticed that OpenElec XBMC ran better from a USB stick rather than from the SD card. I tried moving the site to a USB stick. This took very little time. No measureable difference in performance. Might be a benefit if you need more space as large USB sticks are cheaper than SD cards. php-apc was installed

256MB vs. 512MB:
No measurable difference in page serve speeds. Might be a benefit if you run other things on the server than just WordPress. If you have an older 256MB B Model then use it. has been tried with and without php-apc.

Removed unnecessary components:
I have removed the web browsers, scratch and squeak from the server. wpagui (wifi config on desktop) can also be removed. I left Python on. I am sure there are other things that can be removed to free up disk space (storage). I worry more about those items that take up memory space. Still looking into stuff that affects system memory usage.

Using a USB stick as swap:
I use an old 512MB USB stick as a swap file in my WordPress server. The whole stick was partitioned as a swap file for Linux using GParted. The device is in fstab (/etc/fstab) as sda1.
cd /etc
Sudo nano fstab
/dev/sda1 /swap vfat defaults 0 0
If you choose to do this then you should turn off the default swapfile.
sudo dphys-swapfile swapoff
I used GParted to create the swapfile on the USB stick!

sudo nano /etc/sysctl.conf
The swappiness setting was changed from =1 to =40. placed at the end of the file.

vm.min_free_kbytes = 16384

In my opinion this protects the SD card from swapping. Reduces the number of reads and writes on the card. It is actually used very little. I have only seen about 14MB of swap being used.
total used free shared buffers cached
Mem: 232 208 23 0 9 65
-/+ buffers/cache: 132 99
Swap: 511 14 497

Leave a Reply