0

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!

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
Sk Miraj
  • 47
  • 4
  • I guess you could do it by hand but it would probably be easier to install one of the prepackaged setups like WAMP or XAMPP which does it all for you – ADyson Jul 16 '23 at 19:01
  • You say "the package", but there're several packages available. Make sure to get a Thread Safe version. You have setup instructions at [Apache 2.x on Microsoft Windows](https://www.php.net/manual/en/install.windows.apache2.php). – Álvaro González Jul 17 '23 at 07:14

1 Answers1

1

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.

Collei Inc.
  • 46
  • 1
  • 5
  • 1
    Please note that this setup will also execute PHP code in files with multiple extensions, such as `foo.php.jpg`. It may or may not be what you want. – Álvaro González Jul 17 '23 at 07:17
  • 1
    Thanks it works now. I downlaoded the non thread safe version that's why I was unable to find hp8apache2_4.dll file. Then when I downloaded thread safe , I find it. Thanks a lot. – Sk Miraj Jul 17 '23 at 20:14