installing php on apache using brew on mac

1. Download and install php using brew

brew update
brew install php

2. To enable PHP in Apache add the following to /etc/apache2/httpd.conf and restart Apache:

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


    SetHandler application/x-httpd-php
 

3. In /etc/apache2/httpd.conf, check DirectoryIndex includes index.php

DirectoryIndex index.php index.html

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

/usr/local/etc/php/8.1/

5. Add php to the command path in ~/.bash_profile

export PATH="/usr/local/Cellar/php/8.1.3/bin:$PATH"
export PATH="/usr/local/opt/php@8.1/sbin:$PATH"

6. Reload .bash_profile after the php path is added to .bash_profile

source ~/.bash_profile

7. Check where is php and php version

which php
php -version

8. Create a folder and a php index file with the following content /Users/yourname/myphpapp/index.php


9. Add the following to /etc/hosts

127.0.0.1 myphpapp.com
127.0.0.1 www.myphpapp.com

10. Add the following to the /etc/apache2/httpd.conf to config the php folder

    ServerName myphpapp.com
    DocumentRoot "/Users/yourname/myphpapp"
    
        Options +MultiViews +FollowSymLinks
        AllowOverride All
        
        Order allow,deny
        Allow from all
        
        = 2.3>
        Require all granted
        
    

11. Restart apache

apachectl restart

12. Open myphpapp.com on a browser and a page with php information should be displayed. If it doesn't show anything and not loading, use the following command to diagnose the issues.

apachectl configtest
cat /var/log/apache2/error_log

Search within Codexpedia

Custom Search

Search the entire web

Custom Search