{"id":220,"date":"2020-03-23T21:54:04","date_gmt":"2020-03-23T20:54:04","guid":{"rendered":"https:\/\/blog.remyblom.nl\/?p=220"},"modified":"2020-11-17T10:20:57","modified_gmt":"2020-11-17T09:20:57","slug":"mongodb-on-openbsd6-6-with-php-fpm","status":"publish","type":"post","link":"https:\/\/blog.remyblom.nl\/?p=220","title":{"rendered":"MongoDB on OpenBSD6.6 with PHP-FPM&#8230;"},"content":{"rendered":"\n<p>Okay, for a new project I want to try and move to MongoDB, I am really looking forward to a schema free database where I can simply just store my &#8216;documents&#8217; and do with them what I want! <\/p>\n\n\n\n<p>So let&#8217;s log into our server and get some stuff installed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ doas pkg_add mongodb\n$ doas rcctl enable mongod\n$ doas rcctl start mongod\n$ mongo\nMongoDB shell version: 3.2.22\nconnecting to: test\nWelcome to the MongoDB shell.\nFor interactive help, type \"help\".\nFor more comprehensive documentation, see\n\thttp:&#47;&#47;docs.mongodb.org\/\nQuestions? Try the support group\n\thttp:\/\/groups.google.com\/group\/mongodb-user\nServer has startup warnings: \n2020-03-20T23:01:00.737+0100 I CONTROL  &#91;initandlisten] \n2020-03-20T23:01:00.737+0100 I CONTROL  &#91;initandlisten] ** NOTE: your operating system version does not support the method that MongoDB\n2020-03-20T23:01:00.737+0100 I CONTROL  &#91;initandlisten] **       uses to detect impending page faults.\n2020-03-20T23:01:00.737+0100 I CONTROL  &#91;initandlisten] **       This may result in slower performance for certain use cases\n2020-03-20T23:01:00.737+0100 I CONTROL  &#91;initandlisten] \n2020-03-20T23:01:00.737+0100 I CONTROL  &#91;initandlisten] ** WARNING: soft rlimits too low. Number of files is 128, should be at least 1000\n2020-03-20T23:01:00.737+0100 I CONTROL  &#91;initandlisten] <\/code><\/pre>\n\n\n\n<p>For what it&#8217;s worth Mongo is showing some startup warnings, I&#8217;m going to ignore these for now. Let&#8217;s first insert some data so we can test our db connection later when we are in PHP:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ mongo testdb\n> db.users.insert({ 'name': 'Remy Blom', 'email': 'r@aodw.nl' })<\/code><\/pre>\n\n\n\n<p>Thing is we have a working MongoDB, kinda cool, but I want to be able to talk to it from PHP (or do I? I might have to rethink that\u2026 PHP is waaaay old and stuff?)<\/p>\n\n\n\n<p>First we have to prepare our OpenBSD to be able to run the manual installation. (I still think this should also be able to work in such a way that you could just use the <code>pecl install<\/code> method, but I kept running into the error mentioning <code>AUTOCONF_VERSION<\/code> was not set&#8230;)<\/p>\n\n\n\n<p> In order to get <code>phpize<\/code> running I had to do:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ doas pkg_add pear autoconf\n$ cd \/usr\/local\/bin\n$ ln -s phpize-7.3 phpize\n$ ln -s php-config-7.3 php-config<\/code><\/pre>\n\n\n\n<p>Furthermore I had to add to my <code>.\/profile<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>export AUTOCONF_VERSION=2.69<\/code><\/pre>\n\n\n\n<p>Then I had to re-login for the profile to take effect and then I could run:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ git clone https:\/\/github.com\/mongodb\/mongo-php-driver.git\n$ cd mongo-php-driver\n$ git submodule update --init\n$ phpize\n$ .\/configure\n$ make all\n$ sudo make install<\/code><\/pre>\n\n\n\n<p>Restart php-fpm and ready to go:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$ doas rcctl restart php73_fpm<\/code><\/pre>\n\n\n\n<p>Let&#8217;s write a little program that returns that user we inserted in the beginning:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n\n    $m = new MongoDB\\Driver\\Manager(\"mongodb:\/\/localhost:27017\");\n    $query = new MongoDB\\Driver\\Query(&#91;]); \n     \n    $results = $m->executeQuery(\"testdb.users\", $query);\n    echo $results;\n\n    foreach ($results as $result) {\n        print_r($result);\n    }<\/code><\/pre>\n\n\n\n<p>Running this code will print:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>stdClass Object\n(\n    &#91;_id] => MongoDB\\BSON\\ObjectId Object\n        (\n            &#91;oid] => 5e79c3a3c7f38ba9c7943ffd\n        )\n\n    &#91;name] => Remy Blom\n    &#91;email] => r@aodw.nl\n)<\/code><\/pre>\n\n\n\n<p>Please note that in the <code>$results<\/code> object you don&#8217;t see any of your results, that had me looking puzzled and scratching my head for a while&#8230;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Okay, for a new project I want to try and move to MongoDB, I am really looking forward to a schema free database where I can simply just store my &#8216;documents&#8217; and do with them what I want! So let&#8217;s log into our server and get some stuff installed: For what it&#8217;s worth Mongo is &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.remyblom.nl\/?p=220\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;MongoDB on OpenBSD6.6 with PHP-FPM&#8230;&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,15,4,6],"tags":[],"class_list":["post-220","post","type-post","status-publish","format-standard","hentry","category-code","category-config","category-openbsd","category-php"],"_links":{"self":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/220","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=220"}],"version-history":[{"count":7,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions"}],"predecessor-version":[{"id":227,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=\/wp\/v2\/posts\/220\/revisions\/227"}],"wp:attachment":[{"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=220"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=220"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.remyblom.nl\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=220"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}