Development WebServer on OSX Lion – HomeBrew/MariaDB/PECL

Apache2 is already installed on any Mac and most setups (like MAMP or MacPorts) just ignore the built in Apache and install their own version. Shame. You wouldn’t ignore your own car just and get another one to pull a trailer while your own car can do the job perfectly.

Choose OSX Version: 10.6 | 10.7 | 10.8 | 10.9 | 10.10 | 10.11

Before you begin; This post is the first post in a series to build the “perfect” setup. See ‘The “Ultimate” Guide …’ or the menu on the right side here for a complete list of all related posts. Also, a few people have commented that below instructions don’t work, only to find that they did NOT follow ALL instructions. Please read and re-read the entire post before you begin. It WILL save you trouble!

1. Your website-storage, a.k.a. website-folders-location, or whatever you want to call it.

Your (development)websites will be stored on your hard drive. If you’re in a multi-user environment, and everyone should be able to use this setup; don’t put it in your home-directory as Alan suggests. Instead put it in the root; in Terminal, type

Shell commandsudo mkdir -m 777 /Development

This folder will store your websites.

2. Required software.

a. Developer tools or Xcode

You can either install Xcode (see the App store, free for everyone) or the Xcode Commandline Tools (see http://developer.apple.com/downloads, you’ll need a developer account).

option 1) Install Xcode. It is available for Snow Leopard and later in the App Store application on your mac. For older versions of OSX you will need to download the installer from the Mac Developer site yourself. You probably need a development account for it.
After installing Xcode, start it up and finish the installation by installing the Commandline Tools from the Downloads panel in the Preferences. After that, you might need to execute the following command;

Shell commandsudo xcode-select -switch /Applications/Xcode.app/Contents/Developer

option 2) Open the downloaded Commandline Tools DMG file and install the PKG file.

b. Install HomeBrew. This is a simple Terminal command;

Shell commandruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

(See this page for more information)

c. Required tools

In Terminal, do:

Shell commandbrew install gnu-sed autoconf automake pidof cmake apple-gcc42 --use-llvm

3. You will need to tell Apache to allow use of this folder. Type;

Shell-Scriptsudo sh -c "cat >> /etc/apache2/httpd.conf <<'EOF'
<Directory "/Development">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
EOF"

4. Installing your database server; MariaDB.
In Terminal, do:

Shell commandbrew install mariadb

During installation you will be notified of two Terminal command you will need to do a few steps after installation. This is a copy command to copy a file to the LaunchAgents folder and one to add the MySQL loader to the startup sequence. Look for it, but don’t worry; as long as you keep the Terminal window open, you can scroll back to copy it later.

These commands will install the MariaDB server;

Shell-Scriptunset TMPDIR
mysql_install_db --verbose --user="$(whoami)" --basedir="$(brew --prefix mariadb)" --datadir=/usr/local/var/mysql --tmpdir=/tmp
cp $(brew --prefix mariadb)/support-files/my-small.cnf /usr/local/var/mysql/my.cnf
sed -i "" 's/max_allowed_packet = 1.*M/max_allowed_packet = 2G/g' /usr/local/var/mysql/my.cnf
[ ! -d /Library/LaunchAgents ] && sudo mkdir /Library/LaunchAgents

To run it for everyone on boot;

Shell commandsudo cp /usr/local/Cellar/mariadb/*/homebrew.mxcl.mariadb.plist /Library/LaunchAgents/

Shell commandlaunchctl load -w /Library/LaunchAgents/homebrew.mxcl.mariadb.plist

5. Configure PHP.

Shell-Scriptsudo sh -c "grep php /etc/apache2/httpd.conf|grep LoadModule|cut -d'#' -f2 > /etc/apache2/other/php5-loadmodule.conf"

Shell-Scriptsudo cp -a /etc/php.ini.default /etc/php.ini
sudo sh -c "cat >> /etc/php.ini <<'EOF'
;;
;; User customizations below
;;
; Original -- memory_limit = 128M
memory_limit = 196M
; Original -- post_max_size = 8M
post_max_size = 200M
; Original -- upload_max_filesize = 2M
upload_max_filesize = 100M
; Original -- default_socket_timeout = 60
default_socket_timeout = 600
; Original -- max_execution_time = 30
max_execution_time = 300
; Original -- max_input_time = 60
max_input_time = 600
; Original -- display_errors = Off
display_errors = on
; Original -- display_startup_errors = Off
display_startup_errors = on
; Original -- ;date.timezone =
date.timezone = 'Europe/Amsterdam'
EOF"

Shell-Scriptsudo /usr/bin/php /usr/lib/php/install-pear-nozlib.phar

Shell-Scriptcat >> ~/.bashrc <<'EOF'
alias pear="php /usr/lib/php/pear/pearcmd.php"
alias pecl="php /usr/lib/php/pear/peclcmd.php"
EOF

Shell-Script. ~/.bashrc

Shell-Scriptsudo pear channel-update pear.php.net
sudo pecl channel-update pecl.php.net
sudo pear upgrade --force pear
sudo pear upgrade
sudo pecl upgrade

Shell-Scriptsudo sh -c "cat >> /etc/php.ini <<'EOF'
; Original -- ;include_path = ".:/php/includes"
include_path = ".:/usr/lib/php/pear"
EOF"

Shell-Scriptsudo sed -i "" 's/\/var\/mysql\/mysql\.sock/\/tmp\/mysql\.sock/g' /etc/php.ini

6. To install MCrypt, for example, to use RoundCube IMAP Client, see this post.

7. Activate your FTP server; if you’re planning to develop on WordPress this will come in handy. Check this post.

8. Install the PECL SVN plugin if you want to use SVN functions from PHP.

Sorry, Xcode 5.01 and up no longer have the 10.7 include files, so at this time I have no way to compile svn.so.

Shell-Scriptsudo pecl install svn
Shell-Scriptsudo sh -c "cat >> /etc/php.ini <<'EOF'
extension=svn.so
EOF"

9. Managing your virtual hosts

Option A) Use the script I have provided here to scan your development directory and write Apache vhosts file and system hosts file according to that directory.

Option B) Use a DNS based setup (see the post on this for more instructions)

Option C) Use VirtualHostX to manage your virtual hosts. VHX will write both Apache configuration and Hosts file changes for you, but is not free.

Option D) you can always choose to maintain the VirtualHost configuration and hosts files yourself as Alan suggests in his post.

10. And now it is time to reload your web server.

Shell commandsudo apachectl start

11. Manage your Databases with Sequel Pro.

Footnotes:

[August 2014] All instructions verified and updated for OSX 10.10 Yosemite

[August 2014] Updated the HomeBrew install command and link.

[April 2013] Rewritten this post to reflect all ongoing changes and afterthoughts.

[Around october 2012] This post is a re-write of my own post that was here about a year ago. I have rewritten some parts to reflect the changes I have made to my development environments.

[Sometime in 2011] This post is a re-write of this post, by Alan Ivey, for the sole purpose of saving this information for posterity. Also the original article has some excess weight, this is a slimmed down version to reflect my personal setup preference.

Author: Remon Pel

WebDeveloper though not WebDesigner

7 thoughts on “Development WebServer on OSX Lion – HomeBrew/MariaDB/PECL”

  1. I had a problem with installing MariaDB, had to do with the ownership of the /usr/local/Cellar directory.

    I avoided the issue by using

    sudo chown -R $USER /usr/local/Cellar
    1. You should not have to do this, unless you are running the

      brew install mariadb pidof

      command using the wrong user. I have retested and the instructions are accurate. I will keep this in mind though, for future reference.

  2. Also it’s a good thing to also remind people to change their root password on MariaDB (5.2.10 is the latest version as of this comment post). To do this they should first have MariaDB running already. Then issue these two commands (changing ‘new-password’ to their choice password):


    /usr/local/Cellar/mariadb/5.2.10/bin/mysqladmin -u root password 'new-password'


    /usr/local/Cellar/mariadb/5.2.10/bin/mysqladmin -u root -h Whatever-Your-Server-Name-Is-Reported-As.local password 'new-password'

    As well for security’s sake they should also run this command:


    /usr/local/Cellar/mariadb/5.2.10/bin/mysql_secure_installation

    1. That’s a very good tip, but, as stated, I’m not trying to make a production environment in which security is a must. Instead, these instructions are for a development environment in which security is not really an issue. I do thank you, however; it’s a great addition to this post just in case some of us do want to make it more secure.

  3. Last problem I had was with the plist launch agent daemon, in version 5.2.10 the plist name has changed, this should be done before they change the root password and security installation.

    To get MariaDB running, this needs to be changed in your steps:


    sudo cp /usr/local/Cellar/mariadb/5.2.10/homebrew.mxcl.mariadb.plist /Library/LaunchAgents/


    launchctl load -w /Library/LaunchAgents/homebrew.mxcl.mariadb.plist

    Thanks for all of your help and your posts on this!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Confidental Infomation
stop spam mail