PHP scripts can be embedded in a (X)HTML document or written separately without any (X)HTML markup. In both cases, the file must be saved with the extension .php.
Creating PHP Script
Any PHP script (code) must be enclosed within the PHP tags which are represented using <?php (opening tag) and ?> (closing tag). Let’s consider a simple PHP script which prints “Hello World” on the web document:
print "Hello World";
Save the above file as hello.php.
Running PHP Script
To run a PHP script, a web server must be installed and started. Well known web servers are Apache Http Server and Microsoft’s Internet Information Service (IIS).
After a web server is installed, place the PHP file hello.php in the web server’s root directory and start the web server. Now, open a web browser like chrome, firefox or internet explorer and type the following URL in the address bar:
80 is the port at which the web server listens for incoming HTTP requests. The output of the PHP script is:
Watch the below video tutorial for creating and running a PHP script