Search code examples
phpapisubdomainlamp

Sub Domain utilizing same application files as root (using PHP)


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?


Solution

  • 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');