HTML files outside WordPress directory not loading wp-load.php correctly in Local

Hi everyone,

I am having an issue with my Local site structure and hoping someone can help.

My site structure:

/app/public/
├── index.html
├── company/
│   └── index.html
└── wp/
    ├── wp-load.php
    └── (other WordPress files)

The issue:

  • Sites with only /wp/ work fine
  • Plain HTML files (without any PHP) display correctly
  • However, HTML files that contain <?php require('./wp/wp-load.php'); ?> to load WordPress do not work — the PHP is not being processed and WordPress does not load

What I have tried:

  • Router Mode is set to “site domains”
  • I have also tried changing the web server settings:
    • When using nginx, WordPress is not loaded
    • When using Apache, I get a 502 error
  • The site works fine on the production server

Is there a way to configure Local so that PHP is processed in HTML files outside the WordPress directory?

Any help would be appreciated. Thank you!

Hi, @taka! <?php content in .html files doesn’t load by default.

If you change the filename from [name].html to [name].php, does the PHP load correctly? (For example, index.php instead of index.html.)

Thank you for your response! Changing the file extension to .php worked correctly.

However, this method requires me to change all .html files to .php in Local, and then change them back to .html when deploying to the production server, which is a bit inconvenient.

Is there any way to process PHP in .html files without changing the file extension?

Thank you!

Yes, you could modify the nginx and PHP configs to load .html files as PHP:

  1. Click “site folder” for your site that’s using nginx:

  2. Edit the file at confnginxsite.conf.hbs

  3. Replace this line (around line 71):

    	location ~ \.php$ {
    

    With this:

    	location ~ \.(?:php|html?)$ {
    
  4. Edit the file at confphpphp-fpm.dwww.conf.hbs:

  5. Below [www] (line 1), add this:

    security.limit_extensions = .php .html .htm
    
  6. Save your changes to both files.

  7. Stop the site and start it again. (The config changes will not apply until you do this.)

PHP should now load in your local HTML files. You will have to make these changes to any local sites where you want to treat HTML as PHP files. You would also have to modify production servers in a similar way if you haven’t yet. (Most do not load PHP in HTML by default.)

Thank you for the detailed instructions!

I followed the steps, but I noticed that the line location ~ \.php$ { does not exist in my nginx.conf.hbs file. I’ve pasted the full content of the file below — could you let me know what I should look for instead, or where this line might be located in a different format?

error_log "{{logs.errorLog}}";

events {
	worker_connections  1024;
}

http {
	include includes/mime-types.conf;

	server_names_hash_bucket_size 128;

	client_max_body_size 1000M;
	default_type       application/octet-stream;
	access_log         off;
	sendfile           off;
	keepalive_timeout  3;

	fastcgi_buffers 32 32k;
    fastcgi_buffer_size 32k;
    fastcgi_read_timeout 1800s;

	map $http_x_forwarded_proto $resolved_scheme {
        default "http";
        "https" "https";
    }

	map $resolved_scheme $fastcgi_https {
		default '';
		https on;
	}

	include site.conf;
}

Also, I edited the www.conf.hbs file by adding security.limit_extensions = .php .html .htm below [www]. I’ve pasted the full content of this file as well — could you confirm whether this is correct?

{{! This file will not be used on Windows due to PHP-FPM not being available on Windows. }}
[www]
security.limit_extensions = .php .html .htm
listen = "{{phpFpm.socket}}"
pm = static
pm.max_children = 2
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
catch_workers_output = yes

{{! Environment Variables for ImageMagick }}
env[MAGICK_CODER_MODULE_PATH] = "{{imageMagick.codersDir}}"
env[GS_LIB] = "{{imageMagick.ghostscriptLib}}"

Thank you!

Sorry, @taka, the first file you need to edit is confnginxsite.conf.hbs (not nginx.conf.hbs). I edited the steps above with the correct file name.

Your second edited file looks fine.

Thank you for the clarification! I edited site.conf.hbs as instructed and it is now working correctly. The HTML files are now processing PHP as expected.

Thank you so much for your help!