0

这个问题似乎很基础,但我还没有使用过这个场景,所以我会得到一些建议。我正在 LAMP 环境中构建一个带有随附 API 的复杂应用程序。

mydomain.com 将是主要服务和系统的位置。api.mydomain.com 将是我的 API 的所有端点的位置。

所有类文件、数据库配置文件等都将位于主域/根文件夹中。

有推荐的方法来处理这个吗?还是像在 API 端/文件夹中包含所需文件一样简单?

4

2 回答 2

1

As it is on the same server, it should be no problem. You should use absolute paths for including, so for example /web/www/htdocs/config.inc.php instead of ../htdocs/config.inc.php, as it would get really confusing.

It would be the best to have a simple pathConf.inc.php in api directory and root directory, containing this absolute path - so you will be able to easily change it afterwards. Then, use this path configured in pathConf.inc.php and include your classes, db configs etc.

于 2013-09-05T20:50:35.593 回答
1

It all depends on whether api.mydomain.com is on the same server as mydomain.com. If they are, you could allow access to the shared files from both areas by using direct paths. So for example, say you have a structure like this:

/webdata/shared
/webdata/api
/webdata/www

You could simply just do an include like:

include_once('/webdata/shared/config.php');
于 2013-09-05T20:50:52.127 回答