0

This question seems really elementary, but I have never had a use for the scenario as of yet, so figure I will get some advice. I am building a complex application with an accompanying API in a LAMP environment.

mydomain.com will be the location of the main service and system. api.mydomain.com will be the location of all endpoints for my API.

All of the class files, DB config files, etc, will be located at main domain/root folder.

Is there a recommended way to handle this? Or is it as simple as including the required files on the API side/folder?

Chris
  • 4,762
  • 3
  • 44
  • 79
  • if you have a folder named api for example in the main folder,you can include files directly using relative path of this folder – Charaf JRA Sep 05 '13 at 20:50
  • If it were me I would put the files in a special folder outside the Document Root. For example instead of \var\www\html I would put them in \var\www\php then adjust my HTTPD config accordingly. http://stackoverflow.com/questions/2370053/how-to-include-file-outside-document-root – Lumberjack Sep 05 '13 at 20:54

2 Answers2

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.

PDev
  • 1,472
  • 1
  • 10
  • 12
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');
fanfavorite
  • 5,128
  • 1
  • 31
  • 58