Text 10 Nov 141 notes OAMP / mongodb-php-apache on openbsd 5.0

this aims for a very lean install of php and mongo on openbsd (dated 11-2011)

so real quick without pear, pecl and unnecessary garbage -install or upgrade to your preferred openbsd flavor (stable, release, current)

    $ sudo pkg_add -vi php 
    $ sudo pkg_add -vi mongodb

this should get you php 5.3x and mongo 2.0.x cool isn’t it,

load php into apache

   $ sudo cp /var/www/conf/modules.sample/php-5.3.conf /var/www/conf/modules/ 
   $ sudo cat "<? php phpinfo(); ?>" > /var/www/htdocs/info.php  
   $ sudo /usr/sbin/apachectl restart
   $ lynx http://127.0.0.1/info.php

great now php is rendered through apache

let’s bridge mongo to php via the mongo php driver git the source or dowload the tarball from https://github.com/mongodb/mongo-php-driver unpack it

   $ tar xvfz mongodb-mongo-php-driver-xxxxx.tgz
   $ cd mongodb-mongo-php-driver-xxxxx

now the fun : the autoconfig and shit won’t let you move on and you’ve got to read the errors first it will whine aubout autoconf so you install it

   $ sudo pkg_add autoconf

then it’ll cry about autoconf_version so you tell it

   $ env AUTOCONF_VERSION=2.68 phpize-5.3         

it’ll prepare for ./configure but will whine about php-config so you feed it

   $ ./configure --with-php-config=php-config-5.3 

ready for make so you

   $ make

it’ll spit a mismatched quote syntax error at you you have to fix this one by editing the makefile

   $ mg Makefile

you’ll find the quote problem midway in the file with the build flags/command line, fix it by removing the orphan -I/Util” (til the quote) and save Ctrl X+C

   $ make

this should compile the driver quiet fast with no major errors

   $ ls modules/

you shall see the mongo.so module that you’ll have to hook up to php by

   $ sudo make install
   $ sudo mg /etc/php-5.3.ini 

add a line to tell php it has to load the mongo module we’ve just built inputing this line somewhere in the file

    extension=mongo.so

how sweet! let’s now restart apache/httpd to make it load php with the mongo driver

    $ sudo apachectl restart
    $ lynx http://127.0.0.1/info.php

scroll to the mongo section you shall see the driver loaded, if mongod is running you’ll see info about the db, to start mongo create the db folder and run the deamon

    $ cd
    $ mkdir -p data/db
    $ mongod --dbpath data/db &

hope this helps, no need for pecl, pear and stupid libraries. enjoy lean mongo, secured php 5.3 on chrooted apache with the best puffy of OpenBSD

add-on 11/18/11 b/c i received a couple questions on bugs, well actually there aren’t

httpd would/could whine about pthread and the mongo.so uses them if you can’t connect to the db from php check your httpd error file

$sudo less /var/www/logs/error_log

if you find a pthread problem either recompile httpd with pthread option allowed/defaulted in AcceptMutex or start httpd pthread ready like this

$sudo LD_PRELOAD=/usr/lib/libpthread.so.13.1 apachectl start 

anyway sysvsem semaphores are defaulted in openbsd’s httpd instead of POSIX pthreads.

  1. mezba reblogged this from firemyst
  2. firemyst posted this

© firemyst USE AT YOUR OWN RISK