How to do this - on a Pi 

I made this all work on a Pi3 - and here's how.  For the purpose of this demonstration I am not going to discuss the details.  Highlights.

I copied the code from my web server to a Pi installed a web server and PHP on the Pi and tried to run it.  It failed.  It turns out, after an hour or so of debugging JavaScript, that some time between 2015 and now both Chrome and Firefox decided that in order to allow location data from an HTML request the request must be from an HTTPS (secure) site. So:

Install a web server, php and ssl on my PI

apt install apache2 php ssl

Test that I can serve a web page and php by creating:

index.html:
<html><head></head><body>
<h2>Hello World</h2>
</body><html>
index.php
<?php
print "Hello World";

Request index.html and index.php from a web browser

Hello World

and

Hello World

Not exciting and it shows that the web server and PHP are working

Configure apache

I wanted to move the default location for html documents from /var/www/html to /home/pi/www/html just to make it easier to mess with files in the pi home directory.

<Directory /home/pi/www/html/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

This gives permissions for this directory.
DocumentRoot /var/www/html
to
DocumentRoot /home/pi/www/html

Install the code

Enable SSL

We need to enable SSL because, remember, location will not work unless the requester is https.  Hence the install of openssl above

sudo openssl req -new -x509 -days 365 -nodes -out /etc/ssl/localcerts/apache.pem -keyout /etc/ssl/localcerts/apache.key

Add the following after the existing VirtualHost section for port 80

<VirtualHost *:443>
    ServerAdmin webmaster@localhost
    DocumentRoot /home/pi/www/html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    SSLEngine on
    SSLProtocol all -SSLv2
    SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5
    SSLCertificateFile "/etc/ssl/localcerts/apache.pem"
    SSLCertificateKeyFile "/etc/ssl/localcerts/apache.key"
</VirtualHost>

sudo a2enmod ssl
This creates the following links in /etc/apache2/mods-enabled
lrwxrwxrwx 1 root root   26 Jan 16 15:38 ssl.conf -> ../mods-available/ssl.conf:
lrwxrwxrwx 1 root root   26 Jan 16 15:38 ssl.load -> ../mods-available/ssl.load

Restart the apache server:

systemctl restart apache2.service