Activating PHP extensions in Bluemix

2019-05-06 20:10发布

This is a purely Bluemix question!

I've got code running smoothly on a localhost but when I migrated it to Bluemix my DB connection failed me. Checking the logs I found the issue "Call to undefined function mysqli_init()" HTTP response 500. I have found out that extension have been disabled to make it smaller and have found some details about it: Buildpack options.

Unfortunately I have tried that and failed. Maybe I have misunderstood the solution.

Screenshot

Any Help would be greatly appreciated.

EDIT:

bgconfig --> bp-config solved the "undefined function error"

It seems that some extension have been added but not all. "Fatal error:Class 'PDO' not found in /home/vcap/app/htdocs/db_config.php on line 15"

I have however added the PDO extension in options.json.

I tried adding a php.ini overwrite Screenshot

But still get the same error...

For info: line 15 on db_config.php is simply:

$db = new PDO('mysql:host=us-cdbr-iron-east-02.cleardb.net;dbname=ad_dae231843a962ca', $username, $password);}

within try & catch of course.

Any Clues?

4条回答
仙女界的扛把子
2楼-- · 2019-05-06 20:20

Do you have mysql defined in your composer.json?

{
  "require": {
    "ext-mysqli": "*"
  }
}

https://github.com/IBM-Bluemix/php-mysql

查看更多
Lonely孤独者°
3楼-- · 2019-05-06 20:23

The options.json file is correct that you have posted. However it is in the wrong directory, it should be in a folder called .bp-config/. Renamed the folder and repush your app back to Bluemix.

Also try adding pdo_mysql to .bp-config/options.json.

I just tested some code with the PDO driver against a DB and it worked fine. My .bp-config/options.json file is below.

{
    "PHP_EXTENSIONS": ["pdo", "mysqli", "pdo_mysql", "mysql"]
}

I would double check your access to the database with a MySQL desktop client. It looks like an issue with your connection information.

I have an example app for testing your connection information with PDO.

查看更多
神经病院院长
4楼-- · 2019-05-06 20:24

The instructions to add the options.json file are the correct ones and from your screenshot the file looks to be correct. The problem is the directory that you placed the options.json file in you have called .bgconfig when it should be .bp-config.

Can you change the directory name, repush the app to Bluemix and it should work.

查看更多
干净又极端
5楼-- · 2019-05-06 20:24

you can add extension in composer.json file

{
  "require": {
    "ext-mysqli": "*",
    "ext-gd": "*"
  }
}
查看更多
登录 后发表回答