Engine23
blogBannerImage
By Engine23

Setting new Mac 10.9 for PHP development

  1. Download MySQL DMG  http://dev.mysql.com/downloads/mysql/
  2. Install both the MySQL and the startup packages ( this may require approval in your  Mac OS X Privacy & Security settings )
  3. Start mysql via command line  
    sudo /usr/local/mysql/support-files/mysql.server start
  4. Start apache via command line  
    sudo apachectl start
  5. Create a folder for your virtual host files
    sudo mkdir  /etc/apache2/extra/vhosts 
  6. make your virtual hosts file 
    sudo cp /etc/apache2/extra/httpd-vhosts.conf /etc/apache23/extra/vhosts/local.domain.com
    
    sudo vim /etc/apache2/extra/vhosts/local.domain.com 
  1. Now create an vhost file similar to this
    <VirtualHost *:80>
        ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot "/Users/ryan/Sites/local.domain.com"
        ServerName local.domain.com
     
        ErrorLog "/private/var/log/apache2/local.domain.com-error_log"
        CustomLog "/private/var/log/apache2/local.domain.com-access_log" common
     
        <Directory /Users/ryan/Sites/local.domain.com>
            AllowOverride none
     
            Order Allow,Deny
            Allow from all
         </Directory>
     
    </VirtualHost>
  2. edit the computers hosts file to point to our new local site
    sudo vim /etc/hosts
    Now create an entry similar to this at the bottom/or top of this file
    # Redirect back to this computer
    127.0.0.1 local.engine23.com
    # Rediredct to specific IP
    10.10.10.1 dev.engine23.com
  3. restart apache
    sudo apachectl restart
  4. create your folder for the development sites such as /www/ or /Users/whateveryournameis/Sites/
  5.  edit the apache configuration files to get things ready for PHP development and the location of the new start for our localhost 
    sudo vim /private/etc/apache2/httpd.conf 

    Make the following changes to the httdp.conf file.

    • On line 170, change the DocumentRoot:
      DocumentRoot “/www”
    • On line 197, change the Directory location:
      <Directory “/www”>
    • On line 217 (within the Directory location we just updated), change the AllowOverride to “All” so that we can use .htaccess to modify any settings for our local sites:
      AllowOverride All
    • On line 429, uncomment the Include of the httpd-vhosts.conf file:
      Include /private/etc/apache2/extra/httpd-vhosts.conf
    • Add this line jsut below that:
      Include /private/etc/apache2/extra/vhosts/*
    • On line 118, uncomment the LoadModule for PHP:  LoadModule php5_module libexec/apache2/libphp5.so
      • On line 231, add index.php as a default document if a directory is requested:
        DirectoryIndex index.html index.php
      • Add Php settings below that:
        #PHP Settings
        <IfModule php5_module>
            AddType application/x-httpd-php .php
            AddType application/x-httpd-php-source .phps
        </IfModule>
  6. Now edit the /etc/apache2/extra/httpd-vhosts.conf to add our entry
    # Engine23
    <VirtualHost *:80>         DocumentRoot "/www/" ServerName local.engine23.com
            <directory "/Users/ryan/Sites/local.engine23.com/">
                    Options All
                    AllowOverride All
                    Order allow,deny
                    Allow from all
            </directory>
    </VirtualHost>
  7. Set mysql to run via command line: export PATH=$PATH:/usr/local/mysql/bin

    Lastly install wget

    How to Install wget in OS X

    Moving ahead and assuming you have Xcode and the command line tools installed, launch Terminal and enter the following commands as shown.

    First, use curl to download the latest wget source:
    curl -O http://ftp.gnu.org/gnu/wget/wget-1.13.4.tar.gz

    (sidenote: a new version of wget is available as 1.15, but 1.13.4 has been confirmed compatible. You can pick whichever one you want from the http://ftp.gnu.org/gnu/wget/ directory if you want a different version)

    Next we use tar to uncompress the files you just downloaded:
    tar -xzf wget-1.13.4.tar.gz

    Use cd to change to the directory:
    cd wget-1.13.4

    Configure with the appropriate –with-ssl flag to prevent a “GNUTLS not available” error:
    ./configure --with-ssl=openssl

    Build the source:
    make

    Install wget, it ends up in /usr/local/bin/:
    sudo make install

    Confirm everything worked by running wget:
    wget --help

    Clean up by removing wget source files when finished:
    cd .. && rm -rf wget* 

  8. To run mysql verify the command matches mysql folder in /usr/local and run via command line:
    sudo ln -s /usr/local/mysql-5.6.16-osx10.6-x86_64/bin/mysql /usr/bin/mysql
  9.  In PHP to use adminer or phpmyadmin you need to change /etc/php.ini to have the information on how to connect to mysql through localhost instead of 127.0.0.1:

    pdo_mysql.default_socket = /tmp/mysql.sock 

    mysql.default_socket = /tmp/mysql.sock 

    mysql.default_host = 127.0.0.1 

    mysqli.default_socket = /tmp/mysql.sock

  10. Finally how to setup mcrypt

  11.  

  12. How to Install mcrypt for php on Mac OSX 10.9 Mavericks for a Development Server

    The mcrypt extension is missing. Please check your PHP configuration.

    The above error appears after you successfully get phpMyAdmin up and running on OS X, generally you don’t have to worry about it, you only need to address the error if you are going to use a web application that requires it, for example Magento, the shopping cart software or a php framework like Laravel.

    mcrypt is a file encryption method using secure techniques to exchange data. This tutorial has been tested in 10.9 Mavericks.

    There are two ways to solve this issue on OSX, it depends on what your comfortable with and what you already have – this guide takes you through staying what you already have by installing and compiling code to get the extension running, an alternative is to use a packaged version of PHP which already has the mcrypt extension compiled and enabled, this for some would be an easier option to deploy – see that PHP guide here.

     

    Xcode

    Get Xcode 5.0.2 from the Apple app store, free download version, then install it from the /Applications folder it will be called ‘Install Xcode’ or just Xcode.app. You need this to use the compilers to compile the source code that you will download.

    Go to Xcode preferences and then look in the ‘Locations’ button.

    Select  the Xcode 5.0.2 command line tools from the Locations of Xcode.

    Then install the Command Line Tools via the Terminal

    xcode-select --install

    It will prompt a dialog box to install them

     

    Getting it on in OS X Mavericks

    This tutorial works mostly in the Terminal, launch it from /Applications/Utilities, change directory (cd) to the home account and make a directory that you will work in, call it mcrypt

    cd ~ ; mkdir mcrypt ; cd mcrypt

    Get libmcrypt 2.5.8 from Sourceforge,  this is direct download link.

    Get the php code in a tar.gz or .bz2 format- (version 5.4.17 is the one that currently ships with OSX 10.9)

    Check your version at the command line:

    php -v

    Move both of these files that you downloaded into your working directory – mcrypt in this instance and go back to Terminal

    cd ~/mcrypt

    Expand both files via the command line or just double click them in the Finder:

    tar -zxvf libmcrypt-2.5.8.tar.gz
    tar -zxvf php-5.4.17.tar.gz

    Remove the compressed archives

    rm *.gz

    Any errors on the command line including C++ and g++ mostly are due to Xcode not being installed or the command line tools missing.

     

    Configuring libmcrypt

    Change directory into libmcrypt
     
    cd libmcrypt-2.5.8
     
    Libmcrypt needs to be configured, enter
    ./configure
    make
    sudo make install

    With the libmcrypt configured and libraries now installed, time for to make the mcrypt extension.

     

     

    Autoconf Errors

    If the below error occurs after you try the following compile of mcrypt, then autoconf is not installed. (I didn’t get these errors in an upgrade to Mavericks which had autoconf prior but a new installation will need autoconf installed).

    Cannot find autoconf. Please check your autoconf installation and the
    $PHP_AUTOCONF environment variable. Then, rerun this script.

    Autoconf is not installed with the latest Xcode but may be present on some OS X from an upgraded older Xcode.

    If you need autoconf – some more Terminal heavy lifting:

    cd ~/mcrypt
    curl -O http://ftp.gnu.org/gnu/autoconf/autoconf-latest.tar.gz
    tar xvfz autoconf-latest.tar.gz
    cd autoconf-2.69/
    ./configure
    make
    sudo make install

     

    Compile mcrypt php Extension

    cd ../php-5.4.17/ext/mcrypt/
    /usr/bin/phpize

    Output should be:

    Configuring for:
    PHP Api Version:         20100412
    Zend Module Api No:      20100525
    Zend Extension Api No:   220100525

    ./configure
    make
    sudo make install

    The result of this should be:

    Installing shared extensions:     /usr/lib/php/extensions/no-debug-non-zts-20100525/

     

     

    Enabling mcrypt.so  php Extension

    Open /etc/php.iniand add the line below at the end

    extension=mcrypt.so

    If there is no php.ini file,  then you need to make one from php.ini.default in the same location like so:

    sudo cp /etc/php.ini.default /etc/php.ini

    And allow write capability

    sudo chmod u+w  /etc/php.ini

    Then add the line as above in your favourite text editor:

    sudo nano /etc/php.ini

    or

    sudo vi /etc/php.ini

    and add in the line:

    extension=mcrypt.so

    Restart Apache

    sudo apachectl restart

    That’s it, check your phpMyadmin login page or create and browse to a phpinfo.php to see if it loaded correctly, if it didn’t load you may need to declare the extensions directory in /etc/php.ini

    extension_dir = "/usr/lib/php/extensions/no-debug-non-zts-20100525/"