How to Preview a PHP File
Unlike HTML files, PHP files require you to have a PHP server running on your computer to view PHP files locally. As a scripting language, it needs to be interpreted by a web server with a PHP processor module before browsers can render the file's contents. To preview PHP files, you will need to install a PHP server such as Apache. Alternatively, uploading it to a PHP web hosting account will let you preview the file.
Previewing a PHP File Using an Apache Web Server
Install a PHP web server on your computer. PHP web servers such as Apache are available for free download (see Resources).
Copy your PHP file to the default folder for web files on Apache. For most Apache installations, this can be found at "C:\Program Files\Apache Group\Apache2\htdocs."
Open your browser and type in "localhost/yourPHPfile.php" in the address bar. Replace "yourPHPfile" with the name of your PHP file to preview it on your browser.
Previewing a PHP File on the Web
Sign up for a PHP web host. Choose one from a list of free PHP web hosting services available on the Internet (see Resources).
Upload your PHP file to the web host. Log in to your new PHP web hosting account and, using its online File Manager feature, upload your PHP file.
Enter the URL where your file is located. For example, if your assigned URL is "myacount.freephpwebhost.com" and you uploaded the file named "myPHPfile.php" to the "public_html" directory of your web host, the URL to view your file will be "myaccount.freephpwebhost.com/myPHPfile.php."