DEV Community

Himanshu Gupta
Himanshu Gupta

Posted on

How to Run Reactjs Build On Server

Step 1) Add “homepage”:”your url”, to the object in your package.json file.

Step 2) In your terminal run npm run build

Step 3) Add a .htaccess file to your build folder with the following code:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Enter fullscreen mode Exit fullscreen mode

Step 4) Use a file manager to upload all of the files from your build folder including your .htaccess file to the public folder on the server. I used FileZilla, but you can use the built in file manager or SSH keys. If you don’t know how to make an FTP user, go here.

Siteground specific instructions:

Step 5) Navigate to the site tools for the desired website. (You can even use a temporary domain for this).

Step 6) Install an SSL certificate in Security > SSL Manager. (You can use the free one. Take note of the expiration date.)

Step 7) Enforce HTTPS by going to Security > HTTPS Enforce and turn it on.

That should work! Send questions if you have any.

Top comments (0)