要在Apache Web服务器上运行Zend Expressive API,您需要进行以下步骤:
- 确保您已经安装了Apache Web服务器,并且已经配置好了PHP。
- 在您的项目根目录中创建一个
.htaccess
文件,并将以下代码添加到文件中:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]
这将确保所有的请求都被重定向到index.php
文件。
- 在您的项目根目录中创建一个
index.php
文件,并将以下代码添加到文件中:
<?php
declare(strict_types=1);
chdir(dirname(__DIR__));
require 'vendor/autoload.php';
$app = Zend\Expressive\AppFactory::create();
// 添加您的路由和处理程序代码
$app->get('/', function ($request, $response, $next) {
$response->getBody()->write('Hello, World!');
return $response;
});
$app->run();
在这个示例中,我们添加了一个简单的路由,当请求根路径时,返回"Hello, World!"。
- 确保您已经安装了Zend Expressive API的依赖项。在您的项目根目录中运行以下命令:
composer require zendframework/zend-expressive
- 确保您已经将您的项目文件放置在Apache Web服务器的适当目录下,并且已经启动了服务器。
现在,您可以通过访问http://localhost
来测试您的Zend Expressive API了。您应该看到一个包含"Hello, World!"的页面。