How to run composer on MAMP 's php version? - php

I can't run composer install because my php's version on my OS is not enough updated (5.5.36). So i tried to install composer globally with my MAMP's php(5.6.10)
1) I create alias for my MAMP's php
nano ~/.bash_profile
alias phpmamp='/Applications/MAMP/bin/php/php5.6.10/bin/php'
2) Run this line to install composer
curl -sS https://getcomposer.org/installer | phpmamp
3) Run this line to move composer
sudo mv composer.phar /usr/local/bin/composer
Composer is installed (run composer on terminal works)
This is a the tutorial.
But when i want to run composer install, composer uses my OS php.
Any idea ?

Those lines worked for me. I override the OS PHP path to my MAMP PHP path.
PHP_VERSION=`ls /Applications/MAMP/bin/php/ | sort -n | tail -1`
$ export PATH=/Applications/MAMP/bin/php/${PHP_VERSION}/bin:$PATH
$ source ~/.bash_profile
You can check the version by running :
$ which php
The complete solution
Thanks to #Andrew Patton

This is an old question, but it came up in web search for a similar issue I was having, and the latest version of MAMP Pro (mine is 6.6.2) has a GUI solution:
In Languages > PHP, under 'Default version', you should see a checkbox for "Also activate shortcut for Composer".
What this did for me is add an alias of composer=/Applications/MAMP/bin/php/composer (in my zshell ~/.profile file on macOS Monterey). Maybe yours works similarly.
Of course, when switching PHP versions, it wouldn't also switch composer versions (which is necessary when switching between PHP 5 and 7.2.5+), so I have to use the OS install for one version and MAMP's for another. A little tricky, but if you don't have this problem, then the alias will be fine.

Related

zsh: command not found: php. PHP is installed and working with MAMP

I am trying to use composer to install a google client library, but cannot install composer or use php on the command line.
I am using php 8.0.8 with MAMP and it is working fine, so I know it is installed.
If I type php in the terminal, I receive the command not found message. Thinking it could be an environment variable, I have tried navigating to the php folder /Applications/MAMP/bin/php/php8.0.8/lib/php and tried the php command again, but still get the same error
I am using a Mac running Monterey
Change default Mac OS X PHP to MAMP's PHP Installation and Install Composer Package Management
Instructions to Change PHP Installation
First, Lets find out what version of PHP we're running (To find out if it's the default version).
To do that, Within the terminal, Fire this command:
which php
This should output the path to the default PHP install which comes preinstalled by Mac OS X, by default it has to be (Assuming you've not changed it before):
/usr/bin/php
Now, We just need to swap this over to the PHP that is installed with MAMP, which is located at /Applications/MAMP/bin/php/php5.4.10/bin (MAMP 2.1.3)
To do this, We need to edit the .bash_profile and add the MAMP version of PHP to the PATH variable.
Follow these simple steps:
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/php5.4.10/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).
Install Composer Package Management
Now you can fire the command to install the composer globally (So you can access it from anywhere):
$ curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
You can verify your installation worked by typing the following command within the Terminal:
composer
It'll show you the current version and a list of commands you can use if the installation was successful.
Original source

Composer PHP version issue [duplicate]

I'm trying to install my composer packages, but it gives me this:
This package requires php >=7.0.0 but your PHP version (5.5.9)
But php -v gives me this: PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
I am running an Ubuntu 16.04.3 LTS machine, I found some soultions for Mac and Windows, but nobody seems to have the issue on Linux?
try this:
composer install --ignore-platform-reqs
or this in composer.json
"config": {
"preferred-install": "dist",
"platform": {
"php": "7.0.0"
}
}
in the second solution basically you're faking a platform, and run composer.phar update after this
If you're using Debian based systems, you can ask it to globally use a specific version with the following command (depending on how and where your php versions are installed to):
sudo update-alternatives --set php /usr/bin/php7.2
update-alternatives creates, removes, maintains and displays
informations about the symbolic links comprising the Debian
alternatives system.
Try this it worked for me :
alias php='/usr/local/php7/bin/php'
php composer.phar install
composerreferences the PHP executable here as follow:
#!/usr/bin/env php
When I do which php I get /c/Program Files/php-7.1/php under GIT-Bash (Windows 10).
Under Linux (at home I have Debian), php may be a symbolic link to an actual PHP binary.
So do the following:
Double-check the said php with ls -l `which php`
Make sure that you only have one PHP version installed, this may cause mixing incompatible versions which may be the root cause of your problem
That should help you, finding the root cause.
Just sharing here because I had this same issue and found this thread first while searching.
For me I had a Windows server with PHP 5.6.? on it as well as PHP 7.2.? on it. I had configured IIS to use 7.2 but 5.6 was still in the environment variables under path. Open System Properties>Advanced tab> "Environment Variables...". Edit "path", and remove the reference to "C:/program files (x86)/PHP/v5.6" from path and save.
Restart your terminal and you should be set. Hope that helps someone.
I recently came across the same problem. php --version returned 7.4.30, but Composer said it was using PHP 8.0.18.
It turns out Composer is using its own PHP version. The composer script contains a hardcoded path to PHP 8. (To me, this is a composer bug, as Composer should respect the value of the config.platform.php property of the composer.json file.)
An option may be to alias composer:
alias composer='/usr/local/bin/php /usr/bin/composer.phar
Another option may be to rewrite composer:
cat /usr/bin/composer \
| sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
> /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
This is how I found out. First, I wanted to find the location of composer. By using whereis composer, one can find the path of the composer command. For me, it returned
composer: /usr/bin/composer
I then wanted to see the contents of /usr/bin/composer, so I could find out what the composer command was doing under the hood. By using cat /usr/bin/composer, the contents of the composer script are printed. For me, it returned
#!/bin/sh
/usr/bin/php8 /usr/bin/composer.phar "$#"
There it is. The composer command uses hardcoded /usr/bin/php8 to execute the composer.phar file.
Well, this worked for me
$ alias composer="php /usr/bin/composer.phar"
$ composer install
Use the exact php binary in the alias, for example
$ alias composer="php8.1 /usr/bin/composer.phar"
None of above didnt worked for centos 7.
After this command composer php version fixed
The correct answer below
SSH Command:
scl enable ea-php74 'composer diagnose'

atom-beautify & php-cs-fixer

I am a new programmer and I need your help.
I'm pretty much new to Atom editor, but setup some nice packages like Atom Beautify. After using it in a html / php file I'm getting the error "Could not find 'php-cs-fixer' . The program may not be installed. The strange thing is, I did install the package php-cs-fixer but nothing happens.
My system is Windows.
Anyone got an idea how I can fix this?
You must have installed "php" usually when installing the Wamp or Xampp servers are installed by default.
    
Download the file "php-cs-fixer.phar" https://github.com/FriendsOfPHP/PHP-CS-Fixer
In the CMD execute this command: php where.exe
You get a path, that path copy in: Open Atom Packages / Atom Beautify / Settings / Executables / PHP
In the same folder where the php.exe is located copy the file "php-cs-fixer.phar"
Redo the previous process with the CMD and the Atom in PHP-CS-Fixer "
Just run this command in terminal, then it will work perfectly:
$ composer global require friendsofphp/php-cs-fixer
Everything will be fixed!
I am not sure about in Windows, but on Mac and Linux, I do the following. You may be able to do this with Git Bash in Windows.
Install php-cs-fixer with Homebrew (via PHP-CS-Fixer Instructions)
brew install php-cs-fixer
Confirm php-cs-fixer was installed
which php-cs-fixer
its because you need to install php cs fixer, the atom extension is trying to use it but its not currently installed on your system, install it here:
https://github.com/FriendsOfPHP/PHP-CS-Fixer
I suggest you install manually the php-cs-fixer using the following steps:
You can use yum, apt, and other methods of installing a software or a .exe for windows
Get the path to the installed binary, for example for me i checked using whereis php-cs-fixer and I got /usr/bin/php-cs-fixer
Go to Packages > Atom Beautify > Settings > Executables > PHP-CS-FIXER then in the Binary/Script Path give the path of the php-cs-fixer above (/usr/bin/php-cs-fixer)
Enjoy beautify.
The issue for me was originally installing with composer. Composer does not put a .phar file into the /bin folder.
Download the .phar file (https://github.com/FriendsOfPHP/PHP-CS-Fixer#locally) and place it somewhere explicitly, then put that location in settings->executables->PHP-CS-Fixer path
The manual way did work for me and this how I went about it;
I download php-cs-fixer manually.
$ wget https://cs.symfony.com/download/php-cs-fixer-v3.phar -O php-cs-fixer
or with curl
$ curl -L https://cs.symfony.com/download/php-cs-fixer-v3.phar -o php-cs-fixer
Then I fixed the rights and moved it to the right directory.
$ sudo chmod a+x php-cs-fixer
$ sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
Finally, I ran php-cs-fixer and it worked.
full link
make an empty folder somewhere. example: C:\Programs\php-cs-fixer
run composer require friendsofphp/php-cs-fixer
open atom and go to
settings -> packages -> atom beautify -> settings -> executables ->
php cs fixer input the path there:
C:\Programs\php-cs-fixer\vendor\bin\php-cs-fixer.bat
optionally:
add C:\Programs\php-cs-fixer\vendor\bin to windows env path so you
can use it from cli

Composer uses wrong php version, but php -v shows the correct one (Ubuntu)

I'm trying to install my composer packages, but it gives me this:
This package requires php >=7.0.0 but your PHP version (5.5.9)
But php -v gives me this: PHP 7.0.22-0ubuntu0.16.04.1 (cli) ( NTS )
I am running an Ubuntu 16.04.3 LTS machine, I found some soultions for Mac and Windows, but nobody seems to have the issue on Linux?
try this:
composer install --ignore-platform-reqs
or this in composer.json
"config": {
"preferred-install": "dist",
"platform": {
"php": "7.0.0"
}
}
in the second solution basically you're faking a platform, and run composer.phar update after this
If you're using Debian based systems, you can ask it to globally use a specific version with the following command (depending on how and where your php versions are installed to):
sudo update-alternatives --set php /usr/bin/php7.2
update-alternatives creates, removes, maintains and displays
informations about the symbolic links comprising the Debian
alternatives system.
Try this it worked for me :
alias php='/usr/local/php7/bin/php'
php composer.phar install
composerreferences the PHP executable here as follow:
#!/usr/bin/env php
When I do which php I get /c/Program Files/php-7.1/php under GIT-Bash (Windows 10).
Under Linux (at home I have Debian), php may be a symbolic link to an actual PHP binary.
So do the following:
Double-check the said php with ls -l `which php`
Make sure that you only have one PHP version installed, this may cause mixing incompatible versions which may be the root cause of your problem
That should help you, finding the root cause.
Just sharing here because I had this same issue and found this thread first while searching.
For me I had a Windows server with PHP 5.6.? on it as well as PHP 7.2.? on it. I had configured IIS to use 7.2 but 5.6 was still in the environment variables under path. Open System Properties>Advanced tab> "Environment Variables...". Edit "path", and remove the reference to "C:/program files (x86)/PHP/v5.6" from path and save.
Restart your terminal and you should be set. Hope that helps someone.
I recently came across the same problem. php --version returned 7.4.30, but Composer said it was using PHP 8.0.18.
It turns out Composer is using its own PHP version. The composer script contains a hardcoded path to PHP 8. (To me, this is a composer bug, as Composer should respect the value of the config.platform.php property of the composer.json file.)
An option may be to alias composer:
alias composer='/usr/local/bin/php /usr/bin/composer.phar
Another option may be to rewrite composer:
cat /usr/bin/composer \
| sed 's~/usr/bin/php8~/usr/local/bin/php~g' \
> /usr/bin/composer.tmp
mv /usr/bin/composer.tmp /usr/bin/composer
This is how I found out. First, I wanted to find the location of composer. By using whereis composer, one can find the path of the composer command. For me, it returned
composer: /usr/bin/composer
I then wanted to see the contents of /usr/bin/composer, so I could find out what the composer command was doing under the hood. By using cat /usr/bin/composer, the contents of the composer script are printed. For me, it returned
#!/bin/sh
/usr/bin/php8 /usr/bin/composer.phar "$#"
There it is. The composer command uses hardcoded /usr/bin/php8 to execute the composer.phar file.
Well, this worked for me
$ alias composer="php /usr/bin/composer.phar"
$ composer install
Use the exact php binary in the alias, for example
$ alias composer="php8.1 /usr/bin/composer.phar"
None of above didnt worked for centos 7.
After this command composer php version fixed
The correct answer below
SSH Command:
scl enable ea-php74 'composer diagnose'

Running Composer returns: "Could not open input file: composer.phar"

I am new to symfony2 and reading symblog. In third chapter while trying with data-fixtures I tried the command:
php composer.phar update
but I got the error:
Could not open input file: composer.phar
So I googled a little and tried
php composer.phar install
but still getting the same error. So please guide how to deal with this composer to install new extentions or bundles like data-fixtures in symfony2 using wamp.
If you followed instructions like these:
https://getcomposer.org/doc/00-intro.md
Which tell you to do the following:
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer
Then it's likely that you, like me, ran those commands and didn't read the next part of the page telling you to stop referring to composer.phar by its full name and abbreviate it as an executable (that you just renamed with the mv command). So this:
$ php composer.phar update friendsofsymfony/elastica-bundle
Becomes this:
$ composer update friendsofsymfony/elastica-bundle
I had the same problem on Windows and used a different solution. I used the Composer_Setup.exe installation file supplied by the composer website and it does a global install.
After installing, make sure your PATH variable points to the directory where composer.phar is stored. This is usually C:\ProgramData\ComposerSetup\bin (ProgramData might be a hidden directory). It goes without saying, but also be sure that the PHP executable is also in your PATH variable.
You can then simply call
composer install
instead of
php composer.phar install
Background
It is helpful to know that there are two ways to install (and use) Composer: locally as a file in your project directory, or globally as a system-wide executable.
Installing Composer locally simply means that you are downloading a file (composer.phar - which is a PHP Archive) into your project directory. You will have to download it for every project that requires Composer.
Like a regular PHP file that you want to execute on the command line, you will have to run it with PHP:
php composer.phar update
Which basically tells the php executable to run the file composer.phar with update as argument.
However, if you install it globally, you can make composer itself executable, so you can call it without php (and don't have to download it for every project). In other words, you can use composer like this:
composer update
Since you are executing php composer.phar update, and you are getting the error Could not open input file: composer.phar, you probably don't have composer.phar in your current directory.
Solution
If you have Composer installed globally, simply run composer update instead of php composer.phar update.
If you don't have Composer installed yet, download the PHAR using the following command:
curl -sS https://getcomposer.org/installer | php
This will download the installer and run it using php. The installer will download the actual Composer PHAR to your current working directory, and make it executable.
To install Composer globally (I recommend this), copy the file to a location in your PATH. The exact location differs per operating system and setup, see https://getcomposer.org/doc/00-intro.md#globally for more information.
Personally, I prefer to install Composer in my home directory so I don't need sudo to install or update the composer executable (which can be a security risk). As I'm on Linux, I use the following command:
mv composer.phar ~/.local/bin/composer
If anyone else came this low on the page and still didn't find a working answer (like I did), use this:
$ curl -sS https://getcomposer.org/installer | php
$ mv composer.phar /usr/local/bin/composer.phar
$ alias composer='/usr/local/bin/composer.phar'
$ composer --version
et voila! A working composer :-)
To solve this issue the first thing you need to do is to get the last version of composer :
curl -sS https://getcomposer.org/installer | php
I recommend you to move the composer.phar file to a global “bin” directoy, in my case (OS X) the path is:
mv composer.phar /usr/local/bin/composer.phar
than you need to create an alias file for an easy access
alias composer='/usr/local/bin/composer.phar'
If everything is ok, now it is time to verify our Composer version:
composer --version
Let's make composer great again.
I found this worked as I did not have curl installed. On Windows 8 with XAMPP installed. It will add it to your local build I use .gitignore to avoid the repo
php -r "readfile('https://getcomposer.org/installer');" | php
I got it from here: https://getcomposer.org/download/
This worked for me:
composer install
Without
php composer install
Run the following in command line:
curl -sS https://getcomposer.org/installer | php
Yesterday I was trying to install Yii2 framework on Windows 10 and I have same problem(Could not open input file: composer.phar) running this command:
php composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9
Issue is composer.phr file is not in current directory,you need to give full path composer.phr like
php C:\ProgramData\Composer\bin\composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9
Or you can create yii2 project using this command:
composer create-project yiisoft/yii2-app-advanced advanced 2.0.9
Or
composer.phar create-project yiisoft/yii2-app-advanced advanced 2.0.9
I had the same issue. It is solved when I made composer globally available. Now I am able to tun the commands from any where in the folder.
composer update
composer require "samplelibraryyouwant"
Use this :
php -r "readfile('https://getcomposer.org/installer');" | php
Hi friends, follow the steps to fix this issue in MAC OS
Step 1: first run the command in Terminal with your project directory
$ curl -sS https://getcomposer.org/installer | php
Step 2: Move the composer.phar in your project directory
$ mv composer.phar /Applications/MAMP/htdocs/bashrushAPI/composer.phar
Step 3: Setup alias the composer
$ alias composer='/Applications/MAMP/htdocs/bashrushAPI/composer.phar'
Step 4: Check the composer version now
$ composer --version
Composer version 1.7.2 2018-08-16 16:57:12
Step 5: Confirm the project folders and file placed on bellow
$ ls
CONTRIBUTING.md docker-compose.yml templates
README.md logs tests
composer.json phpunit.xml vendor
composer.lock public
composer.phar src
Step 6: Now update composer
$ composer.phar update
Loading composer repositories with package information
Updating dependencies (including require-dev)
Nothing to install or update
Generating autoload files
Step 7: Run your sample project
$ php composer.phar start
php -S localhost:8080 -t public
[Thu Sep 27 03:16:11 2018] ::1:51177 [200]: /
[Thu Sep 27 03:16:11 2018] ::1:51178 [404]: /favicon.ico - No such file or directory
Easy answer, navigate to the directory where you already have the composer.json file that you want to run (ideally your project folder) then download composer into the same folder, then instantly run the install command like so:
php composer.phar install
This will automatically find the composer.json and run your required scripts. Good luck. This stuff is a breeze for terminal wizards and totally bizarre to the rest of us
I am using windows 8.0. In my case to install or update i just use composer install or something else instead of php composer.phar. This worked for me
like
composer require google/apiclient:1.*
To googlers who installed composer via HomeBrew:
make a symbolic link for /usr/local/bin/composer
ln -s /usr/local/bin/composer /usr/local/bin/composer.phar
I got this error "Could not open input file: composer.phar" while installing Yii2 using below mentioned command.
php composer.phar create-project yiisoft/yii2-app-basic basic
Solutions which worked for me was, I changed the command to
composer create-project yiisoft/yii2-app-basic basic
I hope it help!
your composer.phar should be placed in above way.
For windows, I made composer.cmd and used the below text:
php c:\programs\php\composer.phar %*
where composer.phar is installed and c:\programs\php\ is added to my path.
Not sure why this isn't done automatically.
For Windows10 Pro, Following steps fix the issue. select properties check the Unblock program option. run the installer, run the command CMD with Admin rights. At command promp run composer --version to make sure it is globally installed. you should be able to now run composer require drush/drush This is for drush dependency using composer.
Command like this :
composer.phar require intervention/image
error: composer.phar: command not found
I solved the problem by following this process
i set the composer globally and renamed composer.phar to composer then run this command composer require intervention/image . and now it's working fine
Just open cmd as Administrator and go into your project folder and check it is working or not using composer command.
The above error is because of the composer is not accessible globally.
So you need to run "cmd" as Administrator.
This is working fine for me.
If you are using Ubuntu/Linux and you are trying to run
php composer.phar require intervention/image on your command line.
Use sudo composer require intervention/image instead. This will give you want you are looking for.
I had an issue getting a package.json's script to run composer dumpautoload.
I had the file /usr/local/bin/composer.phar, and also the file ~/.bash_profile (on OSX) contained:
alias composer="php /usr/local/bin/composer.phar"
This allowed composer to work from the command line, but it didn't allow scripts to execute composer.
The fix was this:
$ cd /usr/local/bin
$ mv composer.phar composer
$ sudo chmod +x composer // +x allows the file to be executable, such as by CLI scripts
But that yielded this error Could not open input file: /usr/local/bin/composer.phar
The fix was to update ~/.bash_profile (sudo nano ~/.bash_profile), and change the composer alias to:
alias composer="php /usr/local/bin/composer"
# ie: `.phar` extension removed
Now everything is behaving as expected.
Your composer.phar must be in Source files. I had same problem and I just cut my composer.phar into mine framework-standard-edition folder, where is my whole strong textproject.
if the composer is already install all you need is to know where the composer.phar file is (its directory) after that you move to your symfony project where you have the composer.json and from that directory you execute your composer.phar file. In windows here is what you have to do.
symfony project directory_where_composer.json_is>php the_directory_where_composer.phar_is/composer update
That's all
use two steps .
curl -sS https://getcomposer.org/installer | php
sudo php composer.phar update
You can do
curl -sS https://getcomposer.org/installer | php
The -sS flag meaning don't show progress, do show errors
and then
php composer.phar install
from:
How do I get cURL to not show the progress bar?
https://packagist.org/
I've reach to this problem when trying to install composer on a Window 7 machine from http://getcomposer.org/download page. As there was an existing compose version (provided by acquia Dev Desktop tool) the installation fails and the only chance was to fix this issue manually. (or to remove Dev Desktop tool composer).
Anyway the error message is quite straightforward (Could not open input file: composer.phar), we should then tell the system where the file is located.
Edit composer.bat file and should look like:
#SET PATH=C:\Program Files (x86)\DevDesktop\php5_4;%PATH%
php.exe composer.phar %*
See that composer.phar doesn´t have a file path. When standing in a different folder than the one where composer.phar is located the system won´t be able to find it. So, just complete the composer.phar file path:
#SET PATH=C:\Program Files (x86)\DevDesktop\php5_4;;%PATH%
SET composerScript=composer.phar
php.exe "%~dp0%composerScript%" %*
Reopen your window console and that should do the trick.
EDIT: this has an issue because it always uses %~dp0%composerScript%
folder as composer execution. Then all configurations are done in that
folder (besides standing on your current project folder) and not in your project folder.
So far I haven't found a was to make a manual composer installation to
work globally on Windows. Perhaps you should go ahead with composer for windows installation mentioned above.
Do not access the composer by
composer composer.pher install
use
composer install
You can just try this command if you're already installed the Composer :
composer update
or if you want add some bundle to your composer try this :
composer require "/../"

Categories