Given that I have some requirement for PHP, I thought I'd write a quick blurb on how to perform a fast, basic installation.
The new httpd supports a similar architecture as nginx using a unix socket with which to communicate to php-fpm via fastCGI.
Let's assume you have a fresh 5.7 installed. Let's also assume you're root, though we all know the dangers of acting with unilateral authority as root.
First, let's get httpd running by creating a configuration file. Create your /etc/httpd.conf as follows (this is very minimalistic):
# cat <
> server "default" {
> listen on egress port 80
> location "*.php" {
> fastcgi socket "/run/php-fpm.sock"
> }
> }
> EOF
Secondly, we'll set a package path. I chose rit.edu's mirror - you can select your own from OpenBSD's list.
# export PKG_PATH=http://filedump.se.rit.edu/pub/OpenBSD/snapshots/packages/`machine -a`/
Next, add the php-fpm package. I'm forcing the 5.4.38, but you can select any version you like. The -I switch disables the interactive prompts (assuming defaults) and the -v switch enables more verbosity.
# pkg_add -I -v php-fpm-5.4.38
You'll see a jumble of output, but it should eventually install.
I then created /var/www/htdocs/phpinfo.php to test for PHP's functionality.
# cat <
>
> EOF
Lastly, I started php_fpm as well as httpd. Note the -f on httpd may be necessary - I'm forcing it for the demonstration, but ultimately it's up to you.
php_fpm(ok)
# /etc/rc.d/httpd -f start
httpd(ok)
At this point, you should be ready to test your installation of OpenBSD's new httpd + php by visiting your site at http://127.0.0.1/phpinfo.php (if you're local to the machine).
Enjoy!
P.S. To run Perl in CGI on the new httpd, you'll need to do a little extra!
Copy the necessary binary and its accompanying libraries to their respective directories in the /var/www root: (don't forget to create any necessary directories first!)
# mkdir -p /var/www/usr/{bin,lib,libexec}
# cp /usr/bin/perl /var/www/usr/bin
# cp /usr/lib/libpthread.so.18.1 /var/www/usr/lib
# cp /usr/lib/libperl.so.17.0 /var/www/usr/lib
# cp /usr/lib/libm.so.9.0 /var/www/usr/lib
# cp /usr/lib/libutil.so.12.1 /var/www/usr/lib
# cp /usr/lib/libc.so.78.1 /var/www/usr/lib
# cp /usr/libexec/ld.so /var/www/usr/libexec
Don't forget to set ownership/permissions!
# chown www:www /var/www/usr/bin/perl \
# /var/www/usr/lib/{libpthread.so.18.1,libperl.so.17.0,libm.so.9.0,libutil.so.12.1,libc.so.78.1} \
# /var/www/usr/libexec/ld.so
# chmod 550 /var/www/usr/bin/perl
# chmod 440 /var/www/usr/lib/{libpthread.so.18.1,libperl.so.17.0,libm.so.9.0,libutil.so.12.1,libc.so.78.1} \
# /var/www/usr/libexec/ld.so
location "*.shtml" {
fastcgi socket "/run/slowcgi.sock"
}
Start slowcgi:
# /usr/sbin/slowcgi
Restart httpd:
# /etc/rc.d/httpd -f restart
httpd(ok)
httpd(ok)
Your server should be serving CGI now (using the Perl included with OpenBSD). Enjoy!
Looks like your text was processed:
ReplyDeleteI see
```
# cat < /var/www/htdocs/phpinfo.php
>
> EOF
```
though there should be `<<EOF` obviously and some PHP code between `cat` and `EOF`
This article helped me a lot, thank you! How do I enable php_fpm autostart after system restart?
ReplyDeleteAdd `pkg_scripts="php_fpm"` line to `/etc/rc.conf.local`
ReplyDeleteThanks for your article, I've used it in the past. If you're interested, I've put up a post on installing httpd/PHP/MariaDB with HTTPS for OpenBSD 6. Cheers.
ReplyDelete