Until now everything I built was “just infrastructure”. The WordPress module is the first module that uses the infrastructure. Building a WordPress module as the first “real” module had two reasons. First: I need the module to house this blog
. Second: the configuration and data inside the module is reasonably complex. This makes it ideal to develop and test the data-interface of my FreedomBox architecture.
Creating a WordPress module consists of the following steps:
- Create a LXC container to house the module.
- Install MySQL.
- Install PHP & Co.
- Install a Mail Transfer Agent (Exim4).
- Install and configure WordPress.
- Configure Apache.
- Configure the internet module.
Read this first.
This article is one in a series that describes the building of my FreedomBox. Information from the previous articles like network and software configuration is not repeated.
Create a LXC container to house the module.
cd /var/lib/lxc mkdir wordpress /usr/lib/lxc/templates/lxc-debian-box -n wordpress -p /var/lib/lxc/wordpress
Start the container and continue installation.
lxc-start -n wordpress -d
Login (password = root)
ssh root@wordpress.freedom.box
Inside the container issue the following commands:
passwd dpkg-reconfigure tzdata dpkg-reconfigure locales apt-get update atp-get upgrade
Choose both a locale and default locale (my system: es_US.UTF-8).
Install MySQL.
apt-get install mysql-server
Install PHP & Co.
apt-get install php5 php5-mysql php-apc
Installation of PHP triggers the installation of Apache2. The php-apc package caches the byte codes of the PHP interpreter. This makes PHP execution much faster.
Install the Exim4 MTA.
WordPress needs a MTA to send notifications to the blog admin/user. I use a version of Exim4 that is probably way too powerful for this simple task.
apt-get install exim4-daemon-heavy
After installation you can use the following command to configure Exim4:
dpkg-reconfigure exim4-config
Most configurations should be “mail send by smarthost”.
Install and configure WordPress.
I found the Debian WordPress configuration a little bit confusing so I decided to install the official version:
apt-get install wget cd /var/www wget http://wordpress.org/latest.tar.gz tar xfvz latest.tar.gz
Create a WordPress database:
mysql -u root -p mysql> CREATE DATABASE wordpress; mysql> GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' IDENTIFIED BY 'password'; mysql> FLUSH PRIVILEGES; mysql> exit
Change the password in the line with the privileges statement (do not remove the quotes).
Create and edit a wp-config.php:
cd /var/www/wordpress cp wp-config-sample.php wp-config.php
Install your favorite text editor and edit wp-config.php. Change the MySQL settings and use the link in the “Authentication Unique Keys and Salts” section to get unique values.
The www-data user needs to be the owner of /var/www/wordpress.
cd /var/www/wordpress chown -R www-data:www-data *
Remember: every time you edit one of the files in the wordpress directory you have to change the ownership to www-data afterwards.
Configure Apache2.
In my FreedomBox every request to Apache comes from the Nginx web-server in the internet module. Therefore Apache thinks that every request comes from the same IP address. This must be corrected otherwise things like logging and surveys won’t work as expected. To correct the IP address mod_rpaf must be installed and configured:
apt-get install libapache2-mod-rpaf cd /etc/apache2/mods-enabled
Edit rpaf.conf. Add the IP address of the internet module (192.168.1.10) to RPAFproxy_ips.
Make a symbolic link to mod_rewrite so you can have “pretty urls” in WordPress:
ln -s ../mods-available/rewrite.load
Create a file with the name wordpress inside the directory /etc/apache2/sites-available
The file should contain something like:
<VirtualHost *:80>
ServerAdmin yourname@yourdomainname.com
ServerName wordpress.yourdomainame.com
DocumentRoot /var/www/wordpress
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/wordpress>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Change both ServerAdmin and ServerName.
Enable the site by creating a symbolic link in /etc/apache2/sites-enabled and by restarting the Apache web-server.
cd /etc/apache2/sites-enabled ln -s ../sites-available/wordpress apache2ctl restart
Configure the internet module to forward requests to the WordPress module.
Logout from the WordPress module and connect to the internet module:
ssh root@internet.freedom.box
Edit the Nginx configuration in /etc/nginx/nginx.conf. Make it look like:
user www-data;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
gzip on;
sendfile on;
keepalive_timeout 65;
server_names_hash_bucket_size 64;
server {
# this is a catch-all for requests with none of our hosts
listen 80 default;
location / { return 403; }
}
server {
server_name wordpress.yourdomainame.com;
location / {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://wordpress.freedom.box;
}
}
}
Change the server_name setting to the domain name you used inside the WordPress module.
Restart nginx
/etc/init.d/nginx restart
Configure your router.
If you configure your router to forward port 80 to the internet module you can start blogging!
4 comments
Skip to comment form ↓
l.m.orchard
May 2, 2011 at 23:14 (UTC 2) Link to this comment
Just curious: Have you considered automating a process like this using Puppet or another configuration management system, if that’s possible? It would be nice if a setup like this were as easily built-up and torn down as a single “app” on a freedombox
robvanderhoeven
May 3, 2011 at 09:48 (UTC 2) Link to this comment
One of the reasons i house my modules inside LXC containers is ease of deployment. If you build a container for one processor architecture it can be copy-pasted to any machine with the same architecture. For the configuration and data inside a container i am planning a simple data interface. As you can see from the WordPress module, there is very little configuration data that must come from outside the container.
To answer your question: My FreedomBox modules should be built by competent sysadmins and deployed with the normal Debian package management tools (hidden behind a nice user interface).
Frank
May 3, 2011 at 11:04 (UTC 2) Link to this comment
have you considered using nginx as webserver instead of apache2? it’s far more light-weight on resources than apache, and faster for serving static contents.
robvanderhoeven
May 3, 2011 at 19:55 (UTC 2) Link to this comment
Apache is the “natural habitat” of WordPress. If you use Nginx you can get problems with plug-ins that expect Apache as a web-server. For example: “pretty urls” expect mod_rewrite to be loaded.
Tip: The default Apache2 setup is tailored for a medium traffic website on a fast machine. It starts too many daemons for a simple FreedomBox website. I changed the mpm_prefork_module settings in apache2.conf to:
<IfModule mpm_prefork_module> StartServers 2 MinSpareServers 1 MaxSpareServers 1 MaxClients 10 MaxRequestsPerChild 0 </IfModule>