phpapachemod-php

Unable to link Apache and PHP for execution of PHP files


I'm currently facing an issue with linking Apache and PHP on a Windows system. Here's the problem I'm encountering:

I downloaded the PHP ZIP package from https://www.php.net/downloads.php and extracted it to the "php" folder on my C: drive. Then, I downloaded Apache HTTP Server from https://httpd.apache.org and installed it. I added the PHP installation directory to the system's PATH environment variable. However, I'm unable to find the specific PHP module file to link Apache with PHP in the extracted PHP folder. Additionally, there is no mention of PHP in the Apache configuration file. As a result, when I access a PHP file through the browser, it displays the PHP code instead of executing it.

I would appreciate any assistance in resolving this issue. Can you guide me on how to properly link Apache with PHP on a Windows system? What steps am I missing or where can I find the required PHP module file for Apache?

Thank you in advance for your help!


Solution

  • As stated in the @ADyson comment, it would be easier for you download and install a pre-built environment like XAMPP, WAMP, etc.

    As you had already installed both (Apache and PHP), including them in the Windows PATH enviroment variables, etc., I would tell (at least one of) the missing step(s) is add some lines to Apache's httpd.conf located under conf directory.

    #
    # e.g., for PHP 8
    #
    AddHandler application/x-httpd-php .php
    AddType application/x-httpd-php .php
    
    # Adjust the path to the real location of the corresponding module
    LoadModule php_module "C:/php/php8apache2_4.dll"
    
    # Change it to the directory path of
    PHPIniDir "C:/php"
    

    Indeed, it depends also on which PHP version you downloaded (we recommend the newest stable release) and the compatibility with the Apache version you installed.