php icon indicating copy to clipboard operation
php copied to clipboard

downloaded index.php instead of load the app

Open reregin opened this issue 1 year ago • 15 comments

hi, i'm a total beginner and i want to deploy my laravel app on vercel. i was planning to connect it to Oracle ATP to use it as the database. but i'm totally stuck on the vercel. when i open the website, it downloaded the index.php instead of load the app.

this is how my project looks like

project
├── .vercel
│   ├── ...
├── .vercelignore
├── api
│   └── index.php
...
├── public
│   ├── .htaccess
│   ├── favicon.ico
│   ├── index.php
│   └── robots.txt
...
├── vercel.json
└── vite.config.js

i already included functions and routes on my vercel.json like this:

"functions": {
        "api/*.php": {
            "runtime": "[email protected]"
        }
    },
    "routes": [
        {
          "src": "/(.*)",
          "dest": "/api/index.php"
        }
    ],

and i point the /api/index.php to my original index.php like this:

<?php

// Forward Vercel requests to normal index.php
require __DIR__ . '/../public/index.php';

but it just downloaded the /api/index.php instead. do anyone has any ideas what happened? and are they more informations that i could give to help?

reregin avatar Dec 12 '23 23:12 reregin

it's seems like the htaccess issue, have you tried to remove the htaccess firest?

DmitryAdam avatar Dec 13 '23 07:12 DmitryAdam

what do you mean by htaccess firest?

reregin avatar Dec 13 '23 19:12 reregin

I have this same issue for vanilla PHP with no build or framework. I don't know what to do again. In my case, I don't have any .htaccess file

vercel.json

{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]"
    }
  }
}

api/index.php

<?php

// Forward Vercel requests to normal index.php
require __DIR__ . '../index.php';

Here is my project structure

project
└── api
     └── index.php
└── css
└── fonts
└── images
└── js
└── index.php
└── other_php_pages.php
└── vercel.json

solamichealolawale avatar Feb 09 '24 12:02 solamichealolawale

@solamichealolawale Can you show me repository and public vercel URL?

f3l1x avatar Feb 09 '24 13:02 f3l1x

@f3l1x sure.

Repo:https://github.com/solamichealolawale/payit URL: https://payit-chi.vercel.app/

@f3l1x Can you view this?

solamichealolawale avatar Feb 21 '24 07:02 solamichealolawale

I was fixing other bug, now it's time for your app. :-)

f3l1x avatar Feb 25 '24 17:02 f3l1x

bump, bug still occurring with Laravel and PHP runtimes 0.7.0 & 0.6.1

moghwan avatar Mar 21 '24 01:03 moghwan

fixed on my end, at vercel level I've set output directory value to api .

moghwan avatar Mar 21 '24 12:03 moghwan

I was fixing other bug, now it's time for your app. :-)

@f3l1x any update on this?

solamichealolawale avatar Mar 21 '24 20:03 solamichealolawale

i have the same face

lukman-fun avatar Jun 22 '24 17:06 lukman-fun

Everything is ok. You just need to deploy it to production. vercel --prod

mrezayusufy avatar Jun 28 '24 19:06 mrezayusufy

Move all .php files to /api and update vercel.json:

vercel.json

{
  "functions": {
    "api/*.php": {
      "runtime": "[email protected]"
    }
  },
  "rewrites": [
    { "source": "/api/(.*)", "destination": "/api/$1" }
  ]
}

project structure:

project
└── api
     └── index.php
     └── other_php_pages.php
└── css
└── fonts
└── images
└── js
└── vercel.json

sekedus avatar Jul 23 '24 12:07 sekedus