So to start this whole process, I backed up the important stuff from the old machine:
$ sudo tar czvf /waterdb.tgz /etc /var/www
If your UNIX skills are a little rusty I'm using tar to backup my /etc and /var/www directories and store them in a gzip compressed archive on my root parition, all done through sudo because we need to be root. After that I used scp to copy it to another machine.
Next I downloaded the i386 version of the ramdisk kernel:
ftp ftp://ftp.openbsd.org/pub/OpenBSD/5.2/i386/bsd.rd
and moved it to my root partition (overwriting the old 5.0 bsd.rd):
$ mv ~/bsd.rd /bsd.rd
With that in place it was time to bid farewell to my system and reboot.
I stopped the boot loader at the:
boot>
screen (by hitting the space key) and told it to boot my ramdisk kernel:
boot> /bsd.rd
After hitting enter and watching the kernel fly by I was left at the installer menu.
I won't get too much into how to install OpenBSD because there are better tutorials out there, namely the INSTALL.i386 file and for the
http://www.youtube.com/watch?v=014wVkGEi5c
For the install, I created a separate /var/www partition and only installed:
base52.tgz = base system
etc52.tgz = etc directory
man52.tgz = man pages (not essential)
bsd = kernel
bsd.rd = emergency / install ramdisk kernel
After rebooting the system, I enabled the user I created during the install to run commands via sudo by logging in a root and running:
# visudo That ran vi on the sudoers file, to actually make the change I used the arrow keys and scrolled down to the lines:
# Uncomment to allow people in group wheel to run all commands# and set environment variables.# %wheel ALL=(ALL) SETENV: ALL
And while my cursor was on top of the "#" in front of the "%wheel" line I tapped x on my keyboard to delete the "#" character. To save and edit I pressed Esc and then typed :wq to write and quit the file. (If you run into trouble, hitting Esc and then typing :q! will get you back to the shell, without saving).
Now that my regular user had sudo abilities I logged off as root and back in as my user.
The next step was to install php-frm by running:
$ sudo pkg_add php-fpm
pkg_add went off and installed the dependencies I needed. Once that was all said and done it was time to configure php-fpm and nginx.
Now there are a few ways of having nginx talk to the PHP module, I wanted to use unix sockets because they involve less overhead than TCP.
To do this you'll have to remember that when nginx is running, it's inside of the chroot so the root directory (/) in config files (and scripts running on the site) is actually at /var/www when on the system.
To have php-fpm leave a socket where nginx can see it I ran:
$ sudo vi /etc/php-fpm.conf
and changed the line:
listen = 127.0.0.1:9000
to:
listen = /var/www/tmp/php.sock
By using the x to delete and then Esc and i to switch vi back into inserting mode.
After saving and exiting, it was time to edit the nginx.conf:
$ sudo vi /etc/nginx/nginx.conf
I looked for the lines:
location ~ \.php$ {
root /htdocs;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /htdocs$fastcgi_script_name;
include fastcgi_params;
}
fastcgi_pass 127.0.0.1:9000;
to:
fastcgi_pass unix:/tmp/php.sock;
If you're wondering why it's not unix:/var/www/tmp/php.sock it's because of the chroot.
Before exiting I also changed this line:
index index.html index.htm;
to:
index index.html index.htm index.php;
Now, I was ready to make a test file:
$ sudo vi /var/www/htdocs/phpinfo.php
with:
<?php phpinfo(); ?>
And finally start the services:
$ sudo nginx
$ sudo /usr/local/sbin/php-fpm-5.3
Then fire up a browser to my site /phpinfo.php, and bask in the glory of PHP and nginx living in harmony :)
As a side note, I'll post some instructions on how to get nginx and php-fpm-5.3 to start up at boot time.
EDIT: Okay, so this is probably just for 5.2 as it will be different in 5.3:
$ sudo vi /etc/rc.local.conf
Add the line:
pkg_scripts="ng inx php_fpm"
Save & exit and you're done! (maybe reboot to check it).
EDIT: Okay, so this is probably just for 5.2 as it will be different in 5.3:
$ sudo vi /etc/rc.local.conf
Add the line:
pkg_scripts="ng
Save & exit and you're done! (maybe reboot to check it).
Thanks for reading!
Amazing tip on using unix sockets for php via nginx. Thank you so much.
ReplyDeleteI think this tutorial might be useful as well:
ReplyDeletehttp://blog.szulak.net/administration/install-nginx-on-rhel-centos6/
The correct file in Obsd 5.2 is $sudo vi /etc/rc.conf.local
ReplyDeleteThanks, this helped me get nginx/php running on:
ReplyDeleteOpenBSD 5.5-beta
Your notes still apply, the only thing I would change is, for testing, I started the daemons with:
$ sudo /etc/rc.d/php_fpm start
php_fpm(ok)
$ sudo /etc/rc.d/nginx -f start
nginx(ok)
And to make it permanent, put in rc.conf.local:
nginx_flags="" # for normal use: ""
pkg_scripts="php_fpm"
because nginx is part of base it only needs the flag, and php_fpm is a package, so it goes in the pkg_scripts variable.
I also had a bit of a surprise when I got the default /var/www/htdocs "OpenBSD Apache 'It Worked!'" page, before I remembered that was just the stock webpages that haven't been updated to reflect the inclusion of nginx in base.
Lastly, you have a small typo:
The next step was to install php-frm by running:
The next step was to install php-fpm by running: