Using PHP 5 from Dreamhost through Command Line

I recently ran into an issue that was a bit of a pain in the ass and I wanted to put it up here both to help anyone else out who runs into it and for my own reference.

I have been doing a lot of data mining/visualization recently which requires a large number of calls to several data apis. I am using PHP because I am familiar with it, I like it, and I can’t stand the structure of Python. One advantage of php is that you can execute it in the browser, which I normally take advantage of when I am working on API requests or data scraping. As my scripts have gotten more and more complex lately, I’ve quickly run into Internal Sever Error 500 messages which can only be fixed by limiting the amount of calls to make at a time. At first I thought this was just a limit of my server/php, but then I remembered how I recently was able to import a 4GB database into MySQL through the terminal with no problems after PhpMyAdmin was unable to handle anything near this. So I decided to try to run my script through the command line using SSH with dreamhost.

I attempted to execute the script, and then I got a bizarre error: “Fatal error: Call to undefined function: mysqli_connect()” This error never came up in the browser, yet it was coming up in terminal. After some quick searching I found out this error was attributed to not having PHP 5 installed on my server. This is super strange because PHP 5 is on my server according to dreamhost. I then did a version check on php using the -v parameter. Sure enough, version 4.4.9.

So what was the solution? I found a couple resources after playing around with phrases to search on google, and figured out that while php 5 WAS installed on my server, the command line space is different than the web space, so I had to explicitly point to PHP 5 in order to use it.

Running the following command led me to the path of PHP5 “whereis php” which returns the following path “/usr/local/php5/bin/php”.

So super short finish to a long explanation, use “/usr/local/php5/bin/php” instead of “php” to execute php scripts using version 5 on Dreamhost.



This entry was posted on Saturday, November 14th, 2009 at 10:45 am and is filed under Code, php. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

3 Responses to “Using PHP 5 from Dreamhost through Command Line”

  1. Ivan Guardado

    Thanks!!! It was usefull for me!

  2. Yasin Masukor

    Legendary! just spent a day tearing my hair out over this.

  3. Steve

    :) Glad I could help!

Leave a Reply

Your comment