How to Deploy a Next.js Application on a VPS Server
This is the 15th part of our series on deploying a Next.js application with a headless WordPress backend. In this article, we will walk you through the process of deploying your Next.js application on a VPS server.
Prerequisites
Before you can deploy your Next.js application on a VPS server, you will need to have the following:
- A working Next.js application
- A VPS server with SSH access
- Node.js and npm installed on the VPS server
Step 1: Prepare your Next.js Application for Deployment
Before you can deploy your Next.js application on a VPS server, you need to prepare it for production. Make sure to run the following command to build your Next.js application:
npm run build
Step 2: Transfer your Next.js Application to the VPS Server
Once your Next.js application is built, you can transfer it to your VPS server using SCP or any other file transfer method of your choice:
scp -r /path/to/your/nextjs/app username@vps:/path/to/destination
Step 3: Run your Next.js Application on the VPS Server
After transferring your Next.js application to the VPS server, you can start the application using the following command:
npm run start
Conclusion
Deploying a Next.js application on a VPS server is a straightforward process. By following the steps outlined in this article, you can easily deploy your Next.js application and make it accessible to the world.
thank you very useful video
Thanks a lot, it was really useful ¿How would you deploy Next Js apps in subdomains of that domain and how would you add a database for storing the data?
perfect mate. you're the best
Hello! Thanks for this video! I have a question: if my web-application is using access to Database, I also need to install MariaDB on the server? And how should I configure the database on the server, because before I used only on localhost?
Amazing video, thank you very much.
This video is excellent. You only need to follow all the steps carefully. Thanks a lot!
pm2 is running fine but I can't get any response when i run http://ip:3000, I get default page when running http://ip
very helpful.
thanks
Thanks a million for your valuable efforts! I'm following your tutorials and all is well…
However, when I create the build and run it, all is fine except when you press load more to load more posts:
– New posts are loaded under blog archive page.
– Clicking on newly loaded posts to load the single post page, I get 404. as if these posts pages were not rendered..
Can you try the same and let us know?
Thanks in advance.
Hi, if my app has enviroment variables how i set it in my vps?
Thx!! 🤩
Thank you! Very helpful.
Thank you for this video. I have seen certain developers in the nginx sites-available default file set up an alias for the location /_next/static directive to point to the .next/static/ folder. You have not used that step in this video. Would u mind kindly explaining why not? if this step is a must or not. Thank you very much again for this video.
Very concise. Thanks for this.
Thanks you so much
Thanks