Showing posts with label Wordpress. Show all posts
Showing posts with label Wordpress. Show all posts

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.