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
- A web hosting server (Server requirements details)
- Composer (Download Composer here)
- Terminal (I will be using Terminal App on Mac OS X)
- 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.
- The next step is to load the private key into your SSH-agent from the Terminal.app using the ssh-add command.
1
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.
- Now with your SSH key added, you can connect to your web server using the following command in the Terminal.app.
2
ssh USER@HOST_NAME -pPORT
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.
- 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 Terminal.app.
3
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.
- Now go into the composer-install folder with the command below.
4
cd composer-install/
- Then use the following commands one by one in the Terminal.app.
5 6 7 8
php -r "copy('https://getcomposer.org/installer', '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 getcomposer.org 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.
- 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 Terminal.app.
9
mv composer.phar /usr/local/bin/composer
Congratulations! Now when you type composer in the Terminal.app you will see that the Composer is installed and working on your web server, and it will look like the image below.
We are ready to install the Craft CMS using the Composer. Please see the next article (Part 2) for how.