Can't move composer - php

When I install composer on my mac with:
curl -sS https://getcomposer.org/installer | php
And then try to move it like this:
sudo mv php composer.phar /usr/local/bin/composer
it's telling me:
rename composer.phar to /usr/local/bin/composer: No such file or directory
When I look to my path:
echo $PATH
It's telling me:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Try with below command to install composer globally.
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
Note: On some versions of OSX the /usr directory does not exist by default. If you receive the error "/usr/local/bin/composer: No such file or directory" then you must create the directory manually before proceeding: sudo mkdir -p /usr/local/bin.

If you are running macOS Sierra Version, there might not be a /usr/local/bin folder so you will have to create it. Follow these steps in the terminal:
Step 1: cd ~
Step 2: sudo mkdir -p /usr/local/bin
Step 3: curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer

I had the same error when installing composer to make it global
create the directory is the error no such file or directory by using
sudo mkdir -p /usr/local/bin
now install the composer direct to the bin folder
sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
run composer on the terminal and it should be working

Related

Install PHP composer from a dockerfile

I tried to install composer in a dockerfile using this code
FROM php:8.0-fpm
WORKDIR /app/php
RUN set update && set add curl && \
curl -sS https://getcomposer.org/installer --version=2.0.2 | PHP
but when I exec the container I find that the composer isn't installed
root#70c:/app/php# composer -v
bash: composer: command not found
What's wrong?, and how can I resolve this?
This will download the composer.phar file in the directory you are, in your case /app/php
If you want to have global access to composer you should move it to /usr/local/bin directory and make it executable.
chmod +x composer.phar
sudo mv composer.phar /usr/local/bin/composer

How to install PHP composer inside a docker container

I try to work out a way to create a dev environment using docker and laravel.
I have the following dockerfile:
FROM php:7.1.3-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
&& chmod -R o+rw laravel-master/bootstrap laravel-master/storage
Laravel requires composer to call composer dump-autoload when working with database migration. Therefore, I need composer inside the docker container.
I tried:
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/bin --filename=composer
But when I call
docker-compose up
docker-compose exec app composer dump-autoload
It throws the following error:
rpc error: code = 13 desc = invalid header field value "oci runtime error: exec failed: container_linux.go:247: starting container process caused \"exec: \\\"composer\\\": executable file not found in $PATH\"\n"
I would be more than happy for advice how I can add composer to the PATH within my dockerfile or what else I can do to surpass this error.
Thanks for your support.
Also: this is the gitub repository if you need to see the docker-compose.yml file or anything else.
In Dockerfile :
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
I can install composer adding this line on my test dockerfile:
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Here is the dockerfile:
FROM php:7.1.3-fpm
RUN apt-get update && apt-get install -y libmcrypt-dev \
mysql-client libmagickwand-dev --no-install-recommends \
&& pecl install imagick \
&& docker-php-ext-enable imagick \
&& docker-php-ext-install mcrypt pdo_mysql
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
It works for me, to test if the composer are installed i access to my container bash and execute:
composer --version
Composer version 1.6.5 2018-05-04 11:44:59
This is how i do it with Laravel 8.4 in 2021 to deploy it to CloudRun in Google Cloud:
Dockerfile
#Get Composer
FROM composer:2.0 as vendor
WORKDIR /app
COPY database/ database/
COPY composer.json composer.json
COPY composer.lock composer.lock
RUN composer install \
--no-interaction \
--no-plugins \
--no-scripts \
--no-dev \
--prefer-dist
COPY . .
RUN composer dump-autoload
// some more custom steps like
FROM node:14.9 as frontend
...
FROM php:7.4-fpm
...
// Copy Composer dependencies
# Copy Composer dependencies
COPY --from=vendor app/vendor/ ./vendor/
COPY . .
// Some more custom steps
...
End of my Dockerfile to launch app with cleared optimized cache
# Run Laravel commands
RUN php artisan optimize:clear
CMD php artisan serve --host=0.0.0.0 --port=8080
EXPOSE 8080
Create an executable of your composer file using
RUN curl -sS https://getcomposer.org/installer | php -- \
--install-dir=/usr/bin --filename=composer && chmod +x /usr/bin/composer
use composer in dockerfile using curl
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Dockerfile
FROM 8.1.4-fpm
RUN apt-get update && apt-get install -y \
git \
curl \
zip \
unzip
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
WORKDIR /var/www
We have basicly the same command running with the difference,
--install-dir=/usr/local/bin
Alternatively, you should add the composer bin files path to the $PATH variable.
export PATH=$PATH":/usr/bin"
I'd just like to suggest another way.
Dockerfile:
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
FROM php:7.3-fpm-alpine
RUN docker-php-ext-install pdo pdo_mysql
RUN docker-php-ext-install mysqli && docker-php-ext-enable mysqli
RUN php -r "readfile('http://getcomposer.org/installer');" | php -- --install-dir=/usr/bin/ --filename=composer
RUN apk update
RUN apk upgrade
RUN apk add bash
RUN alias composer='php /usr/bin/composer'
My problem solved. I just stopped firewalld service on system

Composer: Command Not Found

From within the directory holding my composer.phar file, I can't execute any composer commands.
I can see Composer is running when I execute
php composer.phar
But any direct composer statements fail.
Not sure if it matters but Composer was included within a cloned repository.
I just want to install a single Oauth library, then likely not touch Composer again for several months, so I don't need to run it globally. I'm just confused why I can't run Composer from within this directory.
This problem arises when you have composer installed locally.
To make it globally executable,run the below command in terminal
sudo mv composer.phar /usr/local/bin/composer
I am using CentOS and had same problem.
I changed /usr/local/bin/composer to /usr/bin/composer and it worked.
Run below command :
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/bin/composer
Verify Composer is installed or not
composer --version
Your composer.phar command lacks the flag for executable, or it is not inside the path.
The first problem can be fixed with chmod +x composer.phar, the second by calling it as ./composer.phar -v.
You have to prefix executables that are not in the path with an explicit reference to the current path in Unix, in order to avoid going into a directory that has an executable file with an innocent name that looks like a regular command, but is not. Just think of a cat in the current directory that does not list files, but deletes them.
The alternative, and better, fix for the second problem would be to put the composer.phar file into a location that is mentioned in the path
This is for mac or ubuntu user, try this on terminal
curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/local/bin --filename=composer
or mac brew can try
brew install composer
MacOS: composer is available on brew now (Tested on Php7+):
brew install composer
Install instructions on the Composer Docs page are quite to the point otherwise.
First I did alias setup on bash / zsh profile.
alias composer="php /usr/local/bin/composer.phar"
Then I moved composer.phar to /usr/local/bin/
cd /usr/local/bin
mv composer.phar composer
Then made composer executable by running
sudo chmod +x composer
Step 1 : Open Your terminal
Step 2 : Run bellow command
curl -sS https://getcomposer.org/installer | php
Step 3 : After installation run bellow command
sudo mv composer.phar /usr/local/bin/
Step 4 : Open bash_profile file create alias follow bellow steps
vim ~/.bash_profile
Step 5 : Add bellow line in bash_profile file
alias composer="php /usr/local/bin/composer.phar"
Step 6 : Close your terminal and reopen your terminal and run bellow command
composer
https://getcomposer.org/download/
it might help
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
this code for ubuntu and wsl2.
Open terminal and run the following command,
sudo ln -s /usr/bin/php71 /usr/bin/php
Works in RHEL 8, php 7.4
sudo mv composer.phar /usr/bin/composer

Composer Installation on Server

How do I install composer on my web server? Is it a directory that I need to include?
I don't understand where the below code goes:
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
From:
https://getcomposer.org/doc/00-intro.md
The command curl -sS https://getcomposer.org/installer | php gets the code located on https://getcomposer.org/installer and sends it to PHP, PHP then runs the code on the given page. The code on that page will produce a composer.phar file in your CWD.
The command mv composer.phar /usr/local/bin/composer moves composer.phar to be file /usr/local/bin/composer
see:
mv
curl
These are Linux commands and are meant to be ran on a Linux server.

Can't install composer on OS X

I did this on terminal:
$ curl -sS https://getcomposer.org/installer | php
the output was:
All settings correct for using Composer
Downloading...
Composer successfully installed to: /Applications/XAMPP/xamppfiles/htdocs/composer.phar
Use it: php composer.phar
then I entered:
$ sudo mv composer.phar /usr/local/bin
No issues with this (it should work because usr/local/bin is in my $PATH). But how do I run it now? When I enter composer or composer.phar on the command line, I get:
-bash: composer: command not found
-bash: composer.phar: command not found
.phar is short for PHP Archive - it's a format that the php executable can read, not an executable on it's own right. To run it you should use:
$ php /usr/local/bin/composer.phar
To make your life a tad easier you could, of course, define an alias:
$ alias composer="php /usr/local/bin/composer.phar"
And then just call composer from your shell.
Did u check what do u have now in your path
ls -al /usr/local/bin
Check the right to execute.
To be sure u can do:
sudo chmod a+x /usr/local/bin/composer.phar
First look like should be composer.phar as you did not precise a new name in ur mv command like:
sudo mv composer.phar /usr/local/bin/composer
Did you made composer.phar executable ?
if not, just do sudo chmod a+x /usr/local/bin/composer.phar
$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
mv: rename composer.phar to /usr/local/bin/composer.phar: No such file or directory
Solution:
make sure composer.phar and directory local ,bin composer exist (/usr/local/bin/composer) in $PATH
else
$ cd usr
usr$m kdir local
usr/local$m kdir bin
usr/local/bin$ mkdir composer
now we're sur local/bin/composer exist than
$sudo mv /path to composer.phar /usr/local/bin/composer
Password:
toto:~ macbookpro$ your composer.phar now is move to directory usr/local/bin/composer

Categories