Parse HTML as PHP w/ LEMP stack

Posted April 6, 2021 179 views

I installed the LEMP package from the marketplace, and I’d like to host a website that relies on having HTML files parsed as PHP. I can find instrucions for doing this with Apache, but not nginx. Is there an easy way to do this, or should I just start over with a LAMP installation?

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
2 answers

Hi there,

Yes, this is also doable with Nginx as well as Apache.

You need to duplicate the .php location rule and add one for .htm$.

So the configuration will look like this, depending on yuor PHP configuration:

    location ~ \.htm$ {
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;

Hope that this helps.

  • Hi Bobby,

    Thanks, that looks like it’s on the right track, but unfortunately I couldn’t quite get that to work for some reason. I fiddled around with different permutations for quite some time, and eventually decided I’d be more comfortable with a LAMP configuration that I’m more familiar with. I seem to have gotten that working, so I will abandon LEMP for the time being, although I will probably be back at some point for another project.


by Justin Ellingwood
by Mark Drake
This tutorial details the process for installing and configuring the components that constitute a LEMP stack on an Ubuntu 18.04 server, including Nginx, MySQL, and PHP. It also includes instructions for testing that these components can communicate effectively and serve your content correctly.