How to Deploy Strapi MySQL on a Traditional Hosting Provider
Tags: strapi, javascript, deployment, mysql
Published: 2022-09-08 07:47:28

_This article explains to deploy a Strapi MySQL on a traditional hosting provider._

**Author: Abdulwahab Ashimi**

If you have a Strapi app you want to deploy but are uninterested in the multiple cloud or [VPS options](https://strapi.io/blog/deploying-strapi-to-your-own-vps) and want to use a shared hosting package instead, this article is for you.

At the end of this tutorial, you should know how to set up a shared hosting package, install your core requirements, tweak your database options, and deploy your Strapi project.

## Introduction to Strapi
Strapi is an headless Content Management System that offers you the chance to develop API with distinctive features. Built on Node.js, works with any GraphQL enabled Frontend Frameworks and is open-source.

## What is a Shared Hosting Package?
Shared hosting is a low-cost multi-tenant web hosting with hundreds of users each getting a personal section of a server and co-utilizing its resources to host their website and application.

## Prerequisites
To follow through this article, you should have:
1. Basic knowledge of JavaScript
2. Basic understanding of Strapi - [get started here.](https://strapi.io/documentation/developer-docs/latest/getting-started/introduction.html)
3. Git installed
4. [Node.js v14+](https://nodejs.org/en/)


## Strapi Hardware Requirements
Your computer should have these to enable you run Strapi effectively:
- At least 1 CPU Core (Recommended: 2 CPU Cores)
- Minimum 2GBs RAM (Recommended: 4GBs)
- Disk Space Minimum of 32GBs

## Things to Consider Before Purchasing a Hosting Package
Before buying a hosting package, you should consider the **price, tech specs or limitations, tech support,** and **scalability.** 

Almost all shared hosting providers promise security and 24/7 uptime which is often true. What you should really pay attention to is the cost of the shared hosting compared to alternatives, the availability of their tech support when you run into issues and how easy it is to upgrade your package. Does it serve your need? What are possible challenges you might face? What do existing users have to say about them?

## Setting up Strapi Locally

We will start by creating a Strapi app on your local machine. Create an empty database in your `Phpmyadmin` and using the terminal, run the following command:
```bash
    npx create-strapi-app@latest my-project
```
**Select the following options:**
* **Installation Type:** Custom
* **Preferred Language:** Javascript or TypeScript but I will be using JavaScript
* **Database Client:** MySQL
* **Database Name:** Your database name

![Strapi Installation](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659541133794_.env+-+my-projectt+-+Visual+Studio+Code+8_3_2022+8_38_06+AM.png)

Navigate into the project folder and run the command below:
```bash
    npm develop
```
![Strapi Dashboard](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659541266615_Homepage+-+Google+Chrome+8_3_2022+8_40_50+AM.png)

The project should be live on your local machine and database.

![Strapi MySQL Database Structure](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659541384695_localhost+_+127.0.0.1+_+strapi+_+phpMyAdmin+5.2.0+-+Google+Chrome+8_3_2022+8_42_18+AM.png)

Let’s deploy our project on our shared hosting.

## Setting up Hosting
We will be using Namecheap for this tutorial. Go to the  [Namecheap Shared Hosting](https://www.namecheap.com/hosting/shared/) page and select your preferred package. They all support our Strapi Requirements but I will be using the **Stellar** package. 

![Namecheap Hosting Purchase Page](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659516157433_Shared+Hosting+Plans+-+Fast+and+Secure+Web+Service+from+Namecheap.+-+Google+Chrome+8_3_2022+1_39_40+AM+2.png)

Click “Get Started” on your preferred package and follow the process. Once you have successfully purchased your hosting, check your mail for instructions and log in to the cPanel or access it from the Namecheap dashboard.

![cPanel Dashaboard](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659516748416_Shared+Hosting+Plans+-+Fast+and+Secure+Web+Service+from+Namecheap.+-+Google+Chrome+8_3_2022+1_50_29+AM.png)

Type “Terminal” on the Search Box

![Terminal Search](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659517125309_cPanel+-+Main+-+Google+Chrome+8_3_2022+1_57_14+AM.png)

Click on the icon and launch your terminal.

![Terminal Page](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659517208614_cPanel+-+Terminal+-+Google+Chrome+8_3_2022+1_59_22+AM.png)

## Setting up Your Project
Make sure git is installed by running the command below:
```bash
    git version
```
The command above will show you the current version of git and if it turns an error, you will have to [install git](https://github.com/git-guides/install-git#:~:text=To%20install%20Git%2C%20navigate%20to,installation%20by%20typing%3A%20git%20version%20.).

Now, you need to clone your Strapi Project from Github.

![Project Page on Github](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659542233643_ibn-ashimi_my--project+-+Google+Chrome+8_3_2022+8_55_56+AM+1.png)

On your terminal, navigate into the `Public_``html` folder and run
```bash
    git clone (url)
```
In my case, it is:
```bash
    git clone https://github.com/ibn-ashimi/my--project.git
```
Now that we have our project on the cPanel, we will proceed to install~~ing~~ Node.
> Note: If you didn’t push your project to git, you can simply zip the file and upload it via File Manager.

## Setting up the Database
Navigate to your cPanel homepage. Search and click on `MySQL Database`.
![MySQL Database option on cPanel](https://paper-attachments.dropbox.com/s_C75A0C7B62C5E48010D724F7C4F9BF53A91173A7ADEE3259FE4C3F44AA9D601F_1659784030903_zXzuZToc.png)

Create a new database and user, then assign them to one another.
![Database Manager on cPanel](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659545826047_cPanel+-+Main+-+Google+Chrome+8_3_2022+9_56_38+AM.png)

Proceed to `Phpmyadmin` on your Cpanel. Locate your database and import your local SQL file.
![Phpmyadmin Preview Page](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659546036359_premium189.web-hosting.com+_+localhost+_+thepsrcz_strapi+_+phpMyAdmin+4.9.7+-+Google+Chrome+8_3_2022+9_59_57+AM.png)

## Installing Node
Navigate to your cPanel homepage. Search and click on `Setup Node.js App`.
![Setup NodeJs App option on cPanel](https://paper-attachments.dropbox.com/s_C75A0C7B62C5E48010D724F7C4F9BF53A91173A7ADEE3259FE4C3F44AA9D601F_1659783920768_TwRbnCqE.png)

Click on “Create Application”.
![Creating Node Application](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659542950724_cPanel+-+Node.js+-+Google+Chrome+8_3_2022+9_06_52+AM.png)

Choose `12.22.9` as Node.js Version, `Production` as the application mode. Input your Strapi directory as the application root, the subdomain or domain as the application URL and use server.js as the application startup file. Click on “Create” and you will be redirected here.

![Created Node Application](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659543249026_cPanel+-+Node.js+-+Google+Chrome+8_3_2022+9_10_06+AM.png)

Launch your terminal and run the provided command (see the circled part of the image above). This will start up a development environment inside the project folder. 

Locate database.js in your config folder and access it using 
```bash
    nano database.js
```
![Terminal Page](https://paper-attachments.dropbox.com/s_05BC650816EB277D069F66D15C4E1C692BDEC220CC97E9695164D3DEC17C56C9_1659546418456_cPanel+-+Terminal+-+Google+Chrome+8_3_2022+10_06_20+AM.png)

Run this command on terminal to create your env file:
```bash
    cp .env.example .env
```
You can access and edit it using:
```
    nano .env
```
Start your Strapi server using the code below:
```
    NODE_ENV=production run build
```

## Conclusion
Well done! You deployed your Strapi project on a Traditional Hosting with MySQL Database. 

Note that it is not so effective and not always recommended to use a traditional hosting. Cloud or [VPS Hosting](https://strapi.io/blog/deploying-strapi-to-your-own-vps) are better options. Start a Discussion below with your questions and share with others too.