The problem with Macports PHP 5.4, composer and OS X
Update, April 19, 2014: @neverpanic has informed me that running the command
sudo port select --set php php54 will create the symlinks for you. This command will also allow you to switch between PHP versions easily.
One annoying thing about using composer under OS X 10.9 Mavericks (and other installations) is that composer only tries to use the binary ‘php’ to perform operations. The problem here is that Macports installs the php 5.4 binary in /opt/local/bin/ as /opt/local/bin/php54 (as it should). In most cases when you run the
composer update command you see something like the following:
elvis$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files Mcrypt PHP extension required. Script php artisan clear-compiled handling the post-update-cmd event returned with an error [RuntimeException] Error Output: update [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--lock] [--no-plugins] [--no-custom-installers] [--no-scripts] [--no-progress] [--with-dependencies] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [packages1] ... [packagesN]
Yikes! Many solutions suggestion you run composer with the no-scripts option,
composer update --no-scripts which seems to work, right?
Wrong. This is a terrible workaround. You will immediately run into problems with frameworks which leverage other phar / php binary files from the commmand line such as Laravel artisan.
I found the only reliable work around was to symlink the php54 files to files without the ’54’ suffix. If you have installed php via Macports it will have already updated your PATH to check /opt/local/bin before checking /usr/bin for the ‘php’ binary. If not, you may wish to edit your ~/.bash_profile file and adjust it to look like the following:
If your ~/.bash_profile is already modified you can create the symlinks and you should be good to go.
Run the following commands to create the symlinks:
sudo ln -s /opt/local/bin/php54 /opt/local/bin/php sudo ln -s /opt/local/bin/php-config54 /opt/local/bin/php-config sudo ln -s /opt/local/bin/phpize54 /opt/local/bin/phpize
Now when you run composer you should no longer get any strange errors:
elvis$ composer update Loading composer repositories with package information Updating dependencies (including require-dev) Nothing to install or update Generating autoload files Generating optimized class loader
Woohoo! No more shitty work around. No more errors. This should work for other versions of php like php53 and php55.