Enable php module for Apache2 on high sierra

It is doubtless a chore to install and configure all necessary software after an OS reinstall or switching to a new computer,especially when you need to set up a web environment for development. Yet it is an opportunity to acquaint oneself with the basic configuration of various web server components.  I'd make a point of noting down the procedure of enabing the php module for apache2.

    When I entered the web url in the browser, the output of the index.php is outputted, which indicated that php module for httpd server was not activated. To make apache2 execute php file, you are required to install php mod first, and then activate it explicitly, since it is not enabled by default. here is the step-by-step guide.

   Go to /etc/apache2 and open httpd.conf. search the file for the keyword php and you will find a line starting with Load and ending with libphp.so. remove hash symbol that set the module inactive.

   then add a new line

  Include /etc/apache2/extra/httpd-php.conf

 paste the following code into httpd-php.conf and save it

<FilesMatch ".+\.ph(p[345]?|t|tml)$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch ".+\.phps$">
    SetHandler application/x-httpd-php-source
    # Deny access to raw php sources by default
    # To re-enable it's recommended to enable access to the files
    # only in specific virtual host or directory
    Order Deny,Allow
    Deny from all
</FilesMatch>
# Deny access to files without filename (e.g. '.php')
<FilesMatch "^\.ph(p[345]?|t|tml|ps)$">
    Order Deny,Allow
    Deny from all
</FilesMatch>

# Running PHP scripts in user directories is disabled by default
#
# To re-enable PHP in user directories comment the following lines
# (from <IfModule ...> to </IfModule>.) Do NOT set it to On as it
# prevents .htaccess files from disabling it.
<IfModule mod_userdir.c>
    <Directory /home/*/public_html>
        php_admin_flag engine Off
    </Directory>
</IfModule>

Finally, restart httpd and it should be working.