Composer installed, get env: php: No such file or directory - composer-php

I am using MAMP on macOS 12 (Monterey), so I want to run through MAMP to use PHP. Therefor I added this alias:
nano ~/.bash_profile
alias phpmamp='/Applications/MAMP/bin/php/php5.4.10/bin/php'
Then I ran:
curl -sS https://getcomposer.org/installer | phpmamp
Which resulted in:
Composer (version 2.4.2) successfully installed to: /Users/johnmiles/composer.phar
Use it: php composer.phar
Then I made it available globally:
sudo mv composer.phar /usr/local/bin/composer
But when I run composer I get:
env: php: No such file or directory
So how do I tell composer to use phpmamp?

Within the Terminal, run vim ~/.bash_profile
Type i and then paste the following at the top of the file:
export PATH=/Applications/MAMP/bin/php/php8.0.8/bin:$PATH
Hit ESC, Type :wq, and hit Enter
In Terminal, run source ~/.bash_profile
In Terminal, type in which php again and look for the updated string. If everything was successful, It should output the new path to MAMP PHP install.
In case it doesn't output the correct path, try closing the terminal window (exit fully) and open again, it should apply the changes (Restart in short).

Related

Laravel error: Laravel Sail no such File or directory found

I am following this tutorial,
I installed Docker and WSL2(Ubuntu 20.04.4 LTS) on my windows system, as shown in image below,
When i am trying to run Laravel project using command,
./vendor/bin/sail up
Why i am getting error no such file or directory found?
Instead of:
./vendor/bin/sail up ❌
Use this:
bash ./vendor/laravel/sail/bin/sail up ✅
composer update && npm install worked for me
This worked for me:
Step 1
In your terminal, run this to open your .bash_profile file :
nano ~/.bash_profile
And paste this :
if [ -r ~/.bashrc ]; then
source ~/.bashrc
fi
Exit and save the modification.
Step 2
Still in your terminal, run this to open your
.bashrc file :
nano ~/.bashrc
And paste this :
alias sail='bash vendor/bin/sail'
Exit and save the modification.
Step 3
You can now open any Laravel project using Sail and write the following command to start it :
sail up
Or to run it on background:
sail up -d
I'm using Ubuntu 20.04 on WSL2

Composer: Command Not Found on Mac

I have installed Composer as per the instructions command not found
After installing I get the prompt that Composer is successfully installed but when I go to check the version it gives me error "Composer: Command Not Found"
I have been looking how to fix this issue and I had to read and understand little bit and the environment variables on MAC.
I understand the issue looks simple but it will get over complicated if you didn't understand how to install composer probably.
Solution 1
I found this solution here: https://duvien.com/blog/installing-composer-mac-osx
Open a terminal and navigate to your user directory, ie cd /User//
Run this command shown below to download Composer. This will create a Phar (PHP Archive) file called composer.phar:
curl -sS https://getcomposer.org/installer | php
Now we move composer.phar file to a directory
sudo mv composer.phar /usr/local/bin/
We want to run Composer with having to be root al the time, so we need to change the permissions:
sudo chmod 755 /usr/local/bin/composer.phar
Next, we need to let Bash know where to execute Composer:
nano ~/.bash_profile
Add this line below to bash_profile and save
alias composer="php /usr/local/bin/composer.phar"
and then run this command:
source ~/.bash_profile
Finally, run:
composer --version
Solution 2:
I understand that the first command you will find online when you try to google this issue would be
curl -sS https://getcomposer.org/installer | php
But actually this is the main terminal installation but sometimes I wanted to manually install the composer, so this 2nd solution about manually installing the composer in specific directory
First of all you need to understand where are you now on the terminal
use
pwd
and then install composer manually using the following commands
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') ==='baf1608c33254d00611ac1705c1d9958c817a1a33bce370c0595974b342601bd80b92a3f46067da89e3b06bff421f182') { echo 'Installer verified'; } else { echo 'Installer corrupt';
unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
to use it on that case you will read on the terminal to use this composer installation use
Use it: php composer.phar
so just write
php composer.phar
and it should be working.... one more thing, during this installation you can install the composer to specific directory / project folder... in that case you can use a flag with command No.4 to tell the terminal to install the composer in specific directory...this flag is --install-dir=your-directory-path
and you will the terminal this time after installing composer asking you to use the following path to call the composer
Use it: php /Users/muatafa/composer.phar
if you want to read more about this issue, I think you must read the composer documentation how to install it>>> https://getcomposer.org/download/
that's how I solved my current issue... if you still have any issues comment on this replay & Hopefully we can figure it out!
I had the same problem. "composer require something" works if installed in global and not locally.
If you install composer locally you'll then install dependencies using "php composer.phar require nameofyoudependency"
To install globally open a terminal to install as mentionned on the composer website. Then run "sudo mv composer.phar /usr/local/bin/composer"
Now you can use "composer" directly to install dependencies like => "composer require something/sdk"
the composer you installed is still named /usr/local/bin/composer.phar - look in the second yellow/brownish line in your output. Just rename it to just composer
Your composer command is not set to path, use
export PATH=$PATH:/usr/local/bin/
I had the same issue, After installing composer using the command line on their website. I forgot to put composer.phar into a directory on my PATH, so it can simply be called from any directory (Global install). and then I ran this command "sudo mv composer.phar /usr/local/bin/composer" and it was resolved
I figured out. in place of "composer require twilio/sdk" I needed to use
"composer.phar require twilio/sdk" since I am on mac. It worked

Laravel package installation on live server

How to install package in laravel on live server, whenever I run "command composer require monolog/monolog". It gives error Could not open input file: /home/root/composer.phar
First of all, you should not run composer require on live server. You should only run composer install so you should require it locally, test if everything is working fine and then on live server just install library that is tested in your application.
About error:
Could not open input file: /home/root/composer.phar
make sure this file really exists (if not you can download it from Composer site) and make sure it has correct permissions (it should have execute permission) - use chmod +x composer.phar to make it executable
Please try like this.
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
$ php composer.phar update monolog/monolog
You can install package without any problem.

Laravel new -bash: laravel: command not found [duplicate]

I have installed Laravel using composer without problems, but when I try to execute "laravel" in my terminal I have this typical error:
-bash: laravel: command not found
If I read the documentation of the official site I need to do that:
Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable is found when you run the laravel command in your terminal.
But I don't know how to do.
Can you help me with that? Thanks!!
Ok, I did that and it works:
nano ~/.bash_profile
And paste
export PATH=~/.composer/vendor/bin:$PATH
do source ~/.bash_profile and enjoy ;)
Important: If you want to know the difference between bash_profile and bashrc please check this link
Note: For Ubuntu 16.04 running laravel 5.1, the path is: ~/.config/composer/vendor/bin
On other platforms: To check where your Composer global directory is, run composer global about. Add /vendor/bin to the directory that gets listed after "Changed current directory to ..." to get the path you should add to your PATH.
Add the following to .bashrc file (not .bash_profile).
export PATH="~/.composer/vendor/bin:$PATH"
at the end of the file and then in terminal run source ~/.bashrc
To verify that:
echo $PATH
(Restart the terminal, Check & Confirm the path is there)
Run the laravel command!
Note:
For Ubuntu 16 and above use below:
export PATH="~/.config/composer/vendor/bin:$PATH"
When using MacBook, refer to the snippets below;
For zsh:
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
For Bash:
echo 'export PATH="$HOME/.composer/vendor/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
Solution on link http://tutsnare.com/laravel-command-not-found-ubuntu-mac/
In terminal
# download installer
composer global require "laravel/installer=~1.1"
#setting up path
export PATH="~/.composer/vendor/bin:$PATH"
# check laravel command
laravel
# download installer
composer global require "laravel/installer=~1.1"
nano ~/.bashrc
#add
alias laravel='~/.composer/vendor/bin/laravel'
source ~/.bashrc
laravel
# going to html dir to create project there
cd /var/www/html/
# install project in blog dir.
laravel new blog
Type on terminal:
composer global require "laravel/installer"
When composer finish, type:
vi ~/.bashrc
Paste and save:
export PATH="~/.config/composer/vendor/bin:$PATH"
Type on terminal:
source ~/.bashrc
Open another terminal window and type: laravel
If you're using Ubuntu 16.04.
You need to find the composer config files in my case is :
~/.config/composer or in other cases ~/.composer/
you can see the dir after this command composer global require "laravel/installer"
after Laravel Installed you can find your laravel in ~/.config/composer/vendor/laravel/installer/.
and you will find the Laravel shortcut command in here : ~/.config/composer/vendor/bin/
set your .bashrc using nano ~/.bashrc and export your composer config file :
export PATH="$PATH:$HOME/.config/composer/vendor/bin"
or you can use allias. but above solution is recommended.
alias laravel='~/.config/composer/vendor/laravel/installer/laravel'
Now refresh your bashrc using source ~/.bashrc and then laravel is ready!!
above steps works with me in Ubuntu 16.04
For zsh and bash:
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
source ~/.zshrc
source ~/.bashrc
For bash only:
export PATH=~/.config/composer/vendor/bin:$PATH
source ~/.bashrc
For Developers use zsh Add the following to .zshrc file
vi ~/.zshrc or nano ~/.zshrc
export PATH="$HOME/.composer/vendor/bin:$PATH"
at the end of the file.
zsh doesn't know ~ so instead it by use $HOME.
source ~/.zshrc
Done! try command laravel you will see.
If on mac (and think *nix) just run this in your terminal.
export PATH="~/.composer/vendor/bin:$PATH"
For those using Linux with Zsh:
1 - Add this line to your .zshrc file
export PATH="$HOME/.config/composer/vendor/bin:$PATH"
2 - Run
source ~/.zshrc
Linux path to composer folder is different from Mac
Use $HOME instead of ~ inside the path with Zsh
The .zshrc file is hidden in the Home folder
export PATH= exports the path in quotes so that the Laravel executable can be located by your system
The :$PATH is to avoid overriding what was already in the system path
If you are coming here 2021 this has worked for me also using Ubuntu 16.04
nano ~/.bash_profile
export PATH=$HOME/.config/composer/vendor/bin:$PATH
ctrl+x and save
source ~/.bash_profile
For MAC users:
1. Open terminal
cd ~
2. Double check the $PATH
echo $PATH
3. Edit file
nano ~/.bash_profile
4. PASTE
export PATH="~/.composer/vendor/bin:$PATH"
Don't forget to put quotation marks.
5. control + X (y + enter to save the file and exit)
Now start vagrant, go to your folder and try:
laravel new yourprojectname
I set the PATH,but it didn't work.I find other way to solve it. (OSX 10.10 & laravel 5.2)
1) find the executable file:
~/.composer/vendor/laravel/installer/laravel
2) give execute permissions:
chmod +x ~/.composer/vendor/laravel/installer/laravel
3) make a soft link to /usr/bin:
sudo ln -s /Users/zhao/.composer/vendor/laravel/installer/laravel /usr/bin/laravel
1) First, download the Laravel installer using Composer:
composer global require "laravel/installer"
2) Make sure to place the ~/.composer/vendor/bin directory in your PATH so the laravel executable can be located by your system.
set PATH=%PATH%;%USERPROFILE%\AppData\Roaming\Composer\vendor\bin
eg: “C:\Users\\AppData\Roaming\Composer\vendor\bin”
3) Once installed, the simple laravel new command will create a fresh Laravel installation in the directory you specify.
eG: laravel new blog
type on terminal:
nano ~/.bash_profile
then paste:
export PATH="/Users/yourusername/.composer/vendor/bin:$PATH"
then save (press ctrl+c, press Y, press enter)
now you are ready to use "laravel" on your terminal
If you have Composer installed globally, you can install the Laravel installer tool using command below:
composer global require "laravel/installer=~1.1"
Late answer...
Composer 1.10.1 2020-03-13 20:34:27
laravel --version
Laravel Installer 3.0.1
Put
export PATH=$PATH:~/.config/composer/vendor/bin:$PATH
in your ~/.zshrc or ~/.bashrc
source ~/.zshrc or ~/.bashrc
This works
Composer should be installed globally:
Run this in your terminal:
mv composer.phar /usr/local/bin/composer
Now composer commands will work.
My quick way of creating a new project
//install composer locally on web root - run the code from: https://getcomposer.org/download/
Then install laravel:
php composer.phar require laravel/installer
Then create the project without adding anything to any path
vendor/laravel/installer/bin/laravel new [ProjectName]
//add project to git
cd ProjectName
git init
git remote add origin git#...[youGitPathToProject]
Wondering if this way of doing it has any issues - please let me know
Just use it:
composer create-project --prefer-dist laravel/laravel youprojectname

Error trying to run composer with Laravel 4

I am new to Laravel and to using the terminal.
I installed composer globally and it is running, but when I try to mv I get an error:
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
No such file or directory
I echo $PATH and get this:
/Users/ebernal/.rvm/gems/ruby-1.9.3-p286/bin:/Users/ebernal/.rvm/gems/ruby-1.9.3-
p286#global/bin:/Users/ebernal/.rvm/rubies/ruby-1.9.3-
p286/bin:/Users/ebernal/.rvm/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
Not sure what all this means, and why can't Terminal not find /usr/local/bin?
I can run composer using composer.phar and it mostly runs, but at the very end I get this error:
Script php artisan clear-compiled handling the post-install-cmd event returned with an
error
[RuntimeException]
Error Output:
Thanks for your help
As it says in the error message, no such file or directory.
Locate the /usr/local/bin/composer file. Show hidden folders or use the cd command to navigate through Terminal.
You possibly don't have a composer folder, hence why it can't move it into it.

Resources