Skip to content

Instantly share code, notes, and snippets.

@jwcobb
Last active February 19, 2021 18:38
Show Gist options
  • Save jwcobb/9fd614d47e16fabce3ab7b01b625e5fa to your computer and use it in GitHub Desktop.
Save jwcobb/9fd614d47e16fabce3ab7b01b625e5fa to your computer and use it in GitHub Desktop.
Install NGINX, MariaDB 10.1, and PHP 7.1 stack on macOS Sierra using MacPorts

Install NGINX, MariaDB 10.1, and PHP 7.1 stack on macOS Sierra using MacPorts

I keep most of my configuration stuff in a local Git repository so I can track changes and I symlink to those from where they should be so you will see commands such as

 sudo ln -s ~/Documents/configs/PHP/fat-tony.local/php71.ini /opt/local/etc/php71/php.ini 

If you don’t have a similar setup, just copy your configuration files to where they need to be.

I like to prepend some of the commands with time just for curiosity’s sake to see how long it takes.

Turn off the built-in Apache

Go to System Preferences -> Sharing and uncheck the Personal Web sharing. You will never turn Apache on/off here again.

Install Xcode via Mac App Store

macappstore://itunes.apple.com/app/xcode/id497799835?mt=12

Install Xcode Command Line Tools

Find the latest version in the Mac Dev Center. (You must have a free Apple Developer account.)

Agree to Xcode license

Either launch Xcode via GUI or run

sudo xcodebuild -license

Install MacPorts

Use the macOS Sierra v10.12 installer.

The installer will prepend your $PATH with the necessary /opt/local/bin:/opt/local/sbin:

Make sure MacPorts knows the path for Xcode

As of Xcode 4.3 you need to make sure Xcode knows where to look.

sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer/

Make sure everything is up to date before installing any ports

sudo /opt/local/bin/port -v selfupdate

Install cURL with the SSL variant

time sudo port install curl +ssl +http2

Install MariaDB 10.1 Server

Maria DB Server is an enhanced, drop-in MySQL replacement and it isn’t controlled by Oracle.

One of the most popular database servers. Made by the original developers of MySQL. Guaranteed to stay open source.

time sudo port install mariadb-10.1 +openssl mariadb-10.1-server mysql_select

Install Percona Toolkit

Percona explains these best:

Percona Toolkit for MySQL is a collection of advanced command-line tools used by Percona MySQL Support staff to perform a variety of MySQL server and system tasks that are too difficult or complex to perform manually…

time sudo port install p5.24-dbd-mysql -mysql56 +mariadb10_1 percona-toolkit

Add MariaDB to you $PATH (optional)

ZSH

nano ~/.zshrc

or Bash:

nano ~/.bash_profile

Add the following line

export PATH=/opt/local/lib/mariadb-10.1/bin:$PATH

Install your my.cnf if you have one

MacPorts’ MariaDB/MySQL looks for my.cnf in the standard paths as defined by MySQL

You can put this in the global spot: /etc/my.cnf or the one specific to this install /opt/local/etc/percona/my.cnf

sudo ln -s ~/Documents/configs/MySQL/fat-tony.local/mariadb-10.1-server.my.cnf /opt/local/etc/mariadb-10.1/my.cnf

If you do not have a my.cnf file or don't know where to start, the Percona Configuration Wizard for MySQL will build you a good base. The my.cnf file here is for my development machine which is a MacBook Pro “Core i7” 2.7 15" Retina 2013 with 16GB of RAM.

Install default tables

If this is a fresh MariaDB install and you're not re-using existing data install the default tables

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

Start up MariaDB

This installs and activates a launchd item.

Do not be confused by MacPorts' documentation referring to StartupItems. StartupItems is their term for special scripts that create launchd items I have no idea why they would choose terminology that makes you think it is a 10.4 (pre-launchd) StartupItem (which are deprecated).

sudo port load mariadb-10.1-server

To stop MariaDB use

sudo port unload mariadb-10.1-server

Run MariaDB’s built-in script for hardening the security of your install

sudo /opt/local/lib/mariadb-10.1/bin/mysql_secure_installation

If you don’t set a root password when it asks you to just ring your call button, and Tommy will come back there and hit you over the head with a tack hammer because you are a retard

If this is not a new install, upgrade your existing tables

sudo /opt/local/lib/mariadb-10.1/bin/mysql_upgrade -uroot -p

Install PHP 7.1 and NGINX

time sudo port install nginx +geoip +gzip_static +http2 +mail +redis +ssl +zip php_select php71 php71-cgi php71-curl php71-exif php71-fpm php71-ftp php71-gd php71-geoip php71-gettext php71-iconv php71-imagick php71-imap php71-intl php71-mailparse php71-mbstring php71-mysql -mysqlnd +mariadb php71-oauth php71-opcache php71-openssl php71-posix php71-redis php71-soap php71-sockets php71-solr php71-sqlite php71-timezonedb php71-zip

If this is your development box also install Xdebug.

time sudo port install php71-xdebug

Please don’t install Xdebug on production machines!

Designate PHP 7.1 as the active version.

Only really necessary if you are upgrading from an older version of PHP (Hat Tip) but doesn’t hurt to do it anyways.

sudo port select php php71

Install the php.ini

sudo ln -s ~/Documents/configs/PHP/fat-tony.local/php71.ini-development /opt/local/etc/php71/php.ini

NOTE: If you are also installing MariaDB probably need to update the mysql.sock paths in your php.ini to reflect /opt/local/var/run/mariadb-10.1/mysqld.sock. There are 3 possible places you may need to set this.

  • mysql.default_socket
  • mysqli.default_socket
  • pdo_mysql.default_socket

Install Cronolog to rotate your log files

If you want to split your log files up into usable chunks.

time sudo port install cronolog

Fix the GeoIP install

If you’re using the free GeoLite database PHP will probably not find it in the default install location.

sudo ln -s /opt/local/share/GeoIP/GeoIP.dat /opt/local/share/GeoIP/GeoIPCity.dat

Symlink NGINX and php-fpm configs

sudo ln -s ~/Documents/configs/NGINX/fat-tony.local/fastcgi.conf /opt/local/etc/nginx/fastcgi.conf 
sudo ln -s ~/Documents/configs/NGINX/fat-tony.local/nginx.conf /opt/local/etc/nginx/nginx.conf 
sudo ln -s ~/Documents/configs/NGINX/fat-tony.local/sites-available /opt/local/etc/nginx/sites-available 
sudo ln -s ~/Documents/configs/NGINX/fat-tony.local/sites-enabled /opt/local/etc/nginx/sites-enabled 

sudo ln -s ~/Documents/configs/PHP/fat-tony.local/php-fpm.conf /opt/local/etc/php71/php-fpm.conf 
sudo ln -s ~/Documents/configs/PHP/fat-tony.local/php-fpm.d/www.conf /opt/local/etc/php71/php-fpm.d/www.conf

Start php-fpm

sudo launchctl load -w /Library/LaunchDaemons/org.macports.php71-fpm.plist

Start NGINX

sudo port load nginx

To stop NGINX use

sudo port unload nginx

Install Some Additional Tools For Development

Install AutoJump

autojump is a faster way to navigate your filesystem. It works by maintaining a database of the directories you use the most from the command line. Directories must be visited first before they can be jumped to.

time sudo port install autojump
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment