How to install Composer on macOS? - php

I was trying to install the Composer on my macOS version: high sierra--> 10.13.4
but after using the command:
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
It created some files and directory but it didn't download the composer.
My terminal displayed following error:
No log handling enabled - using stderr logging
Created directory: /var/db/net-snmp
Created directory: /var/db/net-snmp/mib_indexes`
How can I resolve this problem?

OLD Answer (The Ruby Homebrew installer is now deprecated and has been rewritten in
Bash.):
First install Brew on your MAC:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
NEW Answer:
First install Brew on your MAC:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install PHP:
brew update
brew install php
brew install composer
To test installation, run:
$ composer -V

Install Brew in Mac Terminal
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install Composer
brew install composer
Check Composer
composer -V

Install download the composer using the following curl command in the
terminal:
curl -sS https://getcomposer.org/installer | php
After the command, you will have composer.phar file in the current
directory and the composer command is available as:
php composer.phar [composer commnad]
In order to make composer available globally, you have to move the
recently downloaded composer.phar to local user’s bin folder as follow:
go to /usr/local/bin folder . You can click Shift + Command + G to open
the dialog to go to folder.
move the recently downloaded composer.phar in the usr/local/bin folder
create a alias using command alias composer="php
/usr/local/bin/composer.phar"
Now, you can access the composer from the terminal simply using the
composer command. Thats it.

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

Docker and symfony

I'm struggling with Docker.
I'm tring to create an image to work on symfony project and to learn Docker in the same time.
Here is my Dockerfile:
FROM php:7-apache
LABEL Description = "This image is used to start Symfony3 project"
ENV DIRPATH /var/www/html
# apt-get command
RUN apt-get update && apt-get install -y \
vim \
git \
&& apt-get clean
# Install Composer
RUN curl -sS https://getcomposer.org/installer | php
RUN mv composer.phar /usr/local/bin/composer
# Install the Symfony Installer
RUN curl -LsS http://symfony.com/installer -o /usr/local/bin/symfony
RUN chmod a+x /usr/local/bin/symfony
I build the image with the command:
docker build -t symfony .
Works well! Cool!
I'm create a container with:
docker run --name symfony -d -v "$PWD":/var/www/html -p 80:80 symfony
Works well also. The web server is running on the good port.
I can go in my container with:
docker exec -ti symfony bash
But when I'm trying to do a composer update, I have some errors:
Failed to download symfony/symfony from dist: Could not decompress the archive, enable the PHP zip extension.
A php.ini file does not exist. You will have to create one.
How can I create the php.ini in Dockerfile?
I also think that I have an issue with permission.
When I'm trying to the web/app_dev.php I have this message:
You are not allowed to access this file. Check app_dev.php for more information.
You can ADD a custom php.ini configuration specifing it in the dockerfile,
As Example, you can take a look at this repo for this example:
dokerfile
# install a few more PHP extensions
RUN apt-get update && apt-get install -y php5-imagick php5-gd php5-mongo php5-curl php5-mcrypt php5-intl
# copy a custom config file from the directory where this Dockerfile resides to the image
COPY php.ini /etc/php5/fpm/php.ini
You can find various approach and various sample on the net.
Hope this help
Next to the missing php.ini file you should also install zip so you can download from dist, i.e.
RUN docker-php-ext-install zip
Which will install and enable the PHP zip extension which is requested in your error message.

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

Laravel - Unable to open composer.phar file

Hey just started working on laravel. First day for me. Not much idea. Step by step following the steps from documentation given by https://www.laravel.com
After installing composer on my desktop at root folder. As soon, i opened composer.phar, it showed this error -> there is a problem opening the file "/root/composer.phar"
I followed steps given in https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx .
apt-get install curl
apt-get install php5-cli
curl-sS https://getcomposer.org/installer | php
php composer.phar
Is there any problem ? Please help me........
For installing composer try follow this
sudo apt-get install curl
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
Setting up Laravel
Run only composer and see if composer is installed.
If yes then let's install laravel installer to quickly install laravel. Run this command from your command line composer global require "laravel/installer=~1.1"
Now if you are using zsh then add this line to user home directories .zshrc file export PATH="~/.composer/vendor/bin:$PATH"
Else add this lines to .bashrc file export PATH="~/.composer/vendor/bin:$PATH"
Now you can run laravel new blog and a new laravel installation will be downloaded.
Now run php artisan serve from that directory to serve your laravel
See http://laravel.com/docs/5.1/#installation for more details
Tips: You can create a separate file and include it to your
.zshrc or .bashrc

How to install Composer on a Mac?

I'm trying to get the Laravel PHP framework installed and for that I need to install Composer. However I'm getting stuck there. I installed it before for Symfony but I couldn't get it to work so I think I deleted it.
When I open the terminal on Mac and enter one of the commands for installing composer like:
curl -sS https://getcomposer.org/installer | php
I get:
-bash: php: command not found
curl: (23) Failed writing body (0 != 1635)
Why is this?
You can install it via Brew.
First, install Brew;
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then you can use Brew to install Composer;
brew install composer
That's it, it's now installed. You can verify this by running composer --version
download file from https://getcomposer.org/installer
execute the file
sudo php installer
and move the file
mv composer.phar /usr/local/bin/composer
Here it is:
curl -s https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
First install brew if not installed in Mac:
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update brew and install php and composer.
$ brew update
$ brew install php
$ brew install composer
Verify by checking version:
$ composer -V
I hope it helps.
try
~ which php
/usr/bin/php
curl -sS https://getcomposer.org/installer | /usr/bin/php
just open your terminal and follow this steps,
here odbase is username of my mac.
cd /Users/odbase/Downloads
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '93b54496392c062774670ac18b134c3b3a95e5a5e5c8f1a9f115f203b75bf9a129d5daa8ba6a13e2cc8a1da0806388a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
php composer.phar
mv composer.phar /usr/local/bin/composer
(if this produce error please run with prefix sudo. {sudo mv composer.phar /usr/local/bin/composer})
installed for check
cd /usr/local/bin
ls
I deleted some files that I should not have deleted. Did a repair install of OS X and now it works.

Categories