I've installed a fresh copy of High Sierra today (After resetting my whole mac) so now I am at the point of installing all things related to programming, like the Laravel installer for now.
I have problems with installing the laravel installer and with the path I suppose.
I know there are a lot of questions a bit similiar to this but for some reason I haven't found the right answer yet.
So as the documentation of Laravel said I installed composer and that works just fine. After that I installed the Laravel installer with composer. I placed the command(?) for my path in the .bashrc file but after a re open of my terminal the command Laravel was not found. I knew from previous times this thing was a pain in the ass and I am also not very familiar with all those things in the command line so this is kinda hard for me.
What I did:
1) I installed composer. After that, I did mv composer.phar /usr/local/bin/composer in my terminal. Also I did mkdir -p /usr/local/bin because i had a fresh install so those directories were not found of course, because they didn't exist.
2) After that I ran composer global require "laravel/installer" in my terminal. This was all going great.
3) Last step was to do this thing with the PATH. I still don't know if I did this right. What I did was nano ~/.bashrc and then added export PATH=~/.composer/vendor/bin:$PATH to this file. This did not work, so I still can't use Laravel .. in my terminal. I don't know much about this source command but when I do source ~/.bashrc I can use this Laravel command but when I open a new tab or window I can't use it anymore.
4) Besides export PATH=~/.composer/vendor/bin:$PATH in the .bashrc file I also tried export PATH="$HOME/.composer/vendor/bin:$PATH" in that file. that doesn't work either.
Is there someone that can help me out? Good to know is that I just installed a fresh copy of OS and did nothing besides installing some normal programms. Laravel/Composer were my first things with the terminal.
It might be that your terminal program is set to create a login shell, which doesn't source ~/.bashrc
Try adding this to ~/.bash_profile
[[ -f ~/.bashrc ]] && . ~/.bashrc
I have installed Composer locally only for one Laravel project
~/phpstorm/myproject/composer.phar
and didn't have any problem till I tried to create a new Laravel project, then I got an error:
Could not open input file: composer.phar
I tried to add the .phar file directly to the PATH, but it doesn't seem to change anything.
PATH=~/phpstorm/myproject/composer.phar:$PATH
Does somebody know how I could manage this problem without installing Composer globally? In the Internet I only found this easiest kind of solution, but it doesn't suit me, alas.
Thanks for your proposals in advance!
Change the name from composer.phar to composer by this command:
mv composer.phar composer, give it execution permissions by running the following: chmod 0755 composer or chmod a+x composer, and put the current path to the PATH env variable in your .bashrc or .zshrc file, restart your terminal and it should work, or you can always install it globally. Bests! ;)
You don't need to add composer to your path unless you want to use it globally. You can just do
php composer.phar
Another, easy option would be to create an alias for it in your shell
eg for bash:
alias composer='php ~/phpstorm/myproject/composer.phar'
I am working on a PHP development project that includes Composer. I am relatively new at this so I thank you in advance for your patience with my question, and ask that you reply in as simple of language as possible.
I am trying to run the following command in terminal:
php composer.phar dump-autoload -o
I am getting the following error:
Could not open input file: composer.phar
This is the file path to my composer.phar folder:
/Users/administrator/Dropbox/2016/2016ProjectFiles/2016ProjectsWeb/GG/authentication/composer.phar
I have tried several ways to provide the file path, including the following:
$cd /Users/administrator/Dropbox/2016/2016ProjectFiles/2016ProjectsWeb/GG/authentication/composer.phar dump-autoload -o
...and...
$cd ../authentication/composer.phar dump-autoload -o
It is entirely possible/likely that my syntax is wrong or there is a stupid simple solution that I just don't know. I just need to be able to run file commands on composer.phar from terminal. Any help is much appreciated!
I figured it out. Here is the answer in case any fellow newbies run into this same conundrum. First, enter the following command into terminal to tell it where to look for Composer:
cd ~/[YOUR FOLDER NAME]
I learned that "~/" is a stand in for your "Users/Username" folders, so if your version of composer is nested beyond that you'll have to write out the file path yourself. For example, if your file is in "Dropbox" in a folder called "Projects" then your first command would look like this...
cd ~/Dropbox/Projects/[YOUR FOLDER NAME]
Then, you'll see your terminal command line change. For example, before I ran the command above, mine looked like...
Admin-MacBook-Pro:~ administrator$
...afterward it looked like...
Admin-MacBook-Pro:authentication administrator$
"authentication" is the folder where I saved Composer. YAY! So then I was able to type in my request:
php composer.phar dump-autoload -o
And it (finally!) returned "Generating optimized autoload files". So there you have it. I hope I saved you a couple of hours staring at the terminal window.
Thank you, Tomáš Votruba for your suggestions!
You have downloaded composer.phar file successfully. Great job. Now the second steps is to make ti globally accessible like php or git.
This article about installing composer in Mac describe as follows:
Quoting Running Composer section
Run commads:
sudo mv composer.phar /usr/local/bin/
vim ~/.bash_profile
Now add to .bash_profile:
alias composer="php /usr/local/bin/composer.phar"
And you're done.
Run composer anywhere you need.
So simply put. I did an in-place update from 10.10.5 to 10.11.1 recently and just discovered that my composer package manager is no longer working.
I've tried a number of solutions and have it installed into the correct directory, but my alias 'composer' which was set globally is now not able to find the composer file.
Following the steps as always
First, Download
curl -sS https://getcomposer.org/installer | php
Then move
sudo mv composer.phar /usr/local/bin/
Then update bash_profile
vim ~/.bash_profile
Finally add alias
alias composer="php /usr/local/bin/composer.phar"
And my end result, when calling composer is this
Could not open input file: /usr/local/bin/composer/
Any ideas why this might happen?
Found the answer by talking to someone on reddit.
///
First off, try going to the composer file in /usr/local/bin and double-click it. It should open up in a new Terminal window. This should at least confirm that the file can be executed.
Second, you shouldn't need to have an alias to use composer. You merely point your path to it like this:
export PATH="~/.composer/vendor/bin:$PATH"
If you have any other path variables you'll just attach a colon to the end of it like so:
export PATH="/usr/local/php5/bin:~/.composer/vendor/bin:$PATH"
Hope this helps.
I would like to use MAMP's version of PHP instead of the default installed on my mac. I tried using
ln -s /Applications/MAMP/bin/php5.3/bin/php php
but I get a "File exists" error. What's the best way to work around this so I can just type php instead of the full path?
I have created a symlink at the original php location.
1. Locate your osx php version with:
which php
The result should be:
/opt/local/bin/php
2. Backup (move) your original php binary:
sudo mv /opt/local/bin/php /opt/local/bin/php.bak
3. Create the symlink:
sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
4. Run your new php version:
php -v
PS:
In order for this to work on El-Capitan
Reboot your Mac to RecoveryMode (hold Cmd+R on boot)
Open Terminal and enter: csrutil disable
Reboot
either : sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /opt/local/bin/php
or sudo ln -s /Applications/MAMP/bin/php/php5.4.4/bin/php /usr/bin/php
Reboot again to RecoveryMode and re-enable security: csrutil enable
I would not recommend trying to modify the default version of PHP that is called on the command line. Doing so may break other parts of your system as well as provide you with problems in the future, should you decide to upgrade your OS.
There is an alternative that may meet your needs. You can create an alias to your copy of MAMP's php 5.3. In my case I named the alias phpmamp. Open your terminal and type:
alias phpmamp='/Applications/MAMP/bin/php5.3/bin/php'
Now, typing phpmamp at the command line will launch the MAMP php interperter. Verify this by typing:
phpmamp --help
You will most likely want to store this, and any other alias, in a ~/.bash_profile This will allow the aliases to persist across reboots. Otherwise, the alias should only last for the particular terminal session you are in. More information about creating a .bash_profile file can be found here:
http://www.redfinsolutions.com/redfin-blog/creating-bashprofile-your-mac
I prefer not to tamper with the current files, so I just prepend the MAMP PHP bin folder to the $PATH env variable.
You can edit ~/.bash_profile and add the the following line to the top
export PATH="/Applications/MAMP/bin/php/php5.6.1/bin:$PATH"
Just change the PHP version to the current version you are using.
Don't forget to do source ~/.bash_profile after you edit the file.
I wasn't pleased with the results / solutions I've found on the net so far, because the php.ini configs weren't loaded properly in all cases and on all systems, espacially when you need modules like ioncube and others (it's even more confusing on MAMP Pro). That's why I've created my own php version aliases (with configs), so I've come up with the following solution, as example (based on MAMP Pro, remember to adjust the php.ini paths to your needs):
Edit your .bash_profile
vim ~/.bash_profile
And add the following entries:
alias php55="/Applications/MAMP/bin/php/php5.5.26/bin/php -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.5.26.ini'"
alias php56="/Applications/MAMP/bin/php/php5.6.10/bin/php -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.10.ini'"
alias php56cgi="/Applications/MAMP/bin/php/php5.6.10/bin/php-cgi -c '/Library/Application Support/appsolute/MAMP PRO/conf/php5.6.10.ini'"
Re-Initialize the .bash_profile in the current terminal session (otherwise you won't see any changes, unless you restart the terminal):
source ~/.bash_profile
If you have some additional modules installed, then you can test it with php56 -v and you should get a output of the ioncube, etc. modules. Otherwise test it with php56 -i | grep "yourModuleNameOrSomethingElse"
Now you are able to easily use one of the php versions like "php56" in your terminal with all configs loaded. So it's perfect for testing and building your applications through all iterations of versions including the right php.ini configs through the terminal.
For normal MAMP Users, the configs should be located in /Applications/MAMP/conf/ I think. Happy programming.
2021 - For those using ohmyzsh, the file to edit is:
/Users/your_user/.zshrc
so, you can edit this file and add the path:
export PATH=/Applications/MAMP/bin/php/php8.0.0/bin:$PATH
Works Perfectly with Big Sur
The latest version of MAMP (Version 5+) offers an easy way to make the MAMP PHP version available to the command line. Just select "PHP" in the the side bar menu and check "Make this version available on the command line". Easy peasy! :)
screenshot
If your terminal is using zsh (oh-my-zosh) as shown in the attachment.
check image
Do the following.
Mac Big Sur uses "zsh" Oh-my-zosh for the terminal. so, I did the following.
open terminal.
check if you have .zshrc file in your profile path (/Users/yourProfileName)
if you don't have .zshrc file, create one using (~ touch .zshrc) command.
add these lines:
export MAMP_PHP=/Applications/MAMP/bin/php/php7.4.12/bin
export PATH="$MAMP_PHP:$PATH"
save the file. close the terminal and reopen it. Now run "which php".
let me know if you need help.
For Mac OS Catalina. Find directory /Users/<user_name>/.zprofile
and add (for example)
# MAMP PRO PHP
export PATH="/Applications/MAMP/bin/php/php7.4.2/bin:$PATH"
after reboot, in terminal
which php
new php version /Applications/MAMP/bin/php/php7.4.2/bin/php
Well, the 'file exists' error is probably because you attempted to create a sym-link with the name of a file that was already there. I assume you were in the directory containing the php version you were trying to replace or that this was a second attempt and you did not first remove the existing sym-link. I agree with the others with regard to not "replacing/modifying" the default version of php.
Based on the second part of the question, the best way to get around having to type the full path, the answers suggesting an alias are right on point with that. When multiple versions are involved though, that means having to call something other than php to run the version you want to run.
I have a script that lets me "select" the version of php that I would like to work with which then creates a sym-link to that version and lets me simply enter 'php' as my command when I want to use it. I wrote a blog about it here where you can get the script. Based on the answer given by #ioCron I may need to revisit my script to account for the different config folders associated with each version.
Well none of this was working for me with OSX10.12.5
i have mac ports php70 installed at /opt/local/bin
which php showed:
/usr/bin/php
I set up the aliases and local paths etc, which mostly worked for me, but other programs were failing (like composer) so the solution for me was to prepend:
/opt/local/bin
/opt/local/sbin
to the file /etc/paths
then it all worked a charm!