Set up supervisor

download supervisor

sudo pip install supervisor
sudo apt-get install supervisor
sudo echo_supervisord_conf > supervisord_conf
sudo cp supervisord_conf /etc/supervisord.conf
command=php /home/forge/ queue:work sqs --sleep=3 --tries=3 --daemon
At the end of /etc/supervisord.conf
Change path to your own path and user to your current user
supervisord -c /path/to/supervisord.conf
sudo supervisorctl reread

sudo supervisorctl update

sudo supervisorctl start laravel-worker:*


setup PHPstorm and Xdebug with MAMP

in MAMP, check Applications->MAMP->bin->php choose version open php.ini
At the end of it , edit the port to 9001
In PHP storm, edit configurations of PHP debug. for the server we created , add mapping to each file

Setup your own Exception on Laravel

For the latest Laravel framework, we can easily generate our own Exception.
In the app\Exceptions, there is a handler file which can catch all  exceptions in the framework. Therefore, we can handle all our defined exceptions in the handler file.
For example, to create our own Exception:
 * Created by PhpStorm.
 * User: Ivan
 * Date: 6/07/15
 * Time: 3:43 PM
namespace XXX\Exceptions;
use \Exception;
class MyOwnException extends Exception{
    //example of our own exception
    public function __construct($message = null, $code = null, $previous = null) {
        if($message === null)
            $message = ‘This is my own exception’;
        parent::__construct($message, $code, $previous);
Then in the handler.php
<?php namespace RXSync\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use XeroPHP\Remote\Exception as XeroException;
use RXSync\Library\XeroRequest;
use RXSync\XeroConfig;
use \Redirect;
use \Session;
class Handler extends ExceptionHandler {
     * A list of the exception types that should not be reported.
     * @var array
    protected $dontReport = [
     * Report or log an exception.
     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
     * @param  \Exception  $e
     * @return void
    public function report(Exception $e)
        return parent::report($e);
     * Render an exception into an HTTP response.
     * @param  \Illuminate\Http\Request  $request
     * @param  \Exception  $e
     * @return \Illuminate\Http\Response
    public function render($request, Exception $e)
        if($e instanceof  MyOwnException){
            //catch MyOwnException
            //set error messages to Session
            return Redirect::route(‘home’);
        return parent::render($request, $e);
    public function setErrorMessage($e){
        Session::put(‘errorMessageContent’, $e->getMessage());
        Session::put(‘errorPosition’,’Error occurs at :’.$e->getFile().’ At line:’.$e->getLine());

Setup ssl on MAMP with Laravel

followed the related question on stack overflow.  I’m  using MAMP 3.3 now and all of these things work well.
Use the terminal to generate a private key in your default folder
# generate a private key
openssl genrsa -des3 -out server.key 2048
# make up a passphrase and remember it, you’ll need it 3 more times.
Then Enter pass phrase for server.key on the terminal.
let’s say: xcvjlwe1435
# generate certificate signing request

openssl req -new -key server.key -out server.csr
Enter pass phrase for server.key:
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.’, the field will be left blank.
Country Name (2 letter code) [AU]:AU
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:Ivan
Email Address []:
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
# generate the certificate from the CSR for 5 years

openssl x509 -req -days 1825 -in server.csr -signkey server.key -out server.crt
Signature ok
subject=/C=AU/ST=NSW/L=Sydney/O=I5.5 degrees Pty Ltd/OU=IT/CN=Ivan/
Getting Private key
Enter pass phrase for server.key:
# remove the password requirement from the server key
cp server.key server.tmp

openssl rsa -in server.tmp -out server.key
I’m using MAMP 3.3 now
Move the certificate files (server.key and server.crt) to:


Open Apache’s httpd.conf file:


# set your listen port to 80 (near the top of the file)
Listen 80

# set your ServerName to localhost:80 (default is 8888)
ServerName localhost:80

# uncomment the line that includes the secure (SSL/TLS) connection conf
Include /Applications/MAMP/conf/apache/extra/httpd-ssl.conf

Save it and close. Now open Apache’s ssl conf file:


Find the <VirtualHost> entry (big block at the end of the file starting with <VirtualHost _default_:443> and ending with </VirtualHost>) and replace the entire thing with:

<VirtualHost *:443>
        SSLEngine on
        SSLCertificateFile /Applications/MAMP/conf/apache/server.crt
        SSLCertificateKeyFile /Applications/MAMP/conf/apache/server.key

Save and close. Start your MAMP server. You should be able to access your document root at http://localhost and https://localhost.
The root of MAMP will be https://localhost:80/…
Then in the Laravel framework, we can build a new file called HttpsProtocal.php  in the Middleware.
Like this:
 * Created by PhpStorm.
 * User: yifanfan
 * Date: 6/07/15
 * Time: 4:40 PM
namespace ***\Http\Middleware;
use Closure;
use \Request;
use \Redirect;
class HttpsProtocol {
    public function handle($request, Closure $next)
        /*if (!$request->secure() && env(‘APP_ENV’) === ‘prod’) {
            return redirect()->secure($request->getRequestUri());
            return Redirect::secure(Request::path());
        return $next($request);
The next step is to register this middleware in the Kernel.php, like this:
protected $middleware = [