How to install Craft CMS to a web server. Part 1. Composer install

Categories: Code

Tags: ,

Craft CMS can be installed by using Composer. So in Part 1, I will show you how to install the Composer to a web server first.

You can also install it manually, but I found the process much simpler when using the Composer, even though I’ve never used it before, and I am very new to Craft CMS at the time of writing this article.

The ingredients you need

  1. Firstly you need to generate a SSH key from your web hosting (from cPanel).

    After you generate the key, save the private key text to your computer and remember its directory. The key would look like the image below.

    SSK Key

  2. The next step is to load the private key into your SSH-agent from the using the ssh-add command.
    ssh-add /User/youruser/private_key

    Replace /User/youruser/private_key with the location of your private key and the file name on your computer.

  3. Now with your SSH key added, you can connect to your web server using the following command in the

    Replace USER, HOST_NAME and PORT with the following:

    • USER: your cPanel username
    • HOST_NAME: enter the host orIP of the server
    • PORT: the port for the connection

    You may need to contact your hosting provider for the details.

  4. After connected to your server, you will be in the home directory of your server. From the home directory make a directory called composer-install with the following command in the
    mkdir composer-install

    You will see that it creates a folder composer-install in the home directory of your web server, and we will install the composer in this folder.

  5. Now go into the composer-install folder with the command below.
    cd composer-install/
  6. Then use the following commands one by one in the
    php -r "copy('', 'composer-setup.php');"
    php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
    php composer-setup.php
    php -r "unlink('composer-setup.php');"

    Line 5 – 8 could be updated any time, please use the latest scripts from the download page.

    Now if you go to the File Manager from the cPanel, you will see a composer.phar file in the composer-install folder.

  7. Next step is to enable the composer command to be used from any directory on your web server. So we will move the composer.phar file to usr/local/bin directory. Use the command below in the
    mv composer.phar /usr/local/bin/composer
  8. Congratulations! Now when you type composer in the you will see that the Composer is installed and working on your web server, and it will look like the image below.

    Composer installed

    We are ready to install the Craft CMS using the Composer. Please see the next article (Part 2) for how.