Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Azure Web Apps to support PHP in HTML

I am new to Azure and I am testing the Web Apps service.
I have a basic static website with a simple contact form in PHP, but it does not seem to work.
Reading the Azure documentation here has made me feel more lost than before.

I have done some basic testing and it seems that Azure Web Apps support PHP files like this phptest.php

<?php echo "hello world"; ?>

but fail when PHP is integrated with HTML, like this example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
   <HEAD>   
      <TITLE>Use PHP in HTML files</TITLE>  
   </HEAD>  
   <BODY>       
      <h1>
         <?php echo "It works!"; ?>     
      </h1>
   </BODY>
</HTML>

Can someone guide me through this?
What must I configure in my Web App? Do I need to link any dlls?
Thank you!

like image 455
olga Avatar asked Mar 16 '16 13:03

olga


1 Answers

Well, yes, that should work, but the problem for the contact form would remain. I cannot change my index.html file or the additional pages

If you need to use a ".html" file extension for your PHP files so they stay as ".html" within the URL, then you'll need to add a custom Handler Mapping to the Azure Web App so that "*.html" files are handled by the PHP engine. Otherwise, without any Handler Mapping the ".html" files are just served as static resources.

Can someone guide me through this?

As the documentation shows, you need to go into the Azure Portal for the Web App and into "Settings", then "Application Settings". In here you'll see the configuration for the version of PHP that is configured for the Web App. You'll want to make sure this isn't set to "Off" otherwise you wont have PHP turned on. Currently, the default version is sets up is v5.4.

enter image description here

Upon scrolling down to the bottom, you'll see the section for configuring the Handler Mappings. Here is where you need to set the File Extension, and the Path to the PHP engine so you can process ".html" files with PHP. These Handler Mappings are the same as would be configured within IIS, btw.

You want to add a line to the Handler Mappings with the following values, without the quotes of course:

Extension: "*.html"

Processor Path: "D:\Program Files (x86)\PHP\v5.4\php-cgi.exe"

Once saved, this should setup to process ".html" files with the PHP engine. enter image description here

If you have difficulty, you may need to get the correct path for the PHP engine within the Azure Web App. To do this you need to go to the Kudu portal for the Web App. This is accessed by adding ".scm" to the URL of the Web App, right after the Web App name.

For example Kudu is accessed for a Web App with the URL of "http://myapp.azurewebsites.net" from "http://myapp.scm.azurewebsites.net"

Once in Kudu, you'll need to click on the "Environment" option in the header menu, then scroll down to the "PATH" section. Here you'll see the path to the version of PHP the Web App is configured to in the list. Use this value to modify the Processor Path for the Handler Mapping accordingly.

enter image description here

I hope this helps clear up any confusion.

like image 88
Chris Pietschmann Avatar answered Sep 28 '22 20:09

Chris Pietschmann