2

After deploying a Grav CMS (http://getgrav.org) based website to Azure via a Bitbucket repo, I get the message "You do not have permission to view this directory or page." when I try to browse the site. I haven't changed any configuration settings yet.

user2721794
  • 401
  • 1
  • 4
  • 20

2 Answers2

8

As PHP applications running on Azure are hosted on IIS, so your issue occurs due to you haven't configured the URL rewrite mode in IIS.

Try to create a file named web.config in the root directory of your application, with the following content:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <defaultDocument>
            <files>
                <remove value="index.php" />
                <add value="index.php" />
            </files>
        </defaultDocument>
        <rewrite>
            <rules>
                <rule name="request_filename" stopProcessing="true">
                    <match url="." ignoreCase="false" />
                    <conditions logicalGrouping="MatchAll">
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
                    </conditions>
                    <action type="Rewrite" url="index.php" />
                </rule>
                <rule name="user_accounts" stopProcessing="true">
                    <match url="^user/accounts/(.*)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="user_config" stopProcessing="true">
                    <match url="^user/config/(.*)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="user_error_redirect" stopProcessing="true">
                    <match url="^user/(.*)\.(txt|md|html|php|yaml|json|twig|sh|bat)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="cache" stopProcessing="true">
                    <match url="^cache/(.*)" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="bin" stopProcessing="true">
                    <match url="^bin/(.*)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="backup" stopProcessing="true">
                    <match url="^backup/(.*)" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="system" stopProcessing="true">
                    <match url="^system/(.*)\.(txt|md|html|yaml|php|twig|sh|bat)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
                <rule name="vendor" stopProcessing="true">
                    <match url="^vendor/(.*)\.(txt|md|html|yaml|php|twig|sh|bat)$" ignoreCase="false" />
                    <action type="Redirect" url="error" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
    <system.web>
        <httpRuntime requestPathInvalidCharacters="&lt;,&gt;,*,%,&amp;,\,?" />
    </system.web>
</configuration>

And then deploy it with your application to Azure. Also, you can find this config file in the webserver-configs folder in your grav application. Or you can refer to https://github.com/Vivalldi/grav/blob/develop/webserver-configs/web.config at github.

Any further concern, please feel free to let me know.

Gary Liu
  • 13,758
  • 1
  • 17
  • 32
  • I added the web.config file to the root of my application but it still didn't work. I'm following the instructions here. https://getgrav.org/blog/grav-on-azure. NB: Although I have a web.config in the root, there is still another web.config in the webserver-configs folder. – user2721794 Jul 05 '16 at 00:02
  • Do you use your own repository? Is it convenient for you to provide your repository for me to reproduce your issue? – Gary Liu Jul 05 '16 at 01:09
  • I deployed with your repository, and it worked fine on my side at http://garygarv.azurewebsites.net/. please double check if the `web.config` existing on your Azure site. You can use visual studio online extension of your Azure App Service to check and modify your scripts on Azure Web apps. check the answer of http://stackoverflow.com/questions/34780571/visual-studio-2015-and-microsoft-azure-syncing-files-server-local/34782888#34782888 – Gary Liu Jul 05 '16 at 01:53
  • I even created a new app and set the deployment source to the repo and yet, I get a 500 error. I'm really confused as it looks like I'm doing everything I should. I confirmed that the web.config exists in the root via Visual studio online. Are there any special things you did before deploying. Specifically, how did you create the app on azure? – user2721794 Jul 05 '16 at 07:45
  • 1
    If you get a 500 error, not a 403 permission issue, please double check the PHP version. As `Grav` need the PHP version higher than 5.6, please modify the PHP version of your App Service. Please refer to https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/ for details – Gary Liu Jul 05 '16 at 07:53
  • Additionally, you can enable to display errors for troubleshooting, also you can find the solution at https://azure.microsoft.com/en-us/documentation/articles/web-sites-php-configure/ – Gary Liu Jul 05 '16 at 07:54
  • Thank you very much. It was the PHP version that was the problem. I just updated it to 5.6 – user2721794 Jul 05 '16 at 11:21
0

As of March 2018, I found I also needed to install the composer extension in order to get the website to load properly.

See https://learn.microsoft.com/en-gb/azure/app-service/web-sites-php-configure#how-to-enable-composer-automation-in-azure for details.

Without doing this I would see a blank page when trying to load the site.