I am developping a custom search API from VuePress static websites and I needed to host it.
Since I have a Cloudways VPS, let’s see how to run the REST API.
What do you need
- Create an account on Cloudways.
- Provision a VPS (
https://unified.cloudways.com/server/create
) (the smallest is fine for my REST API). - Create a custom PHP app.
Important file to include in your repository
Make sure to add a .htaccess
containing the following:
|
|
Deploying the REST API
You can use the “Deployment via GIT” that allow you to pull the code from you repository.
For updates
You will need to use the pull
button under the Cloudways application.
Doing a git pull
in applications/your_rest_api/public_html/
will not work.
Asking Cloudways support to enable mod_proxy
This might not be enabled, so do check with the support Team if you get errors about this.
Your best bet is to ask by default.
Install pm2
package to run your REST API
Unless you do the following, your NodeJS app will stop running after 4h.
Running node app.js
is not sufficient.
pm2
enables you to launch the REST API and have it run without stopping.
To enable pm2
, run the following via SSH logged in with your master user:
|
|
Restart the shell by exiting and reconnecting.
Then run on the root directory of the serve (where you land once connected):
|
|
You should get:
That’s it!
I hope you enjoy this peace. I release a new article once to twice every week. Consider subscribing to my newsletter
Credits
Thanks to the CloudKeeper for his articles: