Why php include() does read files from a parent directory on Azure ?

Kanishka Withanawasam 0 Reputation points
2023-02-17T17:02:50.5266667+00:00

My php Web app is not reading files correctly on azure. How do I fix this ? The web app correctly works in my computer.

The file directory

mainFolder->common_files (common files have all the files used by all the web pages)

mainFolder->pages (pages will have all the .php files except index.php)

mainFolder-> index.php

The index.php files works correctly. However, the .php files inside the "pages" folder does not go to the common_files folder.

I used the following code to include those files from common_files folder:

(The .php files inside "pages" folder use this code)

<head>
    <?php require('../common_files/headfiles.php') ?>
</head>

The webpage should load files from o:

https://glidingcub.azurewebsites.net/common_files/

But try to load from:

https://glidingcub.azurewebsites.net/pages/common_files/

How do I fix this ?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,495 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ajkuma 28,116 Reputation points Microsoft Employee
    2023-02-23T12:47:02.6766667+00:00

    @Kanishka Withanawasam , Apologies for the delay from over the weekend.

    If you haven’t checked/done this already - By default, Azure App Service points the root virtual application path (/) to the root directory of the deployed application files (sites\wwwroot).

    So, you may instead try to change the path in the required statement to the absolute path of the common_files folder.

     For example:

    <head>
    <?php require('/home/site/wwwroot/mainFolder/common_files/headfiles.php') ?>
    </head>

    I see that you have posted the question on SO, as well. And, it looks like the WebApp is loading fine.

    User's image

    Kindly let us know, I’ll be more than happy to assist you further. Thanks for your patience!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.