1

So Apache has its own service account, and when i load a page from the URL, on my browser, it loads runs the page with the service account and it works fine, no errors.

But when i do php -q "LOCAL PATH TO FILE", on root account from the terminal over SSH i get errors such as:

For MySQLi = "Call to undefined function mysqli_connect()"

For MySQL = "mysql_connect(): No such file or directory"

Now the thing is, it does work fine if i load the page from my browser, just not when i run it from terminal.

I need to be able to run it from the terminal because of CronJobs.

This originally worked, but im not sure why it has stopped working, apparently i need to install a PHP module to get it to work, but im not sure because im having a hard time finding results that are the same situation as my issue.

I am using CentOS.

Thanks

Headchopperz
  • 117
  • 3
  • 13
  • 3
    http://stackoverflow.com/questions/11585399/command-line-php-mysqli-fails-but-works-via-web-server-and-works-in-local – cristi _b Jan 02 '13 at 16:38
  • i tried that, it doesnt work, ive already installed php-mysqli – Headchopperz Jan 02 '13 at 16:47
  • are you using `localhost` or `127.0.0.1` or some other host for connection? – user1190992 Jan 02 '13 at 16:58
  • im using localhost, and i have tried both localhost and 127.0.0.1, im using the latest stable version of PHP too. The thing that confuses me, is these files work fine when i navigate to them from my browser. – Headchopperz Jan 02 '13 at 17:02
  • 2
    Often the web server and the CLI SAPI use different ini files. Run `php -i` from the command line, verify that if shows MySQLi as being enabled, and if (when) it is not, go to the ini file identified near the top of the output and enable it. – DaveRandom Jan 02 '13 at 17:03
  • Maybe [this](http://stackoverflow.com/a/7264459/1190992) can help .. – user1190992 Jan 02 '13 at 17:03
  • @user1190992 I have /var/lib/mysql/mysql.sock for mysql and mysqli, i dont have /tmp/mysql.sock, does that mean anything? "MYSQLI_SOCKET /var/lib/mysql/mysql.sock", i have also verified that /var/lib/mysql/mysql.sock does exist on the server – Headchopperz Jan 02 '13 at 17:10
  • @DaveRandom if i look at phpinfo(), then mysqli is clearly enabled, is there an easy way to see php -i (its the same anyway isnt it?), because i can only see the last 20 or so lines before it gets cut off. – Headchopperz Jan 02 '13 at 17:12
  • @DaveRandom i think your right, it looks like CLI isnt actually using a php config file at all... "php -i | grep 'Configuration File'" Returns: "Configuration File (php.ini) Path => /usr/local/lib" - "Loaded Configuration File => (none)", should i set it to the same php config file as the site which is in /etc/php.ini, and if so, how? – Headchopperz Jan 02 '13 at 17:19
  • i copied the php ini file to there, its now loading it, no dice... – Headchopperz Jan 02 '13 at 17:29
  • 1
    @Headchopperz You can specify the ini file that is loaded at call time - add `-c /path/to/php.ini` to your command line. – DaveRandom Jan 02 '13 at 17:33
  • php -c "/etc/php.ini" -f "/path/to/file/" doesnt work, so i guess its not as simple as just using the right php.ini file... – Headchopperz Jan 02 '13 at 17:38
  • I have resolved the issue for mysql using user1190992s suggestion, but not for mysqli, i would rather use mysqli, but at least i can make a connection to the database with php from the CLI now. – Headchopperz Jan 02 '13 at 17:44
  • 1
    Probably CLI is using different php.ini. Just find it and turn on mysqli. – shark555 Jan 02 '13 at 18:46

0 Answers0