s2i-php-container icon indicating copy to clipboard operation
s2i-php-container copied to clipboard

Run MongoClient on Openshift V3

Open maicolcantagallo opened this issue 7 years ago • 15 comments

Hi, when lunch my application return this error:

"Class 'MongoClient' not found in /opt/app-root/src"

So i changed to 'MongoDB\Driver\Manager' but the result is the same:

"Class 'MongoDB\Driver\Manager' not found"

There are modules: sh-4.2$ cd /opt/rh/rh-php70/root/usr/lib64/php/modules sh-4.2$ ls bcmath.so gd.so mysqlnd.so shmop.so wddx.so bz2.so gettext.so opcache.so simplexml.so xml.so calendar.so gmp.so pdo.so soap.so xmlreader.so ctype.so iconv.so pdo_mysql.so sockets.so xmlwriter.so curl.so intl.so pdo_pgsql.so sqlite3.so xsl.so dom.so json.so pdo_sqlite.so sysvmsg.so zip.so exif.so ldap.so pgsql.so sysvsem.so fileinfo.so mbstring.so phar.so sysvshm.so ftp.so mysqli.so posix.so tokenizer.so

why mongodb.so is not installed on server? what is the correct way?

Thanks

maicolcantagallo avatar Oct 09 '17 22:10 maicolcantagallo

@maicolcantagallo More info about adding mongodb driver can be found in https://github.com/sclorg/s2i-php-container/pull/169

omron93 avatar Oct 10 '17 05:10 omron93

Thanks @omron93 but i did not understand how to make the configuration. I've created a source code pods and a mongodb storage pods. Am I doing something wrong?

maicolcantagallo avatar Oct 10 '17 15:10 maicolcantagallo

Thanks @omron93 but i did not understand how to make the configuration. I've created a source code pods and a mongodb storage pods. Am I doing something wrong?

I think you do it right. Mongo driver has to be somehow installed in your source code pod to be able to access database.

omron93 avatar Oct 11 '17 06:10 omron93

thanks @omron93 but I do not understand how to install mongo db inside the pod. when i lunch command pecl install mongodb-1.3.0 return Cannot install, php_dir for channel "pecl.php.net" is not writeable by the current user

maicolcantagallo avatar Oct 11 '17 07:10 maicolcantagallo

@maicolcantagallo As a quick work around, please see the below instructions for using a PHP S2I image that I had created specifically to include the mongodb drivers. This is a workaround until I can update #169 to allow users to pecl install themselves.


In the web console, go to Builds > Builds. Click on the name of your application, and then under Actions, select Edit. Next change Build From to "Docker Image", and specify the following image depending on your version of PHP:

  • wgordon/openshift-s2i-php-56:latest for PHP 5.6
  • wgordon/openshift-s2i-php-70:latest for PHP 7.0

Then hit save! That's it. This is also assuming that you already have a composer.json file that includes "mongodb/mongodb". You can see an example of that here.

wgordon17 avatar Oct 11 '17 11:10 wgordon17

thanks @wgordon17 . do I have to import Docker Image source into my php source codes or do I have to insert an external path?

maicolcantagallo avatar Oct 11 '17 14:10 maicolcantagallo

When start build application return this error

Pulling image "maicolcantagallo/s2i-php-container/7.0" ... pulling image error : unauthorized: authentication required error: build error: unable to get maicolcantagallo/s2i-php-container/7.0:latest

maicolcantagallo avatar Oct 11 '17 15:10 maicolcantagallo

Hi @maicolcantagallo, you don't have to import it at all, you can just change the Build From value. Also, you have to specify Docker Image and use "wgordon" to pull from my DockerHub account

wgordon17 avatar Oct 11 '17 15:10 wgordon17

Thanks @wgordon17 . Now return this error

Pulling image "wgordon/openshift-s2i-php-70:latest" ... pulling image error : manifest unknown: manifest unknown error: build error: unable to get wgordon/openshift-s2i-php-70:latest

maicolcantagallo avatar Oct 11 '17 15:10 maicolcantagallo

Sorry, i was wrong to choose php version

maicolcantagallo avatar Oct 11 '17 15:10 maicolcantagallo

First step it's ok. Where is composer.json? I can't find it in my source

maicolcantagallo avatar Oct 11 '17 16:10 maicolcantagallo

@maicolcantagallo It's a file to tell Composer what dependencies are necessary to install. In the case of MongoDB, you need both the drivers (solved with my custom Docker image), and the extensions (solved by Composer).

Your composer.json file can be a very simple

{
    "require": {
        "mongodb/mongodb": ">=1.0"
    }
}

Add that to your git source, and re-build. The PHP S2I image handles the rest!

wgordon17 avatar Oct 11 '17 17:10 wgordon17

now works fine!

Thanks @wgordon17

maicolcantagallo avatar Oct 11 '17 18:10 maicolcantagallo

sorry @wgordon17 another question. If i want to use MongoClient instead of MongoDB\Driver\Manager is possibile?

Thanks

maicolcantagallo avatar Oct 11 '17 20:10 maicolcantagallo

@maicolcantagallo MongoClient has been deprecated, I'm not familiar enough with it to know how to install it. Sorry

wgordon17 avatar Oct 12 '17 13:10 wgordon17

Since MongoClient has been deprecated, then I am closing this issue. Feel free to reopen it in case it is still valid.

phracek avatar Mar 28 '23 07:03 phracek