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:
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!