PHP

This article includes examples of how to set up the following PHP applications to deploy on Kinsta’s Application Hosting services from a GitHub repository:

Prerequisites

  • Kinsta’s quick start templates are stored and managed in GitHub; therefore, you need a GitHub account to access them.
  • You need to create a MyKinsta account to deploy the application.

PHP

  1. Log in to GitHub and create a new repository from this template (Use this template > Create a new repository): Kinsta – Hello World – PHP.
  2. In MyKinsta, click Applications > Add application > select GitHub, click Connect git provider > Authorize, and log in to your GitHub account.
  3. Choose the Hello World PHP repository and a Data center location. Leave all other settings as default and click Continue on each step.
  4. On the Summary step, click Deploy now.

During deployment, Kinsta automatically detects the Start command for the web process and installs dependencies defined in your composer.json file. The app is available as soon as the deployment finishes, and the Kinsta Welcome page loads at your application’s URL.

Kinsta Welcome page after successful deployment of PHP.
Kinsta Welcome page after successful deployment of PHP.

Prefer to watch the video version?

Web Server Setup

Kinsta automatically configures an Apache web server that serves your index.php file from the main directory of the project in the usual fashion. Create an index.php file in your project folder as your default index page.

Jigsaw

This is an example of how to set up a static site with Jigsaw on Kinsta’s Application Hosting services from a GitHub repository.

Jigsaw is a static site framework that uses Blade templates to create your page layouts and Markdown to build your content within the templates so you can produce simple static sites without complex coding knowledge. More information is available on the Jigsaw website.

  1. Log in to GitHub and create a new repository from this template (Use this template > Create a new repository): Kinsta – Jigsaw Starter.
  2. In MyKinsta, click Applications > Add application > select GitHub, click Connect git provider > Authorize, and log in to your GitHub account.
  3. Choose the Jigsaw Starter repository and a Data center location. Leave all other settings as default and click Continue on each step.
  4. On the Summary step, as you must add the necessary Buildpacks before deploying, click Deploy later.
  5. So that the application can build the CSS/JS files, you need to add two buildpacks: Node.js and PHP. Click Settings > Add buildpack, select Node.js > Add buildpack. Repeat this for PHP.
  6. Click Deployments > Deploy now > choose the required branch > Deploy application.

Jigsaw is based on Laravel; it’s a regular PHP-based application, so during deployment, Kinsta automatically detects the Start command for the web process and installs dependencies defined in your composer.json file. The app is available as soon as the deployment finishes, and a default Jigsaw page loads at your application’s URL.

Jigsaw default page after successful installation.
Jigsaw default page after successful installation.

Buildpacks

In most cases, you’ll want the application to build the CSS/JS files, so you’ll need to add these two Buildpacks:

  • Node JS
  • PHP

Web Server Setup

Start Command

When you deploy the application, Kinsta automatically creates a web process with npm start as the Start command. If required, you can change this within Processes.

Laravel

This is an example of how to set up a Laravel application to deploy on Kinsta’s Application Hosting services from a GitHub repository.

  1. Log in to GitHub and create a new repository from this template (Use this template > Create a new repository): Kinsta – Hello World – Laravel.
  2. Laravel requires the APP_KEYenvironment variable to be set. You can generate an app key yourself locally, or you can use this online Laravel key generator.
  3. In MyKinsta, click Applications > Add application > select GitHub, click Connect git provider > Authorize, and log in to your GitHub account.
  4. Choose the Hello World Laravel repository and a Data center location. In Environment variables, in Key 1, enter APP_KEY, and in Value 1, paste the key generated from Step 2, select Available during runtime and Available during build process.
  5. Leave all other settings as default and click Continue on each step. On the Summary step, click Deploy later to add the necessary Buildpacks before deploying.
  6. So that the application can build the CSS/JS files, you need to add two buildpacks: Node.js and PHP. Click Settings > Add buildpack, select Node.js > Add buildpack. Repeat this for PHP.
  7. Click Deployments > Deploy now > choose the required branch > Deploy application.

Laravel is a regular PHP-based application, so during deployment, Kinsta automatically detects the Start command for the web process and installs dependencies defined in your composer.json file. The app is available as soon as the deployment finishes, and a default Jigsaw page loads at your application’s URL.

Kinsta Welcome page after successful deployment of Laravel.
Kinsta Welcome page after successful deployment of Laravel.

Prefer to watch the video version?

Connect a Database

If you want to connect your application to a database, start by creating a database in the same data center your application is in.

  1. Add a database.
  2. Connect the database to the application by adding an internal connection and selecting the Add environment variables… checkbox. This will automatically populate the environment variables from the database.
  3. Some of the variable names (keys) Laravel uses are different from the ones automatically created in MyKinsta. Edit the variable keys as needed to match the variable names defined in Laravel’s database.php file. Below are the corresponding variable names (keys) for the database types Laravel supports.

Environment Variables

MySQL and PostgreSQL

Automatically Generated KeyLaravel Key
DB_HOSTDB_HOST
DB_PORTDB_PORT
DB_NAMEDB_DATABASE
DB_USERDB_USERNAME
DB_PASSWORDDB_PASSWORD
DB_CONNECTION_URLDB_URL

Redis

Automatically Generated KeyLaravel Key
DB_HOSTREDIS_HOST
DB_PORTREDIS_PORT
DB_NAMEREDIS_DB
DB_USERREDIS_USERNAME
DB_PASSWORDREDIS_PASSWORD
DB_CONNECTION_URLREDIS_URL

Laravel APP_KEY

Laravel requires the APP_KEY environment variable to be set. If this key is not set, you will see a 500 error page served by Laravel. You can generate an app key yourself locally, or you can use the online Laravel key generator. Once you have a key, you can add it as an environment variable.

Buildpacks

In most cases, you’ll want the application to build the CSS/JS files, so you’ll need to add these two Buildpacks:

  • Node.js
  • PHP

The buildpack that contains the primary language of your application must be the last one in the buildpacks list. In this example, PHP is the primary language and should be the last buildpack in the list.

Web Server Setup

Start Command

The default web process is heroku-php-apache2. This example includes an .htaccess file that reroutes all requests to public/index.php for Laravel. If needed, you can change this command when adding your application (Set up your processes) or on the application’s Processes page after deployment. You can use:

heroku-php-apache2 /public

or

php artisan serve --host 0.0.0.0 --port 8080

Leaf

This is an example of how to set up a Leaf PHP application to deploy on Kinsta’s Application Hosting services from a GitHub repository.

Leaf is a slim and lightweight PHP framework focused on developer experience, usability, and high-performance code. More information is available on the Leaf PHP website.

  1. Log in to GitHub and create a new repository from this template (Use this template > Create a new repository): Kinsta – Hello World – Leaf PHP.
  2. In MyKinsta, click Applications > Add application > select GitHub, click Connect git provider > Authorize, and log in to your GitHub account.
  3. Choose the Hello World – Leaf PHP repository and a Data center location. Leave all other settings as default and click Continue on each step.
  4. On the Summary step, click Deploy now.

During deployment, Kinsta automatically detects the Start command for the web process and installs dependencies defined in your composer.json file. The app is available as soon as the deployment finishes, and the Kinsta Welcome page loads at your application’s URL.

Kinsta Welcome page after successful installation of Leaf PHP.
Kinsta Welcome page after successful installation of Leaf PHP.

Prefer to watch the video version?

Web Server Setup

Port

Kinsta automatically sets the PORT environment variable. You should not define it yourself, and you should not hard-code it into the application.

Start Command

When deploying the application, Kinsta automatically creates a web process running heroku-php-apache2.

Deployment Lifecycle

Whenever a deployment is initiated (through creating an application or redeploying due to an incoming commit), the composer install command is run.

Statamic

This is an example of how to set up a Statamic application to deploy on Kinsta’s Application Hosting services from a GitHub repository.

Statamic is a flat-file CMS that, by default, stores all the data in the Git repository. Before you push the code to MyKinsta, installing Statamic locally is the recommended approach for creating and maintaining your site. Next, create a super user account, and then commit and push all the changes to the repository.

  1. Log in to GitHub and create a new repository from this template (Use this template > Create a new repository): Kinsta – Statamic Boilerplate.
  2. Statamic is based on Laravel, so the APP_KEY environment variable must be set. You can generate an app key yourself locally, or you can use this online Laravel key generator.
  3. In MyKinsta, click Applications > Add application > select GitHub, click Connect git provider > Authorize, and log in to your GitHub account.
  4. Choose the Statamic Starter repository and a Data center location. In Environment variables:
    1. In Key 1, enter APP_KEY, and in Value 1, paste the key generated from Step 2.
    2. Click Add another and in Key 2, enter APP_KINSTA, and in Value 2, enter true.
    3. Select Available during runtime and Available during build process.
  5. Leave all other settings as default and click Continue on each step. On the Summary step, click Deploy later to add the necessary Buildpacks before deploying.
  6. So that the application can build the CSS/JS files, you need to add two buildpacks: Node.js and PHP. Click Settings > Add buildpack, select Node.js > Add buildpack. Repeat this for PHP.
  7. Click Deployments > Deploy now > choose the required branch > Deploy application.

Statamic is based on Laravel; it’s a regular PHP-based application, so during deployment, Kinsta automatically detects the Start command for the web process and installs dependencies defined in your composer.json file. The app is available as soon as the deployment finishes, and the Statamic Welcome page loads at your application’s URL.

Statamic welcome page after successful installation.
Statamic welcome page after successful installation.

Prefer to watch the video version?

Environment Variables

Statamic requires the following environment variables to be set:

Buildpacks

In most cases, you’ll want the application to build the CSS/JS files, so you’ll need to add these two Buildpacks:

  • Node.js
  • PHP

The buildpack that contains the primary language of your application must be the last one in the buildpacks list. In this example, PHP is the primary language and should be the last buildpack in the list.

Web Server Setup

Start Command

The default web process is heroku-php-apache2 public/. If needed, you can change this command when adding your application (Set up your processes) or on the application’s Processes page after deployment.

PHP To Send Emails

This is an example of how to set up a PHP application to send emails via SendGrid on Kinsta’s Application Hosting services, deployed from a GitHub repository.

Kinsta does not natively support outbound emails from servers. Sending emails through specialized outbound providers such as SendGrid or Mailchimp offers more flexibility and higher success rates for transactional and campaign emails.

  1. Log in to GitHub and create a new repository from this template (Use this template > Create a new repository): Kinsta – Hello World – Email Sending With PHP.
  2. In MyKinsta, click Applications > Add application > select GitHub, click Connect git provider > Authorize, and log in to your GitHub account.
  3. Choose the Hello World Email PHP repository and a Data center location. In Environment variables, add the following:
    • SENDGRID_API_KEY: The API key from SendGrid.
    • TEST_EMAIL_TO_ADDRESS: The address to send the test email to.
    • TEST_EMAIL_FROM_ADDRESS: The address to send the test email from.
    • TEST_ENDPOINT: The endpoint to use as a trigger to send the test email. Please use a random string of at least 8 characters.
  4. Leave all other settings as default and click Continue on each step. On the Summary step, click Deploy now.

The app is available as soon as the deployment finishes, and a Hello World page loads at your application’s URL.

PHP email sending Hello World page after successful installation.
PHP email sending Hello World page after successful installation.

Trigger an Email

Through a very simple index.php entrypoint, two endpoints are exposed; all others will return a 404:

  • /: A simple page that returns the Hello World message
  • /${TEST_ENDPOINT}: A page that triggers a test email.

To trigger an email, find the URL of your deployment on the Deployments page, append your test endpoint to this URL, and visit the page. For example, if your TEST_ENDPOINT is set to o34nifnodhni4of and your latest deployment is at https://example.kinsta.app, you can trigger a test email from https://example.kinsta.app/o34nifnodhni4of in your browser.

Was this article helpful?