Craft CMS 3 can be installed and updated by Composer. So in Part 2, we will use the Composer to install the Craft to a web server using a Terminal.app.
If you don’t have the Composer installed on your web server, please read my previous post first.
As mentioned in my previous post I am new to Craft, and it took a few attempts to install and make it work on my web server. So if you are new to Craft as I am, and trying to install it on a web server, hopefully this post can save some of your time.
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, set up a directory (folder) on your server for the Craft CMS to be uploaded to, then change its document root directory.
In my case I have set up a subdomain called craft from the cPanel on my web server, then modified the subdomain’s document root folder to be ~/public_html/craft/web.
In more details, when you set up a subdomain its directory will be ~/public_html/subdomain or something similar. Then you need to change the subdomain’s document root directory to be ~/public_html/subdomain/web.
This is very important that you set up the subdomain’s document root directory. If you don’t set it up, after you install the Craft CMS you would get 503, 500 or 403 errors. It will be explained more in the later process.
- Next, open the Terminal.app and connect to your server by using the command below.
1
ssh USER@HOST_NAME -pPORT
Replace USER, HOST_NAME and PORT according to your own server.
If you are already connected to your server, skip this step. Please refer to the previous post for more details.
- Then move to your subdomain directory using the following command.
2
cd public_html/subdomain
Replace public_html/subdomain with your own subdomain directory.
- Now we can command Composer to install Craft CMS in your subdomain directory by inputting the following snippet in the Terminal.app.
3
composer create-project craftcms/craft .
Do not miss the dot at the end of the command. Otherwise, Composer will create a separate sub folder called craft within your subdomain folder.
After the command, you will see the installing process on your Terminal.app screen. When the Craft CMS is successfully uploaded onto your subdomain folder you will see the the Craft CMS welcome message. It will look like the image below.
Now if you open the File Manager on your cPanel, you will see that the Craft CMS is uploaded to the ~/public_html/subdomain directory. And you will also notice that index.php or .htaccess files are missing from the subdomain folder.
The index.php and .htaccess are located in the folder called web. This is the reason why we needed to set up the subdomain’s document root folder to be ~/public_html/subdomain/web earlier.
Finally, with the Craft CMS uploaded onto your server, you can finalise the installation.
Open your browser and type in the URL of your subdomain then add /admin at the end, something like http://subdomain.domain.com/admin in the address bar.
You will see the install screen of your first Craft CMS on your browser. It will look like the image below.
Follow the instruction on the screen. You need to have a fresh database set up to connect to your Craft CMS.
After completing the install process including connecting the database, you will be redirected to the admin panel of the Craft CMS. It will look like the following image.
Congratulations! You have successfully installed Craft on your web server. Happy Crafting!