Skip to content

Instantly share code, notes, and snippets.

@tommcfarlin
Last active May 30, 2022 10:42
Show Gist options
  • Save tommcfarlin/c652d5df78243954f7beab60e95543c2 to your computer and use it in GitHub Desktop.
Save tommcfarlin/c652d5df78243954f7beab60e95543c2 to your computer and use it in GitHub Desktop.
Setting up Composer with MAMP

Using MAMP, PHP, and Composer

For PHP 5.6.10

Add the following to the top of .bash_profile:

PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -2 | head -1`
alias composer='php /Applications/MAMP/bin/php/${PHP_VERSION}/bin/composer.phar'
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
```

## Using PHP7

If you _are_ using MAMP, then this will allow you to use the latest version installed with PHP.

```
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
```

## Example of Adding PHPUnit For Composer

```json
{
    "require-dev": {
        "phpunit/phpunit": "5.0.*"
    }
}
```

## MySQL as Executable Functions

If you're interested in tweaking what version of MySQL is used and _how_ it's used, then take a look at the code below.This will makes it usable from within shell scripts (unlike an alias) and will also avoid conflicting with other tools on the system.

```
mysql() {
    /Applications/MAMP/Library/bin/mysql "$@"
}
mysqladmin() {
    /Applications/MAMP/Library/bin/mysqladmin "$@"
}
export -f mysql
export -f mysqladmin
```

It's outside the scope of the general purposes of this document, but worth noting should this come up.
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -2 | head -1`
alias composer='php /Applications/MAMP/bin/php/${PHP_VERSION}/bin/composer.phar'
export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
curl -sS https://getcomposer.org/installer | php
{
"require-dev": {
"phpunit/phpunit": "5.0.*"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment