Home  >  Article  >  Backend Development  >  How to Configure PHP and Apache with Brew on macOS for Seamless Extension Installation?

How to Configure PHP and Apache with Brew on macOS for Seamless Extension Installation?

Susan Sarandon
Susan SarandonOriginal
2024-10-19 12:45:02193browse

How to Configure PHP and Apache with Brew on macOS for Seamless Extension Installation?

PHP Brew Installation and Apache Configuration

When installing PHP extensions via brew on macOS, it's crucial to ensure compatibility with Apache.

Checking PHP Versions

Check if brew's PHP differs from Apache's by using:

brew search php

Confirm that the version you expect is installed and add it to your PATH if necessary.

Configuring Apache

To enable PHP in Apache, follow these steps:

  1. Open your httpd.conf file and add the following lines:
LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
  1. Check DirectoryIndex to include index.php:
DirectoryIndex index.php index.html
  1. Restart Apache to apply the changes.

PHP Configuration Files

The configuration files for PHP are located at:

/usr/local/etc/php/7.4/

You can find additional information in the Homebrew PHP formula page:

brew info php

By adhering to these instructions, you can ensure that Apache uses the PHP version installed via brew and seamlessly integrate your PHP extensions.

The above is the detailed content of How to Configure PHP and Apache with Brew on macOS for Seamless Extension Installation?. 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