How to install Nginx, PHP MySQL on FreeBSD 11 (FEMP stack) including Composer and Drush for Drupal 8

I'm going to share bunch of commands here I recently tried on a FreeBSD 11 environment.

First make sure all packages are using the latest.

sudo pkg update -f

Then let's start installing FEMP stack.

Nginx

pkg install nginx

MySQL 5.6

pkg install mysql56-server

PHP 7.1

pkg install php71 php71-mysqli

Other PHP packages for Drupal

pkg install php71-gd php71-pdo_mysql php71-opcache php71-curl php71-json php71-simplexml php71-openssl phph71-xmlwriter php71-mbstring php71-dom php71-filter php71-hash php71-pdo php71-xml php71-ctype php71-iconv

Now let's configure php-fpm

cd /usr/local/etc
sudo nano php-fpm.conf

Instead of using a port use a unix socket. In order to do this do the following.

nano /usr/local/etc/php-fpm.d/www.conf

Find this line and change it to the following

listen = 127.0.0.1:9000

Chang it to this

listen = /var/run/php-fpm.sock

Unix socket related settings

listen.owner = www
listen.group = www
listen.mode = 0660

Now let's set up auto start

sysrc nginx_enable=yes mysql_enable=yes php_fpm_enable=yes

Now let's start services

service nginx start
service mysql-server start
service php-fpm start

MySQL configurations

In order to secure the MySQL configurations run the following commands and answer to those questions.

mysql_secure_installation

Install Pear

We need this to install Composer

wget http://pear.php.net/go-pear.phar
php go-pear.phar

now move this file to the /usr/local/bin

mv go-pear.phar /use/local/bin/pear

Install Composer

wget -c http://getcomposer.org/composer.phar
mv composer.phar /usr/local/bin/composer

Install Drush

composer global require drush/drush
ln -s /root/.composer/vendor/bin/drush /usr/local/bin/drush