Introduction

PHP is a popular server-side scripting language that makes it easy to create dynamic web pages. This guide will help you deploy a simple PHP application.

Prerequisites

  • a UNIX-like system (see WSL if you are using Windows), in order to use the Valyent CLI
  • a Valyent account, with a registered payment method (you can sign up here)
  • PHP installed on your machine

Installing the CLI

curl -L https://cli.valyent.cloud | sh

You can inspect the installation script here and the GitHub repository.

Authenticating

valyent auth login

Initializing the project

First, let’s create a new directory and add our PHP file:

mkdir php-app && cd php-app
touch index.php

In the index.php file, add this simple code:

<?php
echo "Hello, World!";

Now, initialize the valyent.toml configuration file:

valyent init

This command will ask you to select/create a project and an associated application.

Adding the Dockerfile

Create a Dockerfile for the application:

touch Dockerfile

Add the following content:

# Use the official PHP Apache image
FROM php:8.2-apache

# Copy the application files to the web server's document root
COPY . /var/www/html/

# Set appropriate permissions for the document root
RUN chown -R www-data:www-data /var/www/html

# Expose port 80
EXPOSE 80

Deploy the project

To expose the application’s port, we need to set up a gateway (in this case, the port 80):

valyent gateways create

Deploy your application to Valyent:

valyent deploy

Once the deployment is finished, open your application:

valyent open

Your simple PHP application should now display “Hello, World!” in the browser.