php code showing in browser rather than rendered html

Beginner level developers may experience this problem when they start learning php. If your php script is displaying on your browser instead of showing output, then you may check the following thing.

1. Make sure that your url not starting like file:///C:/ , This is so funny but sometimes it happens with some developers. Your url pattern must starts with http:// 

2. Check your PHP installation is working properly. This can be done by just open the terminal or command prompt and type php -v and hit enter button. It must return your installed php version like PHP 7.0.0 

3. Confirm that the PHP module is listed and uncommented inside of your Apache’s httpd.conf This should be something like LoadModule php5_module “c:/php/php5apache2_2.dll” in the file. Search for LoadModule php, and confirm that there is no comment (;) in front of it.

4. Confirm that Apache’s httpd.conf file has the PHP MIME type in it. This should be something like AddType application/x-httpd-php .php. This tells Apache to run .php files as PHP. Search for AddType, and then make sure there is an entry for PHP, and that it is uncommented.

5. Confirm your file has the .php extension on it, or whichever extension specified in the MIME definition in point #3, otherwise it will not be executed as PHP.

6. Confirm you are not using short tags in the PHP file ( Make sure you are accessing your file over your webserver using an URL like http://localhost/file.php not via local file access file://localhost/www/file.php
And lastly check the PHP manual for further setup tips.

7. Confirm that you have’t accidentally saved my script in UTF-16 encoding. PHP5 can’t recognize <?php tag in 16 bit encoding by default.

Note for php 7 users, add this to your httpd.conf file:

# PHP 7 specific configuration
<IfModule php7_module>
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    <IfModule dir_module>
        DirectoryIndex index.html index.php