php composer update command and status: 404 Not Found on Linux

Today I tried to update Cakephp by running php composer update on my server. I tried to follow the commands given at under Command-line installation but it failed at the very first go. The command line code was:

php -r "copy('', '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');"

My server is a CentOS Linux release 7.4.1708 (Core) server with cpanel installed. So, running the first command over there gave me the following error:

Error in argument 1, char 2: option not found r

Which clearly indicates the there is no r argument. If we check the above code in detail this is what it tries to do:

  1. It tries to read the installer from give url and write it to a file named composer-setup.php
  2. If the file hash matches the given hash it tells user that install is verified otherwise it says that the Installer is corrupt and deletes the file from server.
  3. Runs composer-setup.php
  4. Deletes composer-setup.php from server.

After doing all these steps it would let you run the following command in your directory in which you installed the composer:

php composer update

However my method failed. After doing some searching, I found that composer was already installed on my server at location /opt/cpanel/composer/bin. Since it was installed globally and not under php, php composer won’t work at all.

php composer update

Now if I ran composer update, because it was installed in the given path it would show me the following message:

Composer could not find a composer.json file in /opt/cpanel/composer/bin
To initialize a project, please create a composer.json file as described in the "Getting Started" section

So all I needed was to specify the correct path of my working directory. Doing this worked like a charm for me:

composer update --working-dir /home/myproject/public_html/

Leave a Reply