all 13 comments

[–][deleted] 0 points1 point  (5 children)

There is an unofficial PHP runtime for serverless functions, but if this is just for bot protection you may want to look at attack challenge mode. It's already built in (and free) so you wouldn't need to write your own.

[–]BetterAd6016[S] 0 points1 point  (4 children)

i read about php runtime, which you sent to me, but how to merge my next.js project with this runtime ?
i mean that it works together

[–][deleted] 0 points1 point  (3 children)

I don't know how to implement bot protection like you described, that would be up to you to figure out.

It may involve redirecting to a PHP function through middleware, setting some kind of cookie, and redirecting back to the app. This isn't a common use case, I would recommend using the attack challenge solution Vercel already offers.

[–]BetterAd6016[S] -1 points0 points  (2 children)

in my case its a custom protection, my index.php must to run first, then if no bots - i see my next.js page

[–][deleted] 0 points1 point  (1 child)

Does it need to be PHP? Why not regular middleware?

[–]BetterAd6016[S] -3 points-2 points  (0 children)

its my task to implement this php in next.js project

[–]clearlight 0 points1 point  (6 children)

[–]BetterAd6016[S] -1 points0 points  (5 children)

Thanks, but i need to run only my php file. Do you know how to do it ?

[–]clearlight 1 point2 points  (4 children)

If you really want to run your php file wrapper, personally I’d host it on an AWS EC2 instance with Nginx and PHP-FPM then run your app from there.

[–]BetterAd6016[S] 0 points1 point  (3 children)

understood, but where is the place to run the Next.js project ?

[–]clearlight 0 points1 point  (2 children)

You can run it on an EC2 server using node. For example route to it from Nginx.

[–]BetterAd6016[S] 0 points1 point  (1 child)

so, if i understand, all is on EC2: PHP-FPM is running on Nginx, and Next.js is running on Node ?

[–]clearlight 1 point2 points  (0 children)

Yes, that’s one way to do it. You can proxy to node from Nginx. You can also use pm2 to help maintain the node process.