Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the php that brew installed?

On my mac I've got php installed and working fine. I recently wanted to install mcrypt, so I did so using brew. Although it seemed to install fine, it doesn't show up in my phpinfo(). So I think that the php that brew installed mcrypt in, isn't the php that apache uses.

Does anybody know how I can:

  1. check whether there is a difference between the php installed by brew and the php which Apache uses?
  2. make apache use the php that brew installed?

All tips are welcome!

like image 479
kramer65 Avatar asked Dec 11 '13 15:12

kramer65


People also ask

What is Homebrew PHP?

May 5, 2020 January 15, 2022 homebrew, php. Homebrew, the popular package manager for macOS, allows you to install more than one version of PHP.

Is PHP already installed on Mac?

Before you can enable PHP on a Mac, you first have to enable Apache. Both PHP and Apache are free open source software programs and both come installed on all Macs.


3 Answers

According to the contributors of the Homebrew php formula...

The contributors of the Homebrew php formula give the following instructions. The exact instructions reproduced here install php7.4. Substitute the php version you need.

(Avoid "special" ways of accomplishing your objective; they are often problematic. "Official" approaches are more likely to give you a predictable, maintainable setup.)

$ brew search php // since php can be installed by homebrew but be missing from your PATH, review the list of php versions available through homebrew; a checkmark next to a version indicates one is installed
$ brew install [email protected]
$ echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc // add the alias to your path (issues you are using zsh, the default now for macOS); see comments output during installation
$ source ~/.zshrc // reload . zshrc to use the new settings immediately

The contributors of the formula also provide the following instructions for enabling PHP in Apache:

To enable PHP in Apache add the following to httpd.conf and restart Apache:

   LoadModule php_module /usr/local/opt/php/lib/httpd/modules/libphp.so  

   <FilesMatch \.php$>  
       SetHandler application/x-httpd-php  
   </FilesMatch>`

Finally, check DirectoryIndex includes index.php

   DirectoryIndex index.php index.html  

The php.ini and php-fpm.ini file can be found in:

   /usr/local/etc/php/7.4/

These instructions for enabling PHP in Apache appear in stdout when you install php. Alternatively in Terminal use brew info php or visit the Homebrew PHP formula page

like image 169
Kay V Avatar answered Oct 24 '22 01:10

Kay V


You have to make your Apache use the PHP that you just downloaded.

  • Open your httpd.conf (mine is at /etc/apache2/httpd.conf) and look for the line that loads the PHP module, something like:

    LoadModule php5_module path/to/php

  • Then, make it point to the PHP that brew installed for you with mcrypt support. Mine was at this path. Yours can vary depending on the PHP version that you installed.

    /usr/local/Cellar/php54/5.4.21/libexec/apache2/libphp5.so

  • Finally you will need to restart your Apache server to load the new configuration:

    sudo apachectl restart

like image 66
Manuel Pedrera Avatar answered Oct 24 '22 02:10

Manuel Pedrera


Can't comment on stackoverflow yet due to my lack of experience but to add to the above answer is correct. Just an additional comment to find the correct path:

run:

brew info php54

or which ever version u have installed and it will show you the path:

To enable PHP in Apache add the following to httpd.conf and restart Apache:
    LoadModule php5_module    /usr/local/opt/php54/libexec/apache2/libphp5.so
like image 35
AnthonyT Avatar answered Oct 24 '22 02:10

AnthonyT