How to put your PHP application in a subdirectory of another site with Nginx

Warning: This post is over a year old. I don't always update old posts with new information, so some of this information may be out of date.

In January, Chris Fidao posted a video to Servers for Hackers showing how to put different PHP applications in different subdirectories and have them serving on different paths with Nginx. I’ve had to do this a few times previously, and it’s great to have this video as a reference.

In this video, we work through how to put your PHP application in a subdirectory of another site.

For example, we may have an application running at example.org but need a second application running at example.org/blog.

This feels like it should be simple, but it turns out to be more complex and fraught with confusing Nginx configurations! To make matter worse (or, perhaps, to illustrate this point), a quick Google search reveals a TON of confusing, non-working examples.

https://serversforhackers.com/c/nginx-php-in-subdirectory

Questions? Comments? I’m @opdavies on Twitter.

Tags

About the Author

Picture of Oliver

Oliver Davies is a Full Stack Web Developer and System Administrator based in the UK. He is a Senior Software Engineer at Inviqa and a part-time freelancer specialising in Drupal, Symfony and Laravel development and Linux systems administration.