Composer not found error on MacOs Terminal - composer-php

To install Laravel on latest macOS Monterey 12.5, I installed HomeBrew, used that to install php, then used instructions on Composer.Org to install composer which installed composer.phar on my current directory.
I added my current directory to PATH. But could not run Composer. Then created a directory /usr/local/composer and did "sudo mv composer.phar .." into that directory, which did move the file. Then created a .zshrc file in my current directory and added both my current directory and /usr/local/composer on permanent PATH.
But I still can't invoke composer. zsh gives me "command not found: composer".
I am very new to this. Am I making noob mistakes? Thank you very much for any pointers.

Related

I can't install composer globally in my web host, how can I use the "composer" command?

I hosted my website on french host Gandi, with their simple hosting plan.
I cannot move anything in the /usr/local/bin directory since it is read-only, so I used to manage with composer.phar, which works well.
I recently used a library which requires the composer executable to be present (This library executes something like "composer require xxx" and there is no fallback to composer.phar).
Is there a way to make it work ?
What I have done so far :
Tried to install composer globally (Failed because of the read-only filesystem)
Tried to install composer globally for the current user (Failed because there was no ~/.local/bin directory, and also failed after creating the directory and restarting the instance)
Tried to move the file to any directory of the $PATH variable (Failed because all of these directories are read-only)
Tried to rename composer.phar to composer, and allowed it to be executable chmod +x composer (Failed because it only works with the command ./composer and not with composer)
Ok, I finally succeeded with the following steps:
renamed composer.phar to composer mv composer.phar composer
made this new file executable chmod +x composer
added the current path (corresponding to my website's root) to the system's $PATH variable export PATH=$PATH:$PWD
I'm not fully satisfied with this since this relies on a specific website's root folder, but hey, it works! I'll try to update this answer if I find a way to create a folder available for every website I'll host there.

How to install vendor folder

I cloned project from https://github.com/victorfleite/blog-php-oop archived .
But how to create vendor folder and install any dependency?
Just use command composer install in command line (from same directory where composer.json is located). If you don't have an installed composer yet, first install it.
https://getcomposer.org/download/
Go to your Project root directory where composer.json is located
with opening a command prompt and using this commands :
make sure Your lock file contain a compatible set of packages with
running composer update command
after that you can make sure all the packages are installed with composer install command
you can find more packages with composer fund command
Go to cmd or terminal
Make sure you are in the right path (project folder directory)
use cd project_name to go inside the folder and cd .. to go back up out of the folder
In the terminal use the command composer install (if you need to install composer itself, see their official website)
Your vendor folder is installed
In the terminal type php artisan migrate and run the project

Why doesn't composer install Laravel globally in /usr/bin?

The Laravel installation guide says:
First, download the Laravel installer using Composer:
composer global require "laravel/installer"
Make sure to place the $HOME/.composer/vendor/bin directory (or the
equivalent directory for your OS) in your $PATH so the laravel
executable can be located by your system.
Why can't laravel just be installed to /usr/bin like a normal executable?
Is making a symlink instead of adding the path a good idea?
ln -s $HOME/.config/composer/vendor/bin /usr/bin/laravel
Why doesn't composer do this by default?
on MacOS 10.12 I have solve the issue.
after execute the command on terminal
composer global require "laravel/installer"
composer will install laravel/installer on your computer.
Find the location where is installed Laravel installer. Then add a line on ~/.bash_profile
export PATH=<laravel installer location>:$PATH
On my cace <laravel installer location> was /Users/shahriar/.composer/vendor/laravel/installer/bin/
So I have added the line on .bash_profile
export PATH=/Users/shahriar/.composer/vendor/laravel/installer/bin:$PATH
then type a command on terminal source ~/.bash_profile it will update your .bash_profile
and its worked. and now my Laravel installer installed globally.

Composer not working on command prompt Windows 7

I installed Composer via Composer windows installer and it installed to the path C:\ProgramData\ComposerSetup. The composer.phar file is in the bin folder in the directory (C:\ProgramData\ComposerSetup\bin). I have added the Composer PATH to the environment variable. But even after that, I can't make Composer get start by typing composer in the command prompt. Can you help me? I have tried installing it manually in different directories and so far no success.
I have downloaded Console2 and inside it, Composer works just fine. But the windows command prompt doesn't do anything unless I'm in the installation directory.

Installing Laravel via the Laravel installer

I have composer installed, but checking the Laravel docs, I'm struggling with:
"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."
I'm not sure what to do here, could someone explain it to me?
Go to terminal and paste the next line:
nano ~/.bash_profile
After that paste the next line in nano:
export PATH="$PATH:$HOME/.composer/vendor/bin"
Done. Restart your terminal and enjoy laravel.
The PATH environment variable tells your system where to look when you run a command. By default ~/.composer/vendor/bin will not be in your PATH. Therefore, if you just attempt to run the command laravel after installing it via composer, your terminal will give you an error saying the command is not found. But if you use the entire path to the command (~/.composer/vendor/bin/laravel), it will execute successfully.
When you run the command composer global require "laravel/installer=~1.1", composer puts the laravel installer into the directory ~/.composer/vendor/bin (in *nix, ~ represents your home directory). Adding ~/.composer/vendor/bin to your PATH allows you to just execute the command laravel instead of having to use the full path of ~/.composer/vendor/bin/laravel.
Helpful Stuff:
How to set/change your PATH environment variable in OSX
Installing composer packages globally

Resources