How to set default documents for Azure App service(Linux running PHP)

Prasanth Elumalai 1 Reputation point
2021-02-02T14:41:41.787+00:00

We have an azure app service of Linux environment. And we are trying to use Azure pipelines to deploy the application to app service.
Initially the app was loading the default document - hostingstart.html.
After the deployment, we are getting the response "This page isn’t working right now"

I'd like to verify where to see the default document setting mentioned. It should be index.php in our case.
The app is not showing 400/404 error but it responds with 500 error code

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,045 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. brtrach-MSFT 15,356 Reputation points Microsoft Employee
    2021-02-06T06:19:48.913+00:00

    @Prasanth Elumalai

    We’ll need to check the directory structure of the PHP app to see why it isn’t starting.

    1. Go to KuduLite and select WebSSH
    2. Change directories to "home/site/wwwroot" and list the contents
      root@e157e0a1aec8:/home# cd /home/site/wwwroot
      
      root@e157e0a1aec8:/home/site/wwwroot# ls –ltra
      
    3. The hostingstart.html file is still there and there is no index.php file in the root directory.
    4. Depending on the PHP framework being used, the default document will be in certain locations. For Symfony, the index.php is under “public”.
    5. Go to https://<sitename>.azurewebsites.net/public.
    6. The site is there but it’s not formatted correctly.

    Resolution

    • To resolve the issue, we’ll need to create rewrite rules to use the “public” directory when the site is reached. C
    • Create a “.htaccess” file using the following steps.
    • Using WebSSH, go to /home/site/wwwroot, type “vi .htaccess”.
    • In the vi editor, press “i” to begin writing.
    • Add the following. You can copy and paste but make sure to right click in the SSH window to paste.
       RewriteEngine on
       RewriteCond %{REQUEST_URI} !^public
       RewriteRule ^(.*)$ public/$1 [L]
      
    • To save, press “ESC” then “:” and finally “wq!” and press ENTER.
    • Go back to https://<sitename>.azurewebsites.net and you’ll see the site appear as it should. No need to restart.
    1 person found this answer helpful.

  2. Takahito Iwasa 4,841 Reputation points MVP
    2021-09-19T14:04:50.957+00:00

    Hi

    In case of PHP7.4 or less, it can be controlled by htaccess as brtrach says.
    If you have PHP 8.0, it will run on Nginx instead of Apache, so you need to prepare a startup script to modify the config.

    I've verified something similar before and put it on my blog.
    https://dev.classmethod.jp/articles/app-service-linux-php-default-document/

    I hope it helps you.

    1 person found this answer helpful.