Skip to content

Instantly share code, notes, and snippets.

@lequi
Forked from DragonBe/php_apache_homebrew.md
Created October 21, 2017 07:13
Show Gist options
  • Save lequi/d7ff985f2c0d4af39e9294cec22ccb04 to your computer and use it in GitHub Desktop.
Save lequi/d7ff985f2c0d4af39e9294cec22ccb04 to your computer and use it in GitHub Desktop.

Revisions

  1. @DragonBe DragonBe revised this gist Mar 18, 2017. 1 changed file with 33 additions and 13 deletions.
    46 changes: 33 additions & 13 deletions php_apache_homebrew.md
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,24 @@
    # Apache, PHP with homebrew
    I posted several talks about compiling PHP from source, but everyone was trying to convince me that a package manager like [Homebrew](https://brew.sh) was a more convenient way to install.

    The purpose of [Homebrew](https://brew.sh) is simple: a package manager for macOS that will allow you to set up and install common packages easily and allows you to update frequently using simple commands.

    I used a clean installation of [macOS Sierra](https://www.apple.com/macos/sierra/) to ensure all steps could be recorded and tested. In most cases you already have done work on your Mac, so chances are you can skip a few steps in this tutorial.

    # Apache and PHP with homebrew

    I’ve made this according to the installation instructions given on [GetGrav](https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions).

    ## The installation procedures

    Install Xcode command line tools
    These installation procedures will set up your [macOS Sierra](https://www.apple.com/macos/sierra/) with PHP 7.1 and Apache 2.4.

    ### Install Xcode command line tools (if not done yet)

    ```
    xcode-select --install
    ```

    Install Homebrew
    ### Install Homebrew

    ```
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    @@ -25,20 +33,20 @@ brew tap homebrew/homebrew-php
    brew tap homebrew/apache
    ```

    Unload the provisioned Apache from macOS Sierra
    ### Unload the provisioned Apache from macOS Sierra

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

    Install Homebrew Apache
    ### Install Homebrew Apache

    ```
    brew install httpd24 --with-privileged-ports --with-http2
    ```

    Set up for autostart at startup of macOS Sierra
    ### Set up Apache for autostart at macOS Sierra (re)boot

    ```
    sudo cp -v /usr/local/Cellar/httpd24/2.4.25/homebrew.mxcl.httpd24.plist /Library/LaunchDaemons
    @@ -48,13 +56,13 @@ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
    ```

    Check to see it’s running
    ### Check to see Apache is running

    ```
    ps -aef | grep httpd
    ```

    This should be the output
    You should see something similar as output

    ```
    0 23417 1 0 2:48PM ?? 0:00.06 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
    @@ -66,19 +74,25 @@ This should be the output
    501 23428 403 0 2:48PM ttys000 0:00.00 grep httpd
    ```

    Let’s remove previous installed versions of PHP
    ### Uninstall previous versions of PHP

    We assume you had PHP 7.0 installed

    ```
    brew unlink php71
    brew unlink php70
    ```

    ### Install latest PHP version (PHP 7.1.2 at the time of writing)

    Time to install latest PHP with the apache web server

    ```
    brew install php71 --with-httpd24
    ```

    Don’t forget to set `date.timezone` in `/usr/local/etc/php/7.1/php.ini`!!!
    **Don’t forget to set `date.timezone` in `/usr/local/etc/php/7.1/php.ini`!!!**

    ### Configure Apache for PHP usage

    Also make sure to set the following line in `/usr/local/etc/apache2/2.4/httpd.conf` (You might need to disable others):

    @@ -102,16 +116,22 @@ Also make sure you have set the following lines correctly:
    </FilesMatch>
    ```

    Time to restart apache
    ### Time to restart apache

    ```
    sudo /usr/local/bin/apachectl -k restart
    ```

    ### Test your setup

    Create a `phpinfo.php` in `/usr/local/var/www/htdocs` with the following contents:

    ```
    <?php phpinfo();
    ```

    What’s left is to configure virtual hosts
    You should see the famous PHP information page!

    ### Next steps

    Now you can set up your virtual hosts like you normally would do.
  2. @DragonBe DragonBe created this gist Mar 18, 2017.
    117 changes: 117 additions & 0 deletions php_apache_homebrew.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,117 @@
    # Apache, PHP with homebrew

    I’ve made this according to the installation instructions given on [GetGrav](https://getgrav.org/blog/macos-sierra-apache-multiple-php-versions).

    ## The installation procedures

    Install Xcode command line tools

    ```
    xcode-select --install
    ```

    Install Homebrew

    ```
    /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    ```

    Set up for installation of PHP and Apache

    ```
    brew tap homebrew/dupes
    brew tap homebrew/versions
    brew tap homebrew/homebrew-php
    brew tap homebrew/apache
    ```

    Unload the provisioned Apache from macOS Sierra

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

    Install Homebrew Apache

    ```
    brew install httpd24 --with-privileged-ports --with-http2
    ```

    Set up for autostart at startup of macOS Sierra

    ```
    sudo cp -v /usr/local/Cellar/httpd24/2.4.25/homebrew.mxcl.httpd24.plist /Library/LaunchDaemons
    sudo chown -v root:wheel /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
    sudo chmod -v 644 /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
    sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
    ```

    Check to see it’s running

    ```
    ps -aef | grep httpd
    ```

    This should be the output

    ```
    0 23417 1 0 2:48PM ?? 0:00.06 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
    1 23420 23417 0 2:48PM ?? 0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
    1 23421 23417 0 2:48PM ?? 0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
    1 23422 23417 0 2:48PM ?? 0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
    1 23423 23417 0 2:48PM ?? 0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
    1 23424 23417 0 2:48PM ?? 0:00.00 /usr/local/opt/httpd24/bin/httpd -D FOREGROUND
    501 23428 403 0 2:48PM ttys000 0:00.00 grep httpd
    ```

    Let’s remove previous installed versions of PHP

    ```
    brew unlink php71
    ```

    Time to install latest PHP with the apache web server

    ```
    brew install php71 --with-httpd24
    ```

    Don’t forget to set `date.timezone` in `/usr/local/etc/php/7.1/php.ini`!!!

    Also make sure to set the following line in `/usr/local/etc/apache2/2.4/httpd.conf` (You might need to disable others):

    ```
    LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so
    ```

    Also make sure you have set the following lines correctly:

    ```
    #
    # DirectoryIndex: sets the file that Apache will serve if a directory
    # is requested.
    #
    <IfModule dir_module>
    DirectoryIndex index.html index.php
    </IfModule>
    <FilesMatch \.php$>
    SetHandler application/x-httpd-php
    </FilesMatch>
    ```

    Time to restart apache

    ```
    sudo /usr/local/bin/apachectl -k restart
    ```

    Create a `phpinfo.php` in `/usr/local/var/www/htdocs` with the following contents:

    ```
    <?php phpinfo();
    ```

    What’s left is to configure virtual hosts