Skip to content

Instantly share code, notes, and snippets.

@rsuper
Last active January 16, 2018 11:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rsuper/961c05f6d5b2c48a450e2e2bc7ca0eed to your computer and use it in GitHub Desktop.
Save rsuper/961c05f6d5b2c48a450e2e2bc7ca0eed to your computer and use it in GitHub Desktop.
Mac OS Homebrew Apache 2.4 & PHP 7.1
#
# Installing Apache 2.4 and PHP 7.1 using Homebrew
# Credits @ https://gist.github.com/DragonBe/0faebe58deced34744953e3bf6afbec7
#
# Note to self to manage httpd process:
# sudo brew services start|stop|restart httpd
# Install Xcode command line tools
xcode-select --install
# Install homebrew:
# https://brew.sh/
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# Or update homebrew
brew update
brew upgrade
# Installing stuff, order of commands
brew tap homebrew/homebrew-php
brew tap homebrew/apache
# Install Homebrew Apache 2.4
brew install httpd24 --with-privileged-ports --with-http2
# Uninstall old versions of PHP (if applicable)
brew unlink php70
# Install PHP 7.1 (grab a ☕️ or a 🍺, this might take some time)
brew install php71 --with-httpd --with-homebrew-curl
# Update php.ini @ /usr/local/etc/php/7.1/php.ini
date.timezone = "Europe/Amsterdam"
post_max_size = 128M
upload_max_filesize = 128M
opcache.max_accelerated_files = 20000
realpath_cache_size=4096K
realpath_cache_ttl=600
# Configure apache to use the PHP module at /usr/local/etc/httpd/httpd.conf
LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
<FilesMatch .php$>
SetHandler application/x-httpd-php
</FilesMatch>
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
# (Optionally make the webserver run as current user if you find it safe enough)
#
# PHP extensions
#
# Curl
brew install --with-openssl curl
# MCrypt
brew install php71-mcrypt
# OPCache
brew install php71-opcache
# APCU
brew install php71-apcu
# Xdebug for PHP 7.1
# (/usr/local/etc/php/7.1/conf.d/ext-xdebug.ini)
brew install homebrew/php/php71-xdebug
##
# FINALLY
#
# Unload default Apache service integrated in Mac OS (no necessary?)
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
# Apache start automatically upon startup
sudo brew services start httpd
# Check if Apache is running
ps -aef | grep httpd
####################################################################################
# CAVEATS
#
# `brew install httpd24 --with-privileged-ports --with-http2`
# DocumentRoot is /usr/local/var/www
#
# The default ports have been set in /usr/local/etc/httpd/httpd.conf to 8080 and in
# /usr/local/etc/httpd/extra/httpd-ssl.conf to 8443 so that httpd can run without sudo.
#
# To have launchd 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:
# apachectl start
#
# ########
#
# `brew install php71 --with-httpd --with-homebrew-curl`
# To enable PHP in Apache add the following to httpd.conf and restart Apache:
# LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
#
# <FilesMatch .php$>
# SetHandler application/x-httpd-php
# </FilesMatch>
#
# Finally, check DirectoryIndex includes index.php
# DirectoryIndex index.php index.html
#
# The php.ini file can be found in:
# /usr/local/etc/php/7.1/php.ini
#
# ✩✩✩✩ Extensions ✩✩✩✩
#
# If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH:
#
# PATH="/usr/local/bin:$PATH"
#
# PHP71 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP.
#
# ✩✩✩✩ PHP CLI ✩✩✩✩
#
# If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file:
# export PATH="$(brew --prefix homebrew/php/php71)/bin:$PATH"
#
# ✩✩✩✩ FPM ✩✩✩✩
#
# To launch php-fpm on startup:
# mkdir -p ~/Library/LaunchAgents
# cp /usr/local/opt/php71/homebrew.mxcl.php71.plist ~/Library/LaunchAgents/
# launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php71.plist
#
# The control script is located at /usr/local/opt/php71/sbin/php71-fpm
#
# OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH:
#
# PATH="/usr/local/sbin:$PATH"
#
# You may also need to edit the plist to use the correct "UserName".
#
# Please note that the plist was called 'homebrew-php.josegonzalez.php71.plist' in old versions of this formula.
#
# With the release of macOS Sierra the Apache module is now not built by default. If you want to build it on your system you have to install php with the --with-httpd option. See brew options php71 for more details.
#
# To have launchd start homebrew/php/php71 now and restart at login:
# brew services start homebrew/php/php71
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment