Homestead provision

Laravel Homestead commands:

Available commands:
  destroy   Destroy the Homestead machine
  edit      Edit the Homestead.yaml file
  halt      Halt the Homestead machine
  help      Displays help for a command
  init      Create a stub Homestead.yaml file
  list      Lists commands
  resume    Resume the suspended Homestead machine
  run       Run commands through the Homestead machine via SSH
  ssh       Login to the Homestead machine via SSH
  status    Get the status of the Homestead machine
  suspend   Suspend the Homestead machine
  up        Start the Homestead machine
  update    Update the Homestead machine image

There is missing provision command

Solution is:

list all vagrant instance

$ vagrant global-status
id       name      provider   state    directory
6e1aa44  default   virtualbox poweroff /Users/[whoami]/.composer/vendor/laravel/homestead

then run provision with id

 $ vagrant provision 6e1aa4

My Vagrant LAMP stack

I was using Vaprobash as basic starting Vagranfile which is working perfectly ‘post is here’. However, there are too many settings I will never use, I think it’s a better idea I make my own Vagranfile.

I vagranted up a new empty box, and run each commands to setup my LAMP environment, and recorded each command to shell scripts, that make sure all commands are just what I need.

Download my Vagrant LAMP: My Vagrant LAMP


  • remote call shell scripts like Vaprobash
  • use puppet might be better

Vagrant Move Project Directory

I started to move my development works on my local envirnoment setup to Vagrant. Since I like to reinstall my system once major update released like Mac OSX 10.9 to 10.10, this will save lots of time for me.

And also, I watched this video Get Off MAMP on Laracast to push me move to Vagrant.

Recently, I have moved one of my projects to a new directory, and it told me path is not correct once I vagrant up my project. Becuase I am using Vaprobash as basic start Vagrantfile, it is using NFS to sync folder between your local and box, which will modify /etc/exports.

What I need to do after I move existing project to another directory, I just need modify /etc/exports and update the directory path to new one.

Install Mcrypt on Mac by Homebrew

Recently I setup Laravel enviroment on my Macbook, when I create project or run php artisan, it always prompts Mcrypt PHP extension required. error for me. Becuase I am using vagrant homestead for Laravel development, I can homestead ssh to run commands, but I think it’s better and convenience for me to install Mcrypt on my local enviroment. Then I did some reseach, and setup Mcrypt with mac native PHP.

There are three ways I found:

  • Manually complie Mcrypt source and install
  • Using Homebrew to install
  • Using MAMP Mcrypt

For my requirement, I think homebrew is the best way for me.


Install autoconf which is needed when homebrew compling Mcrypt

brew install autoconf

Homebrew tap

Homebrew dupes, versions, and homebrew-php tap

brew tap homebrew/dupes
brew tap homebrew/versions
brew tap homebrew/homebrew-php

Install php55 or php56

brew install php55


brew install php56

PHP Mcrypt

brew install php55-mcrypt


brew install php56-mcrypt


add mcrypt extension into /etc/php.ini. You can find path using brew info php55-mcrypt, eg.

extension= /usr/local/Cellar/php55-mcrypt/5.5.20/

Install Ghost with Nginx and MySQL

The steps I installed Ghost blog on Linode with Debian 7.5


apt-get update
apt-get upgrade
apt-get install -y build-essential

Installing Nginx

apt-get install nginx

Install Node.js

Based on here

Setup with Debian (as root):

curl -sL | sudo bash -

Then install with Debian (as root):

apt-get install -y nodejs nodejs-legacy

Install MySQL

apt-get install mysql-client mysql-server

Secure MySQL


Restart MySQL

/etc/init.d/mysql restart


service mysql restart

Using MySQL mysql -u root -p to setup database:





Install Ghost

Based on here

created /var/www/ghost as ghost folder

mkdir -p /var/www/
cd /var/www/
curl -L -o
unzip -uo -d ghost
cd /var/www/ghost

Then setup ghost environment

npm install --production
npm install mysql
npm install forever -g

Setup Ghost

Copy over the example config file and then edit it

cp config.example.js config.js

vim /var/www/ghost/config.js

Change production default url to your domain and setup MySQL database

url: 'http://YOUR_DOMAIN',
database: {
	client: 'mysql',
	connection: {
		host: 'localhost',
		user: 'YOUR_USERNAME',
		password: 'YOUR_PASSWORD',
		database: 'YOUR_DATABASE',
		charset: 'utf8'

Run Ghost as background process

Fix all permission

chown -R www-data:www-data /var/www/ghost

Then run ghost as background process by forever (you can find other deply methods in here)

NODE_ENV=production forever start index.js

Setup Nginx

vim /etc/nginx/sites-available/ghost
server {
    listen 80;


    location / {
        proxy_redirect		off;
        proxy_set_header	X-Real-IP         $remote_addr;
        proxy_set_header	X-Forwarded-For   $proxy_add_x_forwarded_for;
        proxy_set_header	Host              $http_host;
        proxy_set_header	X-NginX-Proxy     true;


Enable this site

ln -s /etc/nginx/sites-available/ghost /etc/nginx/sites-enabled/ghost

Restart nginx

/etc/init.d/nginx restart

Open Ghost

Now you can check http://YOUR_DOMAIN to see ghost in there.

Login http://YOUR_DOMAIN/ghost to setup your account.

SSH Password for Windows Git bash

I think it’s more effective to use git cli than gui whatever which system you are using.

For example, you need switch branch, it’s just one line in cli

git checkout [branch]

But (eg. windows) you need right click -> choose command -> click -> choose branch -> click

It’s ok if you just do this few times. However, if you like me, going to 10+ repositories and switch to different branches everyday. Command line is your best friend to help you save your time.

Terminal under Mac or *nix is native and easy to use. However, if you are using windows, after you install git, there is git bash to let you easy use git.

Then there is a problem, each time you push, pull, or commit, it requests you to type your ssh password.

What I did is every time when open a new terminal window, it will ask you your ssh password once, then whatever you do, it won’t ask you password again until you close this seesion window.

Please find this file, if you could not find it, then create one.


In this file, add below’s code

eval `ssh-agent`

Now every time, when you open a new git bash window, it will your password once, and you can run as many commands as you want without popup to ask your password again.

Keyboard Maestro as a replacement for TextExpander

Recently, I started to try Keyboard Maestro, and some people talked about it can be used as a replacement for TextExpander. Even I am not super fan of TextExpander, but I still use it sometimes. I decided to try it to see difference.


Add a new trigger, select Typed String Trigger, then This string is typed.

Type any short string as trigger, eg. I use gml (two spaces after gml). And other options which you can select as you like.

Make sure you tick Simulaate x deletes before executing, otherwise the trigger phrase won’t be deleted before expansion is inserted.



There are only two actions. One is Insert Text, and another is Delete Past Clipboard

Insert Text action, type the expansion into the textarea, and you also can use Insert Token to add variables of Keyboard Maestro given.

Delete Past Clipboard action, change the value to 0(default is 1), because Insert Text action will paste the expansion to clipboard, and replace any previously copied.


Gmail Actions with Google Apps Script

Go to Google Apps Script and start a new blank project.

{% gist 7799698 %}

After you save script, run it and authorize the script to access your Gmail account, then add triggers to call script.

Git pull multiple repositories

for REPO in `ls`; do (cd "$REPO";git pull); done;


find . -mindepth 1 -maxdepth 1 -type d -print -exec git -C {} fetch \;


Let’s see what’s differences between JSON and JSONP first;


JSONP is the result that you can load the json as a script file. And it is usually used to allow for cross-site AJAX with JSON data.

function func(json){
var elm = document.createElement("script");
elm.setAttribute("type", "text/javascript");
elm.src = "";

Convert JSON to JSONP in PHP, JSONP will pass callback to script

$json = json_encode($data);
$jsonp_callback = isset($_GET['callback']) ? $_GET['callback'] : null;
echo $jsonp_callback ? "$jsonp_callback($json)" : $json;

Rerference: Stack Overflow