Back to the sea ; the Blog Tool and Publishing Platform (WordPress), episode VII

    

After creating and editing my Website from scratch with Vim, I used Dokuwiki for quite a long time. Then came the Facebook time. This is when I switched to some more hypee tool. I choosed WordPress.

One nice thing WordPress provides, except from full HTTP management, is automatic configuration and updates.
Here’s how I installed it on OpenBSD.

Installation

WordPress is available from binary packages. The only trouble is it may not be available in the latest version. The updates are easily done from WordPress itself without any knowledge of the operating system.
What I’ll do is a “mixed” installation. I’ll use the binary package to enable automatic dependancies management on the OS level. And I’ll use WordPress itself to manage the whole PHP/HTML/CSS file sets.

Install WordPress and its dependancies:

# pkg_add http://ftp.fr.openbsd.org/pub/OpenBSD/4.8/packages/amd64/wordpress-3.0.tgz

Enable PHP modules:

# ln -s /var/www/conf/modules.sample/php5.conf /var/www/conf/modules
# ln -fs /var/www/conf/php5.sample/mysql.ini /var/www/conf/php5/mysql.ini

I didn’t run # ln -s ../wordpress /var/www/htdocs/wordpress because I’ll dump my actually working (and updated) instance in the right place (see “Restore” section).

Install the SSL certificate:

Configure Apache:

# mkdir /var/www/www.tumfatig.net
# vi /var/www/www.tumfatig.net/index.php
<html><?php echo "Welcome!"; phpinfo();  ?></html>
# diff /var/www/conf/httpd.conf.orig /var/www/conf/httpd.conf
344c344
< ServerAdmin you@your.address
---
> ServerAdmin joel@carnat.net
365c365
< DocumentRoot "/var/www/htdocs"
---
> DocumentRoot "/var/www/www.tumfatig.net"
453c453
< DirectoryIndex index.html
---
> DirectoryIndex index.php index.html
543,544c543
< #ErrorLog syslog:daemon
< ErrorLog logs/error_log
---
> ErrorLog syslog:daemon
569c568,569
< CustomLog logs/access_log common
---
> LogFormat "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b" ssl
> CustomLog "|/usr/bin/logger -t httpd -p info" ssl
1009,1010c1009,1010
< SSLLog      logs/ssl_engine_log
< SSLLogLevel info
---
> #SSLLog      logs/ssl_engine_log
> #SSLLogLevel info
1023,1027c1023,1027
< DocumentRoot /var/www/htdocs
< ServerName new.host.name
< ServerAdmin you@your.address
< ErrorLog logs/error_log
< TransferLog logs/access_log
---
> DocumentRoot /var/www/www.tumfatig.net
> ServerName www.tumfatig.net
> ServerAdmin joel@carnat.net
> ErrorLog syslog:daemon
> CustomLog "|/usr/bin/logger -t httpd -p info" ssl
1107,1108c1107,1108
< CustomLog logs/ssl_request_log 
<           "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"
---
> #CustomLog "|/usr/bin/logger -t httpd -p info" 
> #          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x "%r" %b"

Enable Apache:

# vi /etc/rc.conf.local
httpd_flags="-DSSL"
# apachectl startssl

Apache is now up and running, both in HTTP and HTTPS.

By default, Apache is chrooted. This makes it unable to connect to the local MySQL socket.
Let’s solve this:

# mkdir -p /var/www/var/run/mysql
# chown _mysql:_mysql /var/www/var/run/mysql
# chmod 0711 /var/www/var/run/mysql
# ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/

The link to the socket will have to be created on each reboot:

# vi /etc/rc.local
if [ -x /usr/local/bin/mysqld_safe ]; then
        echo -n ' mysql'
        su -c mysql root -c '/usr/local/bin/mysqld_safe >/dev/null 2>&1 &'
        (sleep 10 && ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock) &
fi

You may install a new WordPress instance by downloading it from its homepage and follow the “5 minutes install” documentation. Fairly simple. I do already have an running WordPress that I want to migrate and install on OpenBSD. That’s the process I’m gonna describe here.

Update

Those directions can be used to either backup/restore WordPress from and to the same server or to migrate (or duplicate) an already working WordPress onto another system.

Backup the actual version

On the SQL server hosting the WordPress database, dump the data:

# mysqldump --add-drop-database --compress --flush-logs -u root -p wordpress > wordpress-"`date +%Y%m%d`".sql

You may want to also drop the GRANT permissions for the WordPress SQL user.
If not, you’ll have to create it by hand:

# mysql -u root -p -e "SELECT DISTINCT CONCAT('SHOW GRANTS FOR ''', user, '''@''', host, ''';') AS query FROM mysql.user" | grep wordpress
# mysql -u root -p -e "SHOW GRANTS FOR 'wordpress'@'www.tumfatig.net';"
(...)
| Grants for wordpress@www.tumfatig.net
(...)
| GRANT USAGE ON *.* TO 'wordpress'@'www.tumfatig.net' IDENTIFIED BY PASSWORD '...' |
| GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE ON `wordpress`.* TO 'wordpress'@'www.tumfatig.net' |
(...)

On the Web server hosting WordPress, grab the HTML/PHP/CSS/… files:

# tar czpf ~/wordpress-"`date +%Y%m%d`".tar.bz2 www.tumfatig.net

Restore a previous backup

Installing the data on a new server or restoring data from an already installed server if quite the same. Transfer the data dumps (as created in the previous section) to the destination server.

If the SQL server is new, that is never had any WordPress instance installed, create the WordPress database and restore user permission:

# mysql -u root -p -e "CREATE DATABASE wp;"  
# mysql -u root -p -e "GRANT USAGE ON \*.\* TO 'wordpress'@'www.tumfatig.net' IDENTIFIED BY PASSWORD '...'"  
# mysql -u root -p -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, REFERENCES, INDEX, ALTER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE ON wordpress.* TO 'wordpress'@'www.tumfatig.net'" 

On the SQL server, restore the database:

# mysql -u root -p wordpress < wordpress-"`date +%Y%m%d`".sql

On the Web server, restore the files:

# tar xzpf ~/wordpress-"`date +%Y%m%d`".tar.bz2 -C /var/www/

If you are migrating either the Web or the SQL server, check that WordPress configuration is (still) OK:

# vi /var/www/www.tumfatig.net/wp-config.php
(...)
define('DB_HOST', 'sql.tumfatig.local');
(...)

That’s all about it!