[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live)

[Help](/c/help/9)

# Error Trying to run PHP in vercel

180 views · 0 likes · 2 posts


Kaue10166 (@kaue10166) · 2024-08-26

I'm trying to run a simple PHP code in Vercel (PHP is in the folder 'api'), it opens the HTML code but when it calls the index.php give me the error:

PHP Built-In Server HTTP error: Error: connect ECONNREFUSED 127.0.0.1:8000

my html : 

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Testando php no vercel</title>
</head>
<body>
    <h1>Bem vindo ao meu site</h1>
    <br>
    <!--POST envia os dados, action diz para onde os dados serão enviados-->
    <form method="POST" action="/api/index.php">
        <label for="nome">Digite seu nome: </label>
        <input type="text" id="nome" name="nome" required>
        <!--REQUIRED garante que um input sera enviado, caso contrario imprimira uma msg de erro-->
        <button type="submit">Enviar</button>
    </form>
</body>
</html> 

my PHP:

<?php
  // Verifica se o nome foi enviado via POST
  if (isset($_POST['nome'])) {
      $nome = $_POST['nome'];
      echo "<h1>Bem-vindo ao meu site, $nome!</h1>";
  } else {
      header("Location: /index.html");
      exit();
  }

my vercel.json: 

{
  "functions": {
    "api/index.php": {
      "runtime": "vercel-php@0.7.1"
    }
  },
  "routes": [
    {
      "src": "/api/index.php",
      "dest": "/api/index.php"
    },
    {
      "src": "/(.*)",
      "dest": "/index.html"
    }
  ]
}


Pauline P. Narvas (@pawlean) · 2024-08-27

Hi, @kaue10166!

There is a Vercel Community PHP repo you use to check the set-up and compare with yours :smile: 
https://github.com/vercel-community/php

Otherwise, feel free to create a [minimal reproducible example](https://vercel.com/guides/creating-a-minimal-reproducible-example) for us to dig deeper!