cloudfoundry / php-buildpack

A Cloud Foundry Buildpack for PHP.
Apache License 2.0
142 stars 346 forks source link

Can't enable mysql or mysqli extensions by overriding options.json #130

Closed sriganeshs closed 8 years ago

sriganeshs commented 8 years ago

Hi - I followed the steps provided by Daniel to override the options.json to enable myql and mysqli in my php buildpack. But that does not seem to work for me. Here's what I did:

  1. I created a directory named bp-config under my app directory.
  2. I created a options.json file with the following contents: { "PHP_EXTENSIONS": ["mysqli"] }
  3. Ran "cf push -m 128M -b https://github.com/cloudfoundry/php-buildpack.git "
  4. Included a PHP with the following contents: <?php if (extension_loaded('mysql') or extension_loaded('mysqli')) { echo "yes"; } else {echo "no";} ?>

My PHP script still tells me it cannot find the mysql or mysqli extensions.

What am I doing wrong??

Thanks, Sri

cf-gitbot commented 8 years ago

We have created an issue in Pivotal Tracker to manage this. You can view the current status of your issue at: https://www.pivotaltracker.com/story/show/112490725.

dmikusa commented 8 years ago

I created a directory named bp-config under my app directory.

Is your directory .bp-config or bp-config? The former will work, but the latter will not. You need the leading period.

I created a options.json file with the following contents: { "PHP_EXTENSIONS": ["mysqli"] }

Ex: https://github.com/dmikusa-pivotal/cf-ex-phpmyadmin/blob/master/.bp-config/options.json#L3

Included a PHP with the following contents: <?php if (extension_loaded('mysql') or extension_loaded('mysqli')) { echo "yes"; } else {echo "no";} ?>

This is an easier & better test.

<?php
phpinfo();
?>

Dan

sriganeshs commented 8 years ago

Thanks a bunch Dan. I am up and running now!!!

umairriaz82 commented 8 years ago

Hello Dan,

where do i create the .bp-config folder? when i try to create it on my mac, its not allowing me as it says that . extension can only be created by system. if i can't create the .bp-config folder, then i can't place the options.json file within that folder. can't i keep the options.json file in the root directly of my application?

flavorjones commented 8 years ago

@umairriaz82 - this directory should be created in the application's root directory.

Here's an example application: https://github.com/cloudfoundry/php-buildpack/tree/master/cf_spec/fixtures/php_app_using_httpd

Hope this helps, -m

dmikusa commented 8 years ago

.bp-config goes in the root of your project. i.e. where you run cf push from. You can see an example in the link above.

It doesn't look like finder on Mac will let you create hidden folders. See here: http://osxdaily.com/2010/05/10/create-a-hidden-folder-in-mac-os-x/

umairriaz82 commented 8 years ago

Thank you guys, i got the .bp-config folder created and pushed it to CF. i created the php file to test if its loaded and it says yes. but when i run the logs, i still get the following error messages:

[Wed Jun 15 20:36:14.087697 2016] [proxy_fcgi:error] [pid 54:tid 139944982992640] [client 202.69.56.45:5792] AH01071: Got error 'PHP message: PHP Notice: Undefined variable: host in /home/vcap/app/htdocs/dd3.php on line 45\nPHP message: PHP Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /home/vcap/app/htdocs/dd3.php on line 45\nPHP message: PHP Notice: Undefined index: cat in /home/vcap/app/htdocs/dd3.php on line 52\nPHP message: PHP Notice: Undefined index: cat3 in /home/vcap/app/htdocs/dd3.php on line 60\nPHP message: PHP Warning: mysqli::query(): Couldn't fetch mysqli in /home/vcap/app/htdocs/dd3.php on line 70\nPHP message: PHP Warning: Invalid argument supplied for foreach() in /home/vcap/app/htdocs/dd3.php on line 70\nPHP message: PHP Warning: mysqli::query(): Couldn't fetch mysqli in /home/vcap/app/htdocs/dd3.php on line 79\nPHP message: PHP Warning: Invalid argument supplied for foreach() in /home/vcap/app/htdocs/dd3.php on line 79\nPHP message: PHP Warning: mysqli::query(): Couldn't fetch mysqli in /home/vcap/app/htdocs/dd3.php on line 89\nPHP message: PHP Warning: Invalid argument supplied for foreach() in /home/vcap/app/htdocs/dd3.php on line 89\n'

this works fine on my local machine.

dmikusa commented 8 years ago

Run phpinfo() and see if it shows the extension enabled. I suspect that it's not being enabled. What are you putting in options.json?

umairriaz82 commented 8 years ago

on phpinfo() it says : it shows php extensions: mysqi under enabled column.

I have this under .bp-config/options.json { "PHP_EXTENSIONS": ["mysqli"] }

do i need to do more?

dmikusa commented 8 years ago

Looks like the extension is installed. I would suggest you check your script. There's probably something that's wrong in the script (given the errors you listed).

Note that the version of PHP and the options used in php.ini may not be the same on CF as on your local machine. In addition, the PHP build pack deploys using fast-cgi and not mod_php. These differences mean that a script working locally may not necessarily work on CF.