{"id":1735,"date":"2021-09-17T13:39:58","date_gmt":"2021-09-17T13:39:58","guid":{"rendered":"https:\/\/citrusleaf.in\/blog\/?p=1735"},"modified":"2021-09-17T13:39:59","modified_gmt":"2021-09-17T13:39:59","slug":"deploying-strapi-on-windows-server-without-using-process-managers","status":"publish","type":"post","link":"https:\/\/citrusleaf.in\/blog\/deploying-strapi-on-windows-server-without-using-process-managers\/","title":{"rendered":"Deploying Strapi on Windows Server without using Process Managers"},"content":{"rendered":"\n<p>Hosting a Strapi\/NodeJS application on a windows server is not hard but it can be a big task when done with no proper documentation. We started it with using Process Managers which helps in keeping the application running in the production environment. It helps developers to monitor users\u2019 engagement with real-time logging and reporting. There are several NodeJS process managers available, unfortunately, none of them supports hosting on a Windows server. Here are the issues we faced with some of them-<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>PM2 <\/strong>&#8211; PM2 is a NodeJS process manager with a built-in load balancer. It is one of the most used, highly capable, and well-documented process managers available. When using PM2 to run Strapi application, it worked well for the Linux system. For Windows, it ended up in the npm.cmd error as it has to be run in as a separate JS script. We tried the solution shared <a href=\"https:\/\/github.com\/Unitech\/pm2\/issues\/2808#issuecomment-367352136\">here<\/a>. On trying this one, we came across a new issue where the process was running but the localhost does not connect. With all our failed attempts with PM2 we decided to try another process manager.<\/li><\/ol>\n\n\n\n<ol class=\"wp-block-list\"><li><strong>StrongLoop Process Manager<\/strong> &#8211; Maintained by IBM, StrongLoop PM is a NodeJS production process manager that helps you to build and deploy your NodeJS application and run its process and clusters in the production environment. This has inbuilt load balancing and allows one to keep track of performance metrics on the application. Unfortunately, it works only for Linux and macOS. It is not supported in Windows as mentioned in its <a href=\"https:\/\/loopback.io\/doc\/en\/lb2\/Installing-on-Windows.html\">documentation<\/a>.<\/li><\/ol>\n\n\n\n<p>Both of the above-discussed process managers are well explained in an article on <a href=\"https:\/\/strapi.io\/blog\/what-are-process-managers-and-how-to-use-them-with-strapi\">Strapi blog<\/a>. But both of them failed deploying a Strapi application on the Windows server<\/p>\n\n\n\n<p>After all our failed attempts of using process managers, we decided to run NodeJS as a service on our Windows machine and then expose it using reverse proxy on IIS<\/p>\n\n\n\n<p>Here are the steps we followed to deploy our Strapi application on the Windows server.<br><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Launch the server &#8211;<br><\/strong>Before running your server in production you need to build your admin panel for production.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li> Go to your app folder and run the below command <\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install cross-env<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Then in your package.json scripts section add the below code.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">\"build:win\": \"cross-env NODE_ENV=production npm run build\",<br><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>And then finally run<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">npm run build:win<\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li> <strong>Run the server with the production settings<\/strong> <br>After a successful build, for running the application add the below code in the scripts section in your package.json.<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">\"start:win\": \"cross-env NODE_ENV=production npm start\",<\/pre>\n\n\n\n<p>And then run <\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">npm run start:win <\/pre>\n\n\n\n<p>This will start your application on the default port 1337 or any other port mentioned in your config file. Your application should be running on <a href=\"http:\/\/localhost:1337\/\">http:\/\/localhost:1337\/<\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li> <strong>Create a Windows Service to run our Node.js application automatically<\/strong><br>Create  a Windows service to ensure your Node.js website is always running and  automatically restarted if it ever crashes. There are many tools for  this, we will be going ahead with the free tool NSSM (non sucking  service manager). You can download it from the official website at<a href=\"https:\/\/nssm.cc\/download\"> nssm.cc<\/a>. <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>After downloading, run the executable nssm.exe from downloads\\nssm-2.24\\nssm-2.24\\win64.<\/li><li>Stop the Strapi application if it is still running.<\/li><li>To get the service installation GUI run &#8211; <\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"> nssm install &lt;serviceName><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>On running the above command, an installation window opens up as below.<\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh4.googleusercontent.com\/uPTRGew2J5B245MklHWQ2i7g8SHc9ITiPHRk6H4CgnlxodQSo2qug7EoAJ1n0ibgN_mD15eYmYrQsfU7rtARHYDrHRFoTlqKT_ZgPK21INA41Vez7F9NvdaDWvgPGEmPPAvXk4Z-=s0\" alt=\"\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Enter the application path as the path to your npm.cmd file &#8211; C:\\Program Files\\nodejs\\npm.cmd<\/li><li>Set Startup Directory as path to your Strapi project.<\/li><li>Set Arguments as \u201cstart:win\u201d<\/li><li>Enter any service name and click on Install service.<\/li><li>Then start the service by running the below command<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">nssm start &lt;serviceName&gt;<\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>To confirm the service status, run &#8211; <\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\">\nnssm status &lt;serviceName&gt;\n\n<\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>Go to localhost:1337, your app should be working now.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li> <strong>Reverse Proxy with IIS<\/strong> <br>For running the Strapi  application on windows, we will create an additional layer of reverse  proxy with the built-in web service manager IIS.\u00a0 <\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Make sure the IIS is running on your system. You can start it from the \u201cTurn windows feature on and off\u201d setting in windows 10. <\/li><li>To ensure that IIS is running, the <strong>Internet Information Services checkbox <\/strong>should be selected and on running <a href=\"http:\/\/localhost\">http:\/\/localhost.<\/a>A windows IIS site should appear.<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\"><li>Install Application Request Routing and URL Rewrite<ul><li>Install \u201c<a href=\"https:\/\/www.microsoft.com\/web\/downloads\/platform.aspx\"><strong>Microsoft Web Platform Installer<\/strong><\/a><strong>\u201d <\/strong>if not present already. Run the application. If a <strong>User Account Control<\/strong> box appears, click <strong>Yes<\/strong>. The <strong>Web Platform Installer<\/strong> window appears.<\/li><li>Search by typing \u201c<strong>Application Request Routing<\/strong>\u201d in the search box and press <strong>Enter<\/strong>.<\/li><li>Click the <strong>Add<\/strong> button in the row labeled <strong>Application Request Routing 2.5 with KB2589179<\/strong>. If there\u2019s a newer version, you could choose that one instead.<\/li><li>Back in the search box, type \u201c<strong>URL Rewrite<\/strong>\u201d and press <strong>Enter<\/strong>.<\/li><li>Add <strong>URL Rewrite 2.1<\/strong>.<\/li><li>Click on Install.<\/li><li>To set up a rewrite URL, Start IIS manager. (If it was already opened, please close and start it again to reflect the installations).<\/li><li>Go to Sites by clicking on your system name in the Connections pane.<\/li><li>Under Sites select Default website.<\/li><li>Double click URL rewrite to open its features. Add a new rule.<\/li><li>Select Reverse Proxy and then click on OK.<\/li><li>You will see a window like below.<\/li><\/ul><\/li><\/ul>\n\n\n\n<figure class=\"wp-block-image\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"568\" height=\"574\" src=\"https:\/\/i0.wp.com\/citrusleaf.in\/blog\/wp-content\/uploads\/2021\/09\/89_1lvsG_t.png?resize=568%2C574&#038;ssl=1\" alt=\"\" class=\"wp-image-1738\" srcset=\"https:\/\/i0.wp.com\/citrusleaf.in\/blog\/wp-content\/uploads\/2021\/09\/89_1lvsG_t.png?w=568&amp;ssl=1 568w, https:\/\/i0.wp.com\/citrusleaf.in\/blog\/wp-content\/uploads\/2021\/09\/89_1lvsG_t.png?resize=297%2C300&amp;ssl=1 297w\" sizes=\"auto, (max-width: 568px) 100vw, 568px\" \/><\/figure>\n\n\n\n<ul class=\"wp-block-list\"><li>Enter the server name or IP address where HTTP requests will be forwarded. This is where your Node.js server is listening. If you set up your environment according to this guide, this will be localhost:3000. You can leave the other options set to their default and click <strong>OK<\/strong>.<\/li><li>We\u2019re almost done. With that rule saved, IIS will proxy any traffic heading towards localhost to localhost:3000. You can test that in your web browser.<\/li><\/ul>\n\n\n\n<p>That\u2019s all, with all the steps completed successfully, your <a href=\"https:\/\/citrusleaf.in\/case-studies\/retail-distribution-business-mobile-crm-development\">Strapi application<\/a> is now hosted on a Windows server. If you are looking for any<a href=\"https:\/\/citrusleaf.in\/strapi-headless-cms-development\"> further assistance with your Strapi or NodeJS application<\/a>, you can contact the specialists <a href=\"https:\/\/citrusleaf.in\/contact\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hosting a Strapi\/NodeJS application on a windows server is not hard but it can be a big task when done with no proper documentation. We started it with using Process Managers which helps in keeping&hellip; <\/p>\n","protected":false},"author":2,"featured_media":1741,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[7,10],"tags":[267,268,270,266,265,269],"class_list":["post-1735","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","category-development","tag-deploying-nodejs-applications","tag-iis","tag-reverse-proxy-iis","tag-strapi-applications","tag-windows-server","tag-windows-server-deployment"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/citrusleaf.in\/blog\/wp-content\/uploads\/2021\/09\/Deploying-Strapi-application-on-IIS-without-using-Process-Managers1.png?fit=1200%2C628&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pei5Vv-rZ","_links":{"self":[{"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/posts\/1735","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/comments?post=1735"}],"version-history":[{"count":8,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/posts\/1735\/revisions"}],"predecessor-version":[{"id":1745,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/posts\/1735\/revisions\/1745"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/media\/1741"}],"wp:attachment":[{"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/media?parent=1735"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/categories?post=1735"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/citrusleaf.in\/blog\/wp-json\/wp\/v2\/tags?post=1735"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}