Home  >  Article  >  Backend Development  >  How to Resolve Apache Not Recognizing Brew-Installed PHP?

How to Resolve Apache Not Recognizing Brew-Installed PHP?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-10-19 12:36:29485browse

How to Resolve Apache Not Recognizing Brew-Installed PHP?

Harnessing Brew-Installed PHP with Apache

You've encountered an issue where PHP installed via Homebrew doesn't seem to be recognized by Apache. To resolve this dilemma, let's delve into the following initiatives:

1. Verifying PHP Discrepancies:

To check if Brew's PHP differs from Apache's, run the following command:

<code class="php">which php</code>

This will display the path to the PHP binary used by your system. Compare this to the path shown in Apache's configuration file (httpd.conf):

<code class="php">LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so</code>

If the paths differ, there is a discrepancy.

2. Directing Apache to Brew's PHP:

To ensure Apache uses Brew's PHP, modify httpd.conf:

<code class="php">LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so</code>

Make sure the path matches that of Brew's PHP binary.

3. Enabling PHP in Apache:

Enable PHP in Apache by adding the following code to httpd.conf:

<code class="php"><FilesMatch \.php$>
  SetHandler application/x-httpd-php
</FilesMatch></code>

4. Setting DirectoryIndex:

In httpd.conf, ensure DirectoryIndex includes index.php:

<code class="php">DirectoryIndex index.php index.html</code>

5. Confirming php.ini Location:

The php.ini file is located at:

<code class="php">/usr/local/etc/php/7.4/</code>

Additional Tips:

  • Restart Apache after making these changes.
  • Check the Homebrew PHP formula page for comprehensive instructions.
  • Consider using MAMP or XAMPP for a more convenient local development environment, which includes PHP and Apache pre-configured.

The above is the detailed content of How to Resolve Apache Not Recognizing Brew-Installed PHP?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn