How To Deploy PHP App On Vercel FREE
Published 24 October 2023 by Jarvis Silva
Looking for tutorial on how to host php website on Vercel platform then you are at the right place in this article I will show you how to deploy php app on Vercel web hosting platform.
Vercel is a cloud web hosting service which is popular for hosting web apps made using next js, react or other frontend frameworks but you may not know that you can host php on vercel serveless functions by using their php runtime.
Note: one thing you need to keep in mind with hosting php website or application on Vercel is that Vercel is not optimised for php so it is not recommended to host production applications or large apps, use it only for personal use.
I will show you how to deploy a simple php api which returns hello world and I will use Vercel free tier plan to deploy it, so now let's see how to deploy step by step.
1. Configure php project to deploy to Vercel
First we need to configure our php project to make it deployable on Vercel, first we need to create a api folder and put all our php codes inside it, then we need to create a vercel.json file and add some configuration so let's see step by step.
- First I will create a api folder, add a index.php file inside it and add a basic php api code that returns hello world on get request, you can see from below.
- Now we need to create a vercel.json file in the root of the project and add some code in it so copy the below code and paste in your vercel.json file
{
"functions": {
"api/**/*.php": { runtime: "vercel-php@0.6.0" },
},
"routes": [
{ src: "/(.*)", dest: "/api/index.php" }
],
}
Now our php api is ready to deploy on Vercel, If you have many routes in your php website make sure you add it in the vercel.json file, refer here for more advanced configuration: Using Vercel Serveless Functions.
2. Upload code to Github
To deploy any code on Vercel we need to first upload the code on Github repository then in Vercel connect github account and import the code from the Github repository, follow the below steps to push code to Github:
- Open Github and login to your account, click on create a new repository, enter your app name, leave rest everything default and click create repository.
- Now it will show you commands to push your code to this repository, open a terminal at your static website code location and run all the commands one by one or you can drag and drop.
Read: How to push code to github
After you run all the commands you should see your code upload to your Github repository.
3. Deploying PHP code to Vercel
Now we just need to deploy our php app code on Vercel for that you need to have your Github connected with your Vercel account to do that you can login by Github account or use the connect Github option in Vercel, after connecting follow the below steps:
- Go to your Vercel dashboard and click on the add new button it will open a dropdown in that click on project.
- Now it will open a new page displaying your Github repositories, now here you need to click on import of your php website code repository you want to host.
- Now it will ask you to enter your project name, leave the other settings as default and click on deploy.
Now it will start building your website and deploy it on Vercel, it will generate some preview url to view your php website or app, you can also connect a custom domain if you have.
Also Read: Deploy express app to Vercel
So we have seen it is possible to host php on Vercel, I hope you found this tutorial helpful and you were able to deploy your php app to vercel. Thank you for reading, Have a nice day 😊
About the author
I am Jarvis Silva, a tech enthusiast. I have 5 years of experience in website hosting and development, Now sharing all my knowledge related to web hosting and other various tech on the internet through Hostwizly.