Using MacPorts php from command line

Some time ago I had installed Apache+MySQL using MacPorts in Mac OS X. It was all OK as long as I used the web browser to navigate thru the web pages, but as I runned PHP via CLI to execute Symfony2 commands I started having problems. It said for example that my time zone was not set, and I knew for sure that I had configured it in the php.ini file.

$ php app/console doctrine:schema:update --force

  
[ErrorException] Warning: date_default_timezone_get(): It is not safe to rely on the system' s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those me thods and you are still getting this warning, you most likely misspelled th e timezone identifier. We selected 'Europe/Berlin' for 'CET/1.0/no DST' ins tead in /Users/enekochan/Documents/Webs/este.es/vendor/monolog/monolog/src/ Monolog/Logger.php line 199

          

Searching the web for a solution I realized that the problem was that I was running the binary php that comes with Mac OS X, and I didn’t have the timezone configured for it. You can see where the php.ini file is by running this:

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => (none)

The first solution i came up with was to use the full path for the MacPorts php binary file:

$ /opt/local/bin/php app/console doctrine:schema:update --force
$ /opt/local/bin/php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /opt/local/etc/php5
Loaded Configuration File => /opt/local/etc/php5/php.ini

A better solution consists on adding to the systems path /opt/local/bin before /usr/bin. This can be done adding this to ~/.bash_profile:

PATH=/opt/local/bin:$PATH;export PATH

Then you have to close and open a new terminal or source the newly edited ~/.bash_profile:

$ source ~/.bash_profile

Ref: Stackoverflow

You might also like

Useful Apache 2 and MySQL 5 service aliases for MacPorts
Those are some aliases I use to start, stop and restart Apache 2 and MySQL on my MacPorts installation...
Change root password in MySQL
In GNU/Linux: $ sudo mysqld_safe --skip-grant-tables & $ mysql -u root -p #press enter to use a...
Apache 2 + MySQL 5 + PHP 5.3 + phpMyAdmin 3.5.4 installation script for Mac OS X using MacPorts
Based on the instructions provided by Gilles Fabio I've created a complete installation script to install...
Fix “macports checking for Tcl configuration… configure: error: Can’t find Tcl configuration definitions” when selfupdating Macports in Mac OS X 10.9 Mavericks
I've just upgraded my Mac OS X to Mavericks 10.9. When I tried to update Macports I got an error and...
Leave a comment ?

0 Comments.

Leave a Comment