Skip to content

Instantly share code, notes, and snippets.

@siswadi
Last active June 15, 2017 09:09
Show Gist options
  • Save siswadi/c38868475afe92e454ee9fd61fbbb953 to your computer and use it in GitHub Desktop.
Save siswadi/c38868475afe92e454ee9fd61fbbb953 to your computer and use it in GitHub Desktop.
OSX10.12; Apache2.4; Multi PHP Version

OSX10.12, Install Apache2.4 with Multi PHP Version.

Install Homebrew

$ xcode-select --install
$ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
$ brew update
$ brew install wget vim

Homebrew

Install Apache 2.4.25

$ brew install homebrew/apache/httpd24

Install FastCGI

$ brew install homebrew/apache/mod_fastcgi --with-brewed-httpd24
$ mkdir /usr/local/var/apache2/fastcgi

Install PHP 5.3.29

$ brew install php56 --with-httpd24

$ brew install \
homebrew/php/php53-imagick \
homebrew/php/php53-gmagick \
homebrew/php/php53-mcrypt \
homebrew/php/php53-crypto \
homebrew/php/php53-pdo-dblib \
homebrew/php/php53-mysqlnd_ms

Install PHP 5.6.29

$ brew unlink php53

$ brew install php56 --with-httpd24

$ brew install \
homebrew/php/php56-imagick \
homebrew/php/php56-mcrypt \
homebrew/php/php56-gmagick \
homebrew/php/php56-crypto \
homebrew/php/php56-mysqlnd_ms \
homebrew/php/php56-pdo-dblib

Configuration

Apache Configuration

$ sudo vim /usr/local/etc/apache2/2.4/httpd.conf

# fastcgi_module
LoadModule fastcgi_module /usr/local/Cellar/mod_fastcgi/2.4.6/libexec/mod_fastcgi.so

# php5_module
#LoadModule php5_module /usr/local/Cellar/php53/5.3.29_7/libexec/apache2/libphp5.so
LoadModule php5_module /usr/local/Cellar/php56/5.6.29_5/libexec/apache2/libphp5.so

# Custom Config
Include /usr/local/etc/apache2/2.4/mods/*.conf

# VHost Config
Include /usr/local/etc/apache2/2.4/vhosts/*.conf

PHP Configuration

$ sudo vim /usr/local/etc/apache2/2.4/mods/php5_module.conf

<IfModule php5_module>
  AddType application/x-httpd-php .php
  AddType application/x-httpd-php-source .phps
</IfModule>

FastCGI Configuration

$ sudo vim /usr/local/etc/apache2/2.4/mods/fastcgi_module.conf

<IfModule fastcgi_module>
  AddHandler fastcgi-script .fcgi
  <Directory "/usr/local/var/apache2/cgi-bin-php">
    AllowOverride None
    Order allow,deny
    Allow from all 
    Require all granted
  </Directory>
  # mkdir /usr/local/var/apache2/fastcgi
  FastCgiIpcDir /usr/local/var/apache2/fastcgi
  FastCgiConfig -idle-timeout 110 -killInterval 120 -pass-header HTTP_AUTHORIZATION -autoUpdate
</IfModule>

$ sudo vim /usr/local/var/apache2/cgi-bin-php/php-cgi-5.3.29.fcgi

#!/bin/sh

version="5.3"
shortversion="53"
PHPRC=/usr/local/etc/php/${version}/php.ini
export PHPRC
PHP_FCGI_CHILDREN=3
export PHP_FCGI_CHILDREN
PHP_FCGI_MAX_REQUESTS=5000
export PHP_FCGI_MAX_REQUESTS
# /usr/local/bin/php-cgi ->
exec /usr/local/Cellar/php${shortversion}/${version}.29_7/bin/php-cgi

$ sudo chmod 755 /usr/local/var/apache2/cgi-bin-php/php-cgi-5.3.29.fcgi

VHost Configuration

$ sudo vim /usr/local/etc/apache2/2.4/vhosts/php53.siswadi.com.conf

<VirtualHost *:80>
  DocumentRoot "/Users/siswadi/WWW/php53.siswadi.com/public_html"
  ServerName siswadi.com
  ServerAlias www.siswadi.com
  <Directory "/Users/siswadi/WWW/php53.siswadi.com/public_html">
    AllowOverride All
    allow from all
    Options +FollowSymLinks
  </Directory>
  <IfModule fastcgi_module>
    AddHandler php-cgi .php
    Action php-cgi /cgi-bin-php/php-cgi-5.3.29.fcgi
    <FilesMatch "\.php$">
      SetHandler php-cgi
    </FilesMatch>
  </IfModule>
  ErrorLog "/usr/local/var/log/apache2/php53.siswadi.com-error_log"
  CustomLog "/usr/local/var/log/apache2/php53.siswadi.com-access_log" common
</VirtualHost>

$ sudo vim /usr/local/etc/apache2/2.4/vhosts/php56.siswadi.com.conf

<VirtualHost *:80>
  DocumentRoot "/Users/siswadi/WWW/php56.siswadi.com/public_html"
  ServerName store.siswadi.com
  <Directory "/Users/siswadi/WWW/php56.siswadi.com/public_html">
    AllowOverride All
    allow from all
    Options +FollowSymLinks
  </Directory>
  ErrorLog "/usr/local/var/log/apache2/php56.siswadi.com-error_log"
  CustomLog "/usr/local/var/log/apache2/php56.siswadi.com-access_log" common
</VirtualHost>

$ sudo vim /etc/hosts

127.0.0.1 php53.siswadi.com
127.0.0.1 php56.siswadi.com

$ vim /Users/siswadi/WWW/siswadi.com/public_html/index.php

<? phpinfo() ?>

$ vim /Users/siswadi/WWW/siswadi.com.store/public_html/index.php

<? phpinfo() ?>

Restart Apache

$ sudo apachectl restart

Testing

PHP Version 5.3.29
PHP Version 5.5.9
PHP Version 5.6.0
PHP Version 7.0.13
  • Done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment