Composer doesn't work after global installation - macos

I'm a newbie. I've searched all over the place to find a solution for my issue but unfortunately couldn't find it. So hopefully somebody on here can tell me what I'm doing wrong or what I missed.
I installed composer on my local machine (MacBook Pro).
I've made it global and when I go to /usr/local/bin I can see the file composer.phar
On my desktop I've created a folder teamleader-api. I want to make a WordPress plugin that uses service API's.
As library I want to use https://github.com/sumocoders/Teamleader
On the instructions that I found they say that I need to go to my plugin directory.
$ cd /Users/myname/Desktop/teamleader-api
The library says that to install I need to use composer require sumocoders/teamleader
$ composer require sumocoders/teamleader
But when I give in this command in my terminal I get
-bash: composer: command not found
What am I doing wrong?

I found my solution....just needed to watch the next youtube video :-)
I explain what I did so people who might have the same issue in the future know what to do.
In terminal I went to my teamleader-api folder who is on my desktop.
From https://getcomposer.org/ I copied the code
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Instead of composer require sumocoders/teamleader I need to use php composer.phar require sumocoders/teamleader
And now it works....easy as pie :-)

Related

Laravel: [ErrorException] "continue" targeting switch is equivalent to "break". during "composer install"

When I run ...
composer install
... on a server with PHP and nginx installed.
I get the following exception:
[ErrorException]
"continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"?
How can I fix this?
This is a new warning introduced in PHP 7.3.
It means you are not allowed to have a continue statement inside of a switch, you should use break instead.
To fix this you most likely just have to update composer, this can be done simply by running composer self-update.
You can also just run php without warnings, this can be done by setting the ini config values as a start parameter.
php -d error_reporting=0 composer.phar
Check your current PHP version if it's greater than 7.2, then execute follow below simple steps
1. Disable the latest php version
sudo a2dismod php7.3
2. Restart the nginx service
sudo service nginx restart
3. If you are using Apache2 run as below
sudo service apache2 restart
4. Set alternatives
sudo update-alternatives --set php /usr/bin/php7.2
5. Check the PHP version
php -v
6. Now, Install Composer as below
composer install
Old composer uses continue statement in their code within the switch which is outdated and cannot be used anymore with latest version of php.
you need to update your composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php --install-dir=bin
for more details visit composer download
It was because of an outdated composer. After searching a lot finally the following works for me:
Uninstall the old composer.
Install a new updated composer.
You can download or install composer from this link: https://getcomposer.org/download/
For me,
just go to this file
sudo nano /usr/share/php/Composer/DependencyResolver/RuleSetGenerator.php
As a quick and dirty alternative, you can fix the error in that file. Just replace "continue" with "break"

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

Conflicting versions of composer installed package causing issues

I'm running mac OS X and trying to use codeception through the terminal for a laravel project I'm working on, but I'm having some issues related to the version. The codecept command through terminal is referencing an older version and I cannot figure out how to change the reference to the newer one.
When I type in codecept -v in terminal it shows 2.1.6. However, when I type in ./vendor/bin/codecept it shows 2.4.1. So, every time I need to use codeception I now have to type ./vendor/bin/codecept some_command, which is quite aggravating.
How can I change it so that I don't have to type out ./vendor/bin/codecept every single time I need to run a codeception command and can instead just use codecept, which the older version is currently referencing? I tried using export PATH=$PATH:./vendor/bin/codecept but that didn't do anything.
Try run:
export PATH=./vendor/bin:$PATH
It will prefer binaries from local composer installation.
You may want to add it to your ~/.profile or ~/.bashrc file, then you will not need to run this command in every session.
If your global Codeception installation is installed by Composer, you should be able to update it by:
composer global require codeception/codeception
But I would not recommend to use global installation - required Codeception version may vary for different projects, so using version installed locally should give you less trouble and more predictable results.
what worked for me is:
Install Composer
Navigate to your desired location and copy this set of commands in your terminal:
php -r "copy('https://getcomposer.org/installer',
'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') ===
'669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410')
{ echo 'Installer verified'; } else { echo 'Installer corrupt';
unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
Install latest Codeception via Composer:
In terminal type:
composer require codeception/codeception --dev

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.

what is phpmd and how to use it?

I have Ubuntu 14.04 + Sublime text 3 and installed phpcs packages
additionalty I have installed phpcs and php-cs-fixer on my system
From this blog
I have found that phpmd (PHP Mess Detector) is also a required library, so installed phpmd as per given instructions on official php md page using alternative method From the github repository everything was finished.
:~/phpmd$ curl -s http://getcomposer.org/installer | php
#!/usr/bin/env php
All settings correct for using Composer
Downloading...
Composer successfully installed to: /home/keshav/phpmd/composer.phar
Use it: php composer.phar
but now when I write on terminal
phpmd /opt/lampp/htdocs/myproject, myfile.php
phpmd: command not found
There is phpmd folder on Home directory and everything without any error.
I have local project on core PHP create composer.json in project folder as per suggested on github .
Please tell me what means by
Then install Composer in your project (or download the composer.phar directly):
I think the problem is you've installed phpmd in a local directory, but you're trying to use it as if it was installed globally.
Installation instruction on the referenced sites can't really be made any clearer. Since you've already installed phpcs and php-cs-fixer, and those work for you, just follow similar instructions for phpmd. These are all PHP projects and are installed in a similar way.
Anyway, to use phpmd as a global command you have several options.
Github
Clone the github repository just like you did and add the phpmd bin directory to your PATH variable.
Global composer installation
Use the composer global command to install phpmd globally. You will also need to make sure that composer's bin directory is in the PATH. By default it's ~/.composer/vendor/bin.
composer global require phpmd/phpmd
This command will install phpmd globally, and as soon as ~/.composer/vendor/bin is in your PATH you'll be able to call it by simply invoking phpmd.
It's very well explained in composer's documentation: https://getcomposer.org/doc/03-cli.md#global
Download the phar archive
This is the simplest thing you can do. Simply go the phpmd releases, choose the latest and download the phar archive.
Put the phar file to whatever place you'd like. Just remember that it needs to be in your PATH. You can also rename it, to skip the .phar extension.
For example:
wget http://static.phpmd.org/php/2.1.3/phpmd.phar
sudo mv phpmd.phar /usr/bin/phpmd
sudo chmod +x /usr/bin/phpmd
Docker container
First, fetch the docker image with static analysis tools for PHP:
docker pull jakzal/phpqa
One of the tools provided by the image is phpmd. The command below will run phpmd in a docker container and mount the current working directory as a /project.
docker run -it --rm -v $(pwd):/project -w /project jakzal/phpqa \
phpmd src text cleancode,codesize,controversial,design,naming,unusedcode
When you use the composer-based install, it gets installed into the ./bin directory within the ./vendors directory. So for me, relative to my project's root directory, it was here:
./vendor/bin/phpmd
And I was able to run it from my project's root by running ./vendor/bin/phpmd . text codesize. (I'm not getting any useful output yet, but another issue)

Resources