Deploy PHP Application to Vercel

There are several platforms that can be used to host websites created with the PHP programming language, one of them is Vercel. Vercel is a cloud platform for frontend frameworks and static sites. To be able to host PHP application, we will use the PHP Runtime for Vercel Serverless Function that was created by vercel-community.

Prerequisite

Before we get started, there are a few things that need to be prepared.

  • GitHub

    GitHub is used to connect Vercel with your GitHub repository. So whenever you change your code, Vercel will automatically deploy your application with the changes you make. You can sign up and create your account here.

  • Vercel

    Vercel is used to deploy the application and integrated it with your GitHub repository. We also need some configuration on Vercel to make the application run perfectly. You can sign up and create your account here.

  • PHP

    PHP is used in development, especially in local development. You can modify the application and run it locally using PHP. After that, push your changes to GitHub and Vercel will do the rest. You can download PHP here.

  • Composer

    Composer is used to manage dependency for PHP application. With Composer you can easily manage your external libraries used in PHP application. You can download Composer here.

Create Application

To simplify the process, we will use this website. You can create a new GitHub repository using this template.

Create a new repository from template.

GitHub Template

Give the repository name and description, then Create repository.

Create From Template

The PHP application is ready. Next we will configure Vercel for deployment.

Success Create From Template

Configure Vercel

First, you need to have a Vercel account, then connect your GitHub repository to Vercel.

Select Add new then choose Project.

New Project Vercel

Connect with your previous created repository, then click Import.

Import GitHub Repository

Give project name and click Deploy.

Configure Project Vercel

Wait a moment and then your app has been deployed, after that choose Continue to Dashboard.

Deploy Application Success

Select Settings in your project dashboard.

Dashboard Setting Vercel

Under your project's Settings, choose Environment Variables and then add your Font Awesome kit URL.

Environtment Setting Vercel

A new deployment is required for your changes to take effect, go to Deployments to redeploy it.

Dashboard Deployment Vercel

Under your project's Deployments, click the ellipsis (tree dots) and then choose Redeploy.

Redeploy Vercel

Confirm redeploy by clicking REDEPLOY.

Confirm Redeploy Vercel

Wait a moment and then your app has been redeployed, after that click Visit to view your application.

Redeploy Success

Congratulations, you have successfully deploy your PHP application to Vercel.

Visit Result

Local Development

If you want to start to develop your application locally, you can clone the repository you created before. Remember to change your-name with your GitHub username and repo-name with your repository name.

git clone https://github.com/your-name/repo-name.git

Install the dependencies.

composer install

Create a .env file to store your Font Awesome kit URL.

cp .env.example .env

Run the app locally.

php -S localhost:8000

Open in your browser.

localhost:8000/api/index.php

Summary

That's all about how to deploy PHP application to Vercel. If you encounter a problem or want to make a contribution just raise an issue or pull request. Highly recommended if you also read the documentation from Vercel and from Vercel-Community.