Skip to main content

Quickstart - Setup

Configure your local development environment to get started developing with Temporal.

Install the PHP

Make sure you have the PHP installed.

If you don't have PHP: Visit official website to download and install it.

GRPC extension

GRPC extension is required to work with RoadRunner application server.

If you don't have ext-grpc installed: Visit official website to download and install it.

php -v

Create a Project

Now that you have your build tool installed, create a project to manage your dependencies and build your Temporal application.

mkdir temporal-hello-world
cd temporal-hello-world
composer init -n

Add Temporal PHP SDK Dependencies

Now add the Temporal SDK dependencies to your project configuration file.

composer require temporal/sdk

Install RoadRunner application server

Install RoadRunner application server. It does lots of things for you, including:

  • managing workflow workers
  • managing activity workers
  • provides GRPC channel to communicate with Temporal Service through Go SDK

See RoadRunner installation instructions to learn about other installation methods.

Download RoadRunner by the following command

./vendor/bin/rr get

Create a simple configuration file named .rr.yaml with the following content:

rpc:
listen: tcp://127.0.0.1:6001

server:
command: "php worker.php"

temporal:
address: "127.0.0.1:7233"

logs:
level: info

Install Temporal CLI and start the development server

The fastest way to get a development version of the Temporal Service running on your local machine is to use Temporal CLI.

Choose your operating system to install Temporal CLI:

Install the Temporal CLI using Homebrew:

brew install temporal

DLoad package manager

Consider using DLoad to delegate all installation and updating processes to the package manager.

Add one more download action to the configuration file

<download software="temporal" version="^1.5"/>

So the final configuration file will looks like the following

<?xml version="1.0"?>
<dload xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/internal/dload/dload.xsd"
temp-dir="./runtime"
>
<actions>
<download software="rr" version="^2025.1.6"/>
<download software="temporal" version="^1.5"/>
</actions>
</dload>

Start the development server

Once you've installed Temporal CLI and added it to your PATH, open a new Terminal window and run the following command.

This command starts a local Temporal Service. It starts the Web UI, creates the default Namespace, and uses an in-memory database.

The Temporal Service will be available on localhost:7233. The Temporal Web UI will be available at http://localhost:8233.

Leave the local Temporal Service running as you work through tutorials and other projects. You can stop the Temporal Service at any time by pressing CTRL+C.

Once you have everything installed, you're ready to build apps with Temporal on your local machine.

After installing, open a new Terminal. Keep this running in the background:

temporal server start-dev

Change the Web UI port

The Temporal Web UI may be on a different port in some examples or tutorials. To change the port for the Web UI, use the --ui-port option when starting the server:

temporal server start-dev --ui-port 8080

The Temporal Web UI will now be available at http://localhost:8080.

Run Hello World: Test Your Installation

Now let's verify your setup is working by creating and running a complete Temporal application with both a Workflow and Activity.

This test will confirm that:

  • The Temporal PHP SDK is properly installed
  • Your local Temporal Service is running
  • You can successfully create and execute Workflows and Activities
  • The communication between components is functioning correctly

1. Create the Activity implementation

Create an Activity implementation file (src/GreetingActivity.php):

<?php
declare(strict_types=1);

namespace App;

use Temporal\Activity\ActivityInterface;
use Temporal\Activity\ActivityMethod;

#[ActivityInterface]
class GreetingActivity
{
#[ActivityMethod]
public function greet(string $name): string
{
return "Hello, $name!";
}
}

An Activity is a method that executes a single, well-defined action (either short or long-running), which often involves interacting with the outside world, such as sending emails, making network requests, writing to a database, or calling an API, which is prone to failure. If an Activity fails, Temporal automatically retries it based on your configuration.

You define Activities in PHP as classes annotated with the Temporal\Activity\ActivityInterface attribute.

Each method used in workflow classes should be annotated with Temporal\Activity\ActivityMethod.

2. Create the Workflow Implementation

Create a Workflow implementation file (src/SayHelloWorkflow.php):

<?php
declare(strict_types=1);

namespace App;

use Temporal\Activity\ActivityOptions;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

#[WorkflowInterface]
class SayHelloWorkflow
{
#[WorkflowMethod]
public function sayHello(string $name)
{
$activity = Workflow::newActivityStub(
GreetingActivity::class,
ActivityOptions::new()
->withStartToCloseTimeout(5),
);

return yield $activity->greet($name);
}
}

3. Create Worker

Create a Worker file (worker.php, under project root directory):

<?php
declare(strict_types=1);

use Temporal\WorkerFactory;

ini_set('display_errors', 'stderr');
require "vendor/autoload.php";

$factory = WorkerFactory::create();

$worker = $factory->newWorker();

// Register Workflows
$worker->registerWorkflowTypes(\App\SayHelloWorkflow::class);
// Register Activities
$worker->registerActivity(\App\GreetingActivity::class);

$factory->run();

4. Run the Worker

Previously, we created a Worker that executes Workflow and Activity tasks.

Now, start the RoadRunner application server to run the Worker:

./rr serve

A Worker polls a Task Queue, that you configure it to poll, looking for work to do. Once the Worker dequeues a Workflow or Activity task from the Task Queue, it then executes the task.

Workers are a crucial part of your Temporal application as they're what actually execute the tasks defined in your Workflows and Activities. For more information on Workers, see Understanding Temporal and a deep dive into Workers.

5. Execute the Workflow

Now that your Worker is running, it's time to start a Workflow Execution.

This final step will validate that everything is working correctly with your file labeled client.php.

Create a separate file called client.php:

<?php
declare(strict_types=1);

use Temporal\Client\GRPC\ServiceClient;
use Temporal\Client\WorkflowClient;

ini_set('display_errors', 'stderr');
require "vendor/autoload.php";

$client = new WorkflowClient(
ServiceClient::create('localhost:7233'),
);

$workflowStub = $client->newWorkflowStub(\App\SayHelloWorkflow::class);
$result = $workflowStub->sayHello('Temporal');

echo "Result: {$result}\n";

While your worker is still running, open a new terminal and run:

php client.php

Verify Success

If everything is working correctly, you should see:

  • Worker processing the workflow and activity
  • Output: Result: Hello, Temporal!
  • Workflow Execution details in the Temporal Web UI

Next: Run your first Temporal Application

Create a basic Workflow and run it with the Temporal PHP SDK