Wednesday, July 11, 2007

Installing Wordpress on OpenBSD

To install Wordpress in OpenBSD you need to have a web server, (e.g. Apache) with PHP and a MySQL database.
OpenBSD already comes with Apache. Therefore we only need to install and configure MySQL, PHP and Wordpress.

Starting the Apache (httpd) server
To start Apache from boot edit /etc/rc.conf and change this line:
httpd_flags=NO
To read:
httpd_flags=""
For more information see my tutorial how to start the Apache (httpd) server.

Now reboot then test that Apache is working.
NOTE:
I don't like moving on to the next step until each step works. Then if there is a problem I know what was working last, and where the problem is likely to be.

Installing MySQL Database Server
To learn how to install, and configure MySQL to work inside of chrooted Apache please see my tutorial: Installing MySQL Database Server.

Now test that MySQL is working.

Creating a Database in MySQL for Wordpress
After installing, and configuring MySQL we need to create a database and a database user for Wordpress.
I will call my Wordpress database: wordpressdb, My user: kris and my password: new-password. Please change these to suit your situation.
# mysql -u root -h localhost -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE wordpressdb;
Query OK, 1 row affected (0.04 sec)

mysql> GRANT ALL ON wordpressdb.* TO kris@localhost IDENTIFIED BY 'new-password';
Query OK, 0 rows affected (0.02 sec)

mysql> SHOW DATABASES;
+-------------+
| Database ---|
+-------------+
| wordpressdb |
| mysql ------|
| test -------|
+-------------+
5 rows in set (0.02 sec)

mysql> \q
Bye


Installing Wordpress
Once you have finished creating a MySQL database we can install Wordpress. I'm going to use pkg_add(1)'s interactive mode (-i) so that I can choose which version of wordpress I want to install:
# export PKG_PATH=ftp://ftp.nara.wide.ad.jp/pub/OpenBSD/4.1/packages/i386/
# pkg_add -i wordpress

Ambiguous: choose package for wordpress
0:
1: wordpress-2.0.7
2: wordpress-2.2.1
Your choice: 2
wordpress-2.2.1:libiconv-1.9.2p3: complete
wordpress-2.2.1:expat-2.0.0: complete
wordpress-2.2.1:gettext-0.14.6: complete
wordpress-2.2.1:libxml-2.6.26p0: complete
wordpress-2.2.1:php5-core-5.1.6p1: complete
wordpress-2.2.1:php5-mysql-5.1.6p2: complete
wordpress-2.2.1: complete


Configuring php5
Before we can use Wordpress we need to configure php for use inside of the chrooted Apache: in /var/www/. To do this I ran the following commands:
# /usr/local/sbin/phpxs -s
# cp /usr/local/share/examples/php5/php.ini-recommended /var/www/conf/php.ini
# chown root:www /var/www/conf/php.ini
# chmod 640 /var/www/conf/php.ini
# mkdir /var/www/tmp


Now enable the php MySQL module:
# /usr/local/sbin/phpxs -a mysql

Lastly we need to inform Apache that we have PHP installed, by editing the httpd.conf file and add the following:
# vi /var/www/conf/httpd.conf
LoadModule php5_module /usr/lib/apache/modules/libphp5.so

AddType application/x-httpd-php .php .php4 .php3 .htm .html
AddType application/x-httpd-php-source .phps

Now edit the DirectoryIndex line in httpd.conf to read:
DirectoryIndex index.html index.htm index.php index.php5 index.php4 index.php3

Testing php5
# vi /var/www/htdocs/phptest.html
adding
<?php phpinfo() ?>
Now in your browser open the phptest page, e.g. http://www.yoursever.tld/phptest.html

NOTE: It is a really good idea to remove this page once you have tested php, as it could be a security risk.

Configuring Wordpress
WordPress has been installed into /var/www/wordpress, which is not the document root.

You could point this to the DocumentRoot of your web-server:
# ln -s ../wordpress /var/www/htdocs/wordpress
(make sure you use a relative symlink since Apache is chrooted)

However I want to create two blogs. Therefore I shall copy the contents of the wordpress directory into /var/www/htdocs/

Creating blog one
# cp -rp /var/www/wordpress /var/www/htdocs/one
Creating blog two
# cp -rp /var/www/wordpress /var/www/htdocs/two

Now I need to edit wp-config.php in both blog directories, and add the database information in each.
# vi /var/www/htdocs/one/wp-config.php
// ** MySQL settings ** //^M
define('DB_NAME', 'wordpressdb'); // The name of the database^M
define('DB_USER', 'kris'); // Your MySQL username^M
define('DB_PASSWORD', 'new-password'); // ...and password^M
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value^M


With the second blog I will also change the $table_prefix option, so that I can use the database created above for both blogs:
# vi /var/www/htdocs/two/wp-config.php
// ** MySQL settings ** //^M
define('DB_NAME', 'wordpressdb'); // The name of the database^M
define('DB_USER', 'kris'); // Your MySQL username^M
define('DB_PASSWORD', 'new-password'); // ...and password^M
define('DB_HOST', 'localhost'); // 99% chance you won't need to change this value^M
define('DB_CHARSET', 'utf8');
define('DB_COLLATE', '');

// You can have multiple installations in one database if you give each a unique prefix
$table_prefix = '2wp_'; // Only numbers, letters, and underscores please!


Now in your browser go to: http://your-server.address.tld/one/wp-admin/install.php. This should set-up the database tables needed for your blog.
NOTE: If there is an error, double check your wp-config.php file, and try again.

Then follow each of the steps on the page. Make sure you note the password given to you.
The install script should then send you to the login page. Sign in with the username: admin, and the password generated during the installation. You can then click on 'Profile' to change the password.

Have fun with your new Wordpress blog.

18 comments:

Anonymous said...

nice guide, clear and concise. Manage to get wordpress up in no time with this.

Kris said...

No worries, I'm really glad it helped :)

Anonymous said...

I am having lots of issues getting this to work. I am using vhost with two domains (only one is actually using mysql). I can connect with the database with mysql -u user, and with a php script with php -f test.php (ran on localhost) which connects to the database and prints OK if it worked. But when I try from the web it fails, and also fails if I try host.tld/wp-admin/install.php (says failed to connect to DB). I have done mostly everything you have done not sure what is causing the issue.

Kris said...

It's hard to say, without seeing more information, what the problem could be.

A couple of things to try would be:
1. Checking your firewall rules.
2. Tring to make a different database and re-editing the Wordpress file (wp-config.php) to see if there is an error there.
(I've actually found problems with naming databases certain things, I don't know why)
3. Also you could try downloading Wordpress again, I have twice now got a dodgy download.

Other than these things, I can only suggest that you email me your log files, and any other information you deem important and I'll see if I can figure anything further out.

Anonymous said...

This fixed it:

ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock

Kris said...

I'm really glad you managed to get it working, Well done!
It's an interesting work around; running the MySQL socket from inside the webserver. I've never had to do that before.
In the interests of learning; Do you know why your setup required it?

Anonymous said...

Dear Kris,

First of all thank you for this nice description on how to install wordpress within OpenBSD.

I installed Wordpress on OpenBSD 4.2 and had the following issues:
- the command "pkg_add -i wordpress" failed due to the fact that libexpat in OpenBSD 4.2 is packed within xbase42.tgz, which I, unfortunately didn't have installed. The solution is thus to install xbase42.tgz which is described here: http://www.openbsd.org/faq/faq4.html#AddFileSet
Somewhere on the internet I found that libexpat will again be part of baseXX.tgz from OpenBSD 4.3, so in the future it will work again.
- if you point your browser to "http://your-server.address.tld/one/wp-admin/install.php" it keeps complaining about not being able to access the database. This can be solved with "ln -f /var/run/mysql/mysql.sock /var/www/var/run/mysql/mysql.sock" as described in the third comment.

Keep up the good work!

Kind regards,

Asim

afghantux said...

Thanks
Nice Howto I install wordpress on OpenBSD 4.2 with Gnome
I would be grateful if you write simple and nice Howto about install Snort on OpenBSD 4.2 , I found one but it was not good and nice and was not clear/

Anonymous said...

Thanks for putting in the effort to write these, please keep this up - one of the best sets of OpenBSD tips I've found for ages!

h said...

Gday,

Any chance of an update to your tutorial as the release of 4.3 has killed bits of it.

Thanks for any help

Kim

Unknown said...

great guide.. Saved me many hours and headaches !

Anonymous said...

Your guides are awesome. I have worked in IT for 20+ years and try to keep my skills current. Your guides are a huge help in that effort and MUCH MUCH appreciated. From the for what its worth dept., the Loadmodule instruction has an unfortunate CR/LF in it that took me awhile to figure out. As a debugging technique starting apache from the forground really helped. I think the command is;
# /usr/sbin/apachectl start

Thank you so much for these guides.

Anonymous said...

Thank you for your detailed instructions. It was very helpful although I skipped some steps. My setup is OpenBSD 4.3 based.

I was able to get my Wordpress up and running without much trouble.

oes tsetnoc said...

Hi, Just like to tell you that this piece of info is one quick to the point, no nonsense, workable and effective way as fast as possible. It worked for me and thank you for the effort. Keep up the good work.

Beta said...

I want to install Wordpress on my openBSD. thanks are guided on how to install it.

Anonymous said...

Welcome thank you so much for this information

php web development

SleepyPenguin said...

http://geekybits.blogspot.co.uk/2007/07/installing-wordpress-on-
openbsd.html

Made it up to....

# /usr/local/sbin/phpxs -s
# cp /usr/local/share/examples/php5/php.ini-recommended
/var/www/conf/php.ini
# chown root:www /var/www/conf/php.ini
# chmod 640 /var/www/conf/php.ini
# mkdir /var/www/tmp

and my new OpenBSD 5.1 installation says.....

# /usr/local/sbin/phpxs -s
ksh: /usr/local/sbin/phpxs: not found

# cp /usr/local/share/examples/php-5.3/php.ini-recommended
/var/www/conf/php.ini
cp: /usr/local/share/examples/php-5.3/php.ini-recommended: No such file
or directory

I'm not sure where these files are on my hard disk. Can you make a
suggestion about where I go from here ? Would be nice to be able to
run two Wordpress blogs on my OpenBSD 5.1 web server.

AustinHook said...

I am using OpenBSD 5.2 and probably the same as 5.1, I notice that by doing:

pkg info php

There is text that says that phpxs is no longer necessary, and moreover, how to put in a link to make things work.