How to deploy Laravel 9 on VPS Plesk?

In this article, we will learn to deploy Laravel 9 applications on VPS (Virtual Private Server) Plesk. Deploying the Laravel application on the server looks challenging but in reality, it is easy. Let’s start it.

Is your Laravel application ready to deploy? OR did you already install the Laravel application on a local server? Well here is an article that will help you to install a fresh Laravel application on Windows.

Steps to deploy Laravel 9 on VPS Plesk

Following are steps that need to follow for deploying Laravel 9 on VPS Plesk.

  • Create and Integrate Github Repository
  • Pull commit from Respotory and Deploy to Server

Create and Integrate Github Repository

Plesk has a feature that is integrated with GitHub which performs different tasks between Plesk and Github. It has an interface that adds git to the server. Before adding git into the server make sure that the Laravel application is added to the GitHub repository. Let’s create a repository and upload the Laravel application.

Create an account on github.com or sign in if you have it already. Click on a new button located on the left sidebar of the dashboard page which leads you to create a repository page. Next, create a new repository and upload the Laravel application to it.

Once it is done, go to the Plesk sign-in and click on the Dashboard tab. In the tab, on the right side under the Dev Tools heading click on Git which will lead you to a new page. Further, click on Add Repository button and provide the repository link.

Also, it will ask you to provide a personal access token. To get a personal access token to go to github.com and click on the right side profile picture and then click setting. On the setting, page click on Developer settings and Personal access token. You need to generate a new personal access token so to generate a new token Github might ask you to provide the password for authenticity.

Next, copy and paste the personal access token into Plesk’s Github integration interface. Now, git is enabled and you can see “enabled” text under Git.

Pull commit from Respotory and Deploy to Server

Next, when you click on Git it will lead you to a page where  Plesk provides two features.

1 – Pull Now

This feature fetches branches from the repository and shows them in a drop-down. You can choose any branch if you have multiple and pull the last commit. It also shows the last fetched commit from the branch. So click on pull now to pull all the code from the repository.

2 – Deploy Now

This simply deploys the latest fetched commit into the server. Click the deploy now button to deploy the Laravel application on the server.

It is almost done, the last step is to create index.php in the root and copy and paste all the code from server.php. Next, move or copy the .htaccess file from the public directory to the root.

After making these changes, you are done and the Laravel application should run on the pointed domain.