如何部署纯 PHP 站点(未使用框架)

How do I deploy plain PHP site (no framework used)

用 vanilla PHP 和 Js 写了一个包含大约 5 个文件的小项目。这意味着我没有 composer.json & 没有 .htaccess 文件,没有数据库。只是对脚本的 POST 请求 (php).

尝试在 Heroku 上部署但不能。得到以下错误

-----> Building on the Heroku-20 stack
-----> Using buildpack: heroku/php
-----> App not compatible with buildpack: https://buildpack- 
registry.s3.amazonaws.com/buildpacks/heroku/php.tgz
       
!     ERROR: Application not supported by this buildpack!
!     
!     The 'heroku/php' buildpack is set on this application, but was
!     unable to detect a PHP codebase.
!     
!     A PHP app on Heroku requires a 'composer.json' at the root of
!     the directory structure, or an 'index.php' for legacy behavior.
!     
!     If you are trying to deploy a PHP application, ensure that one
!     of these files is present at the top level directory.
!     
!     If you are trying to deploy an application written in another
!     language, you need to change the list of buildpacks set on your
!     Heroku app using the 'heroku buildpacks' command.
!     
!     For more information, refer to the following documentation:
!     https://devcenter.heroku.com/articles/buildpacks
!     https://devcenter.heroku.com/articles/php-support#activation
      More info: https://devcenter.heroku.com/articles/buildpacks#detection-failure
!     Push failed

如错误消息所述,您必须在项目的根目录中有一个 composer.json¹。

如果您没有任何依赖项,it can be empty:

{}

添加该文件,提交并重新部署。


¹或“遗留行为”的 index.php,但谁想要那样?