How to Resolve Apache Not Recognizing Brew-Installed PHP?

Mary-Kate Olsen
Release: 2024-10-19 12:36:29
Original
487 people have browsed it

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>
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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>
Copy after login

4. Setting DirectoryIndex:

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

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

5. Confirming php.ini Location:

The php.ini file is located at:

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

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!

source:php
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!