Tag Archives: 404

PHP Composer update command and Status: 404 Not Found on Linux server

Today I was trying to update Cakephp on my remote server using composer. I tried to follow the commands given at https://getcomposer.org/download/ under Command-line installation but it failed at the very first go. The command line code is:

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');"

My server is a CentOS Linux release 7.4.1708 (Core) server with cpanel install. So, running the first command over there gives 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 it tries to do:

  1. It tries to read the installer from give url https://getcomposer.org/installer 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 delets 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 you installed the composer in:

php composer update. However my method failed and then I found that the composer was already installed on my server at location /opt/cpanel/composer/bin. Since it was installed globaly and not under php php composer wont work at all.

Now if I ran composer update, because it was installed in teh given path it woudl show me the follwoing 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 https://getcomposer.org/ “Getting Started” section

So all I need is to specify the correct path of my working directory. Doing this worked like a charmfor me:

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