question

PrasanthElumalai-4929 avatar image
0 Votes"
PrasanthElumalai-4929 asked TakahitoIwasa answered

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

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-webapps
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

brtrachMSFT-0711 avatar image
0 Votes"
brtrachMSFT-0711 answered

@PrasanthElumalai-4929

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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TakahitoIwasa avatar image
0 Votes"
TakahitoIwasa answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.