Skip to main content

Style Options

Layout Style

Colors schema

Direction

My Local Dev Environment

My Local Dev Environment

As a LAMP developer, having complete control and knowledge over my local development environment is critical to the success of delivering solutions quickly and efficiently. I almost always end up going back to my roots of installing Apache + PHP, and MySQL from scratch. It's rare when system administrators choose pre-bundled tools like MAMP, WAMP, XAMPP, or Zend Server. So to me, it makes sense to avoid them as well, which can save some time in the future.

When working for larger companies, Mac's are usually the choice of hardware for developers, so working with OS X has become very familiar with me. Initially, I used the proprietary application MAMP but found that learning this application takes more time than it's worth. While OS X ships with a personal web server installed, I've discovered that Macports is the more efficient option due to the automation of stable packages that are included.

Here are the steps to install and setup Apache + PHP:

sudo port install apache2

sudo port install php56

sudo port update

For example here is a simple command to enable mcrypt:

sudo port install php56-mcrypt

sudo port install php56-apache2handler

sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php56.so

sudo /opt/local/apache2/conf/httpd.conf

Once installed, here is a command that will identify warnings/errors in the config. This is very handy when setting up new virtual hosts:

/opt/local/apache2/bin/apachectl -t

Here are the commands to start/stop Apache:

sudo port load apache2

sudo port unload apache2

or

sudo /opt/local/apache2/bin/apachectl stop

sudo /opt/local/apache2/bin/apachectl -k start

 

MySQL - As per the documentation, installing the DMG is the easiest way to go. When I tried to install via Macports, there were some strange permissions problems that didn't allow web applications to connect to the server, so I just install it directly now.

To have MySQL start at boot up, type this command in the terminal:

sudo launchctl load -w com.oracle.oss.mysql.mysqld.plist

To start and stop the MySQL service, use these commands:

sudo launchctl start com.mysql.mysqld

sudo launchctl stop com.mysql.mysqld

 

MariaDB - this spin-off of MySQL is very easily installed Macports. I have not encountered any problems, so I will continue to install it through there until proven otherwise. To install simply use this command:

sudo port install mariadb-server

To start/stop the service use these commands:

sudo port load mariadb-server

sudo port unload mariadb-server

To create the main databases:

sudo -u _mysql /opt/local/lib/mariadb/bin/mysql_install_db

sudo port unload mariadb-server

To run the initial setup, run this wizard:

/opt/local/lib/mariadb/bin/mysql_secure_installation

If you're not using your bash profile to map your mysql command, this will do it for you:

sudo port select --set mysql mariadb

TAGS

Copyright © 2016 Mark Won