Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bobwurtz's avatar

Vapor Shell Command for External Binary

Hey All,

I am trying to execute a shell command from a Vapor deployment. My attempt looks like:

use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

// ...
$process = Process::fromShellCommandline('/cputil/cputil jsonstatus "$STATUS"');
$process->run(null, ['STATUS' => $request['status']]);

// executes after the command finishes
if (!$process->isSuccessful()) {
  throw new ProcessFailedException($process);
}

I have installed the binary on my local machine and added it's location to my $PATH, and it works locally using $process = Process::fromShellCommandline('cputil jsonstatus "$STATUS"');.

Does anyone know how I would accomplish this in a Vapor deployment? I use a Docker runtime. The folder containing the binary that I need is in the root level of my application. I've tried adding it to my deployment files by using:

FROM laravelphp/vapor:php82

COPY cputil/ /cputil

COPY . /var/task

I've also tried:

$process = Process::fromShellCommandline('/var/task/cputil/cputil jsonstatus "$STATUS"'); without any luck.

0 likes
1 reply
LaryAI's avatar
Level 58

It seems like you're trying to execute a binary within a Laravel Vapor environment using Symfony's Process component. When deploying with Vapor, your application is packaged into a Lambda-compatible format, and the filesystem is mostly read-only, except for the /tmp directory.

Here's a step-by-step solution to ensure your binary is executable within the Vapor environment:

  1. Make sure your binary is compiled for a Linux environment, as AWS Lambda runs on Amazon Linux.

  2. Update your Dockerfile to copy the binary to the /tmp directory, which is writable at runtime:

FROM laravelphp/vapor:php82

# Copy the binary to the /tmp directory
COPY cputil/ /tmp/cputil

# Ensure the binary is executable
RUN chmod +x /tmp/cputil/cputil

COPY . /var/task
  1. Modify your PHP code to use the binary from the /tmp directory:
use Symfony\Component\Process\Process;
use Symfony\Component\Process\Exception\ProcessFailedException;

// ...

// Use the full path to the binary in the /tmp directory
$process = Process::fromShellCommandline('/tmp/cputil/cputil jsonstatus "$STATUS"');
$process->run(null, ['STATUS' => $request['status']]);

// executes after the command finishes
if (!$process->isSuccessful()) {
    throw new ProcessFailedException($process);
}
  1. Ensure that your cputil binary and any dependencies it has are included in your deployment package.

  2. If your binary requires specific system libraries that are not available in the AWS Lambda environment, you may need to compile these libraries statically into your binary or include them in your deployment package.

  3. After making these changes, redeploy your application with Vapor.

Remember that the environment variables and paths in AWS Lambda may differ from your local setup, so always use absolute paths and check that all necessary environment variables are set correctly.

If you continue to face issues, you may want to add logging to your application to capture any error messages or output from the binary execution, which can help in diagnosing the problem.

Please or to participate in this conversation.