Tips and tricks

How to create a local dev Apache Mysql PHP Setup on Mac OS X

Tired of using MAMP ?

You should already have Apache installed on mac

1. Install Apache

1a. Homebrew install

Install

brew install httpd php

Start it

brew --prefix

1b. included apache in mac os x – you just need to start it:

sudo apachectl start
restart:
sudo apachectl restart
check config:
apachectl configtest

optional, if you are on Mac OS X Monterey you might need to uninstall the default Apache 2.4

sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd

to check if you have httpd running you can do ps -ef |grep httpd

ps -ef |grep httpd
    0  4182     1   0 Mon01PM ??         0:01.16 /Applications/MAMP/Library/bin/httpd -f /Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf -k start
  501  4183  4182   0 Mon01PM ??         0:00.00 /Applications/MAMP/Library/bin/httpd -f /Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf -k start
  501  4189  4182   0 Mon01PM ??         0:00.02 /Applications/MAMP/Library/bin/httpd -f /Library/Application Support/appsolute/MAMP PRO/conf/httpd.conf -k start
  501 24659 24648   0 12:33AM ??         0:00.00 /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND
  501 24661 24648   0 12:33AM ??         0:00.01 /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND
  501 24662 24648   0 12:33AM ??         0:00.00 /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND

then you can do

$/opt/homebrew/opt/httpd/bin/httpd -V


Server version: Apache/2.4.48 (Unix)
Server built:   Jul  6 2021 20:11:03
Server's Module Magic Number: 20120211:105
Server loaded:  APR 1.7.0, APR-UTIL 1.6.1
Compiled using: APR 1.7.0, APR-UTIL 1.6.1
...

you can check the config syntax with

httpd -t

check which services use port 80

sudo lsof -i -P | grep LISTEN

Access the config from /private/etc/apache2/httpd.conf ### /opt/homebrew/etc/httpd/httpd.conf ( homebrew ) ->

showing how to setup in htaccess config user and group
remember to change the User and Group to your user and group settings

start the server

/opt/homebrew/bin/httpd -k start

add Virtual Hosts . Create a local dev Apache Mysql PHP Setup on Mac OS X – add Virtual Hosts ‣ Digital Zoom Studio

add PHP . Create a local dev Apache Mysql PHP Setup on Mac OS X – add PHP ‣ Digital Zoom Studio

add mySQL . Create a local dev Apache Mysql PHP Setup on Mac OS X – add MySql ‣ Digital Zoom Studio

add XDebug . create a local dev Apache Mysql PHP Setup on Mac OS X – add XDebug ‣ Digital Zoom Studio


FAQ:

What is the difference between apachectl and httpd ?

apachectl is a wrapper over httpd and just sets some environment variables and adds further functionality, like configtest, more in detail herehttpd.worker is like httpd but with the worker module enabled.

Where to find logs for troubleshooting ?

you can find them in ErrorLog “/private/var/log/apache2/error_log”

Check homebrew prefix
brew --prefix
I am getting could not bind to address error
(48)Address already in use: AH00072: make_sock: could not bind to address [::]:80
(48)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80

use this command

sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
sudo apachectl -k restart
I get forbidden 403 when I access any page

apachectl is a wrapper over httpd and just sets some environment variables and adds further functionality, like configtest, more in detail herehttpd.worker is like httpd but with the worker module enabled.


DocumentRoot is /opt/homebrew/var/www

The default ports have been set in /opt/homebrew/etc/httpd/httpd.conf to 8080 and in

/opt/homebrew/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.

To start httpd now and restart at login:

  brew services start httpd

Or, if you don’t want/need a background service you can just run:

  /opt/homebrew/opt/httpd/bin/httpd -D FOREGROUND

==> php

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

LoadModule php_module /opt/homebrew/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:

    /opt/homebrew/etc/php/8.4/

To start php now and restart at login:

  brew services start php

Or, if you don’t want/need a background service you can just run:

  /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
{"type":"main_options","images_arr":"'#ffffff'","enable_ajax":"off","soundcloud_apikey":"","bg_isparallax":"off","bg_slideshow_time":"0","bg_transition":"slidedown","site_url":"https:\/\/digitalzoomstudio.net","theme_url":"https:\/\/digitalzoomstudio.net\/wp-content\/themes\/qucreative\/","blur_ammount":"26","width_column":"50","width_section_bg":"","width_gap":"30","border_width":"0","border_color":"#ffffff","translate_cancel_comment":"Cancel reply","translate_leave_a_comment":"Leave a comment","translate_leave_a_comment_to":"Leave a comment to","is_customize_preview":"off","width_blur_margin":"30","gallery_w_thumbs_autoplay_videos":"off","content_enviroment_opacity":"30","menu_enviroment_opacity":"70","base_url":"https:\/\/digitalzoomstudio.net"}
{"type":"darkfull"}